1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

use flag to enable rpgp

This commit is contained in:
dignifiedquire 2019-02-28 12:10:16 +01:00 committed by B. Petersen
parent 279d95f66b
commit acb8b966bc
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
2 changed files with 43 additions and 42 deletions

View file

@ -167,6 +167,46 @@ cleanup:
* Key generatation
******************************************************************************/
#if DC_RPGP
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key)
{
rpgp_signed_secret_key* skey;
rpgp_signed_public_key* pkey;
rpgp_cvec* skey_bytes;
rpgp_cvec* pkey_bytes;
char* user_id;
/* Create the user id */
user_id = dc_mprintf("<%s>", addr);
/* Create the actual key */
skey = rpgp_create_rsa_skey(DC_KEYGEN_BITS, user_id);
/* Serialize secret key into bytes */
skey_bytes = rpgp_skey_to_bytes(skey);
/* Get the public key */
pkey = rpgp_skey_public_key(skey);
/* Serialize public key into bytes */
pkey_bytes = rpgp_pkey_to_bytes(pkey);
/* copy into the return secret key */
dc_key_set_from_binary(ret_private_key, rpgp_cvec_data(skey_bytes), rpgp_cvec_len(skey_bytes), DC_KEY_PRIVATE);
/* copy into the return public key */
dc_key_set_from_binary(ret_public_key, rpgp_cvec_data(pkey_bytes), rpgp_cvec_len(pkey_bytes), DC_KEY_PUBLIC);
/* cleanup */
rpgp_skey_drop(skey);
rpgp_cvec_drop(skey_bytes);
rpgp_pkey_drop(pkey);
rpgp_cvec_drop(pkey_bytes);
free(user_id);
return 1;
}
#else
static unsigned add_key_prefs(pgp_create_sig_t *sig)
{
@ -269,47 +309,6 @@ static void add_subkey_binding_signature(pgp_subkeysig_t* p, pgp_key_t* primaryk
free(mem_sig); /* do not use pgp_memory_free() as this would also free mem_sig->buf which is owned by the packet */
}
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key)
{
rpgp_signed_secret_key* skey;
rpgp_signed_public_key* pkey;
rpgp_cvec* skey_bytes;
rpgp_cvec* pkey_bytes;
char* user_id;
/* Create the user id */
user_id = dc_mprintf("<%s>", addr);
/* Create the actual key */
skey = rpgp_create_rsa_skey(DC_KEYGEN_BITS, user_id);
/* Serialize secret key into bytes */
skey_bytes = rpgp_skey_to_bytes(skey);
/* Get the public key */
pkey = rpgp_skey_public_key(skey);
/* Serialize public key into bytes */
pkey_bytes = rpgp_pkey_to_bytes(pkey);
/* copy into the return secret key */
dc_key_set_from_binary(ret_private_key, rpgp_cvec_data(skey_bytes), rpgp_cvec_len(skey_bytes), DC_KEY_PRIVATE);
/* copy into the return public key */
dc_key_set_from_binary(ret_public_key, rpgp_cvec_data(pkey_bytes), rpgp_cvec_len(pkey_bytes), DC_KEY_PUBLIC);
/* cleanup */
rpgp_skey_drop(skey);
rpgp_cvec_drop(skey_bytes);
rpgp_pkey_drop(pkey);
rpgp_cvec_drop(pkey_bytes);
free(user_id);
return 1;
}
#if 0
int dc_pgp_create_keypair(dc_context_t* context, const char* addr, dc_key_t* ret_public_key, dc_key_t* ret_private_key)
{
int success = 0;

View file

@ -14,6 +14,9 @@ extern "C" {
#define DC_VERSION_STR "0.40.0"
/* Set to 1 to enable use of rPGP instead of netpgp where available */
#define DC_RPGP 1
/**
* @mainpage Getting started
*
@ -1190,4 +1193,3 @@ time_t dc_lot_get_timestamp (const dc_lot_t*);
}
#endif
#endif // __DELTACHAT_H__