|
|
|
@ -111,14 +111,14 @@ pgp_keydata_new(void)
|
|
|
|
|
/**
|
|
|
|
|
\ingroup HighLevel_Keyring
|
|
|
|
|
|
|
|
|
|
\brief Frees keydata and its memory
|
|
|
|
|
\brief Frees key's allocated memory
|
|
|
|
|
|
|
|
|
|
\param keydata Key to be freed.
|
|
|
|
|
|
|
|
|
|
\note This frees the keydata itself, as well as any other memory alloc-ed by it.
|
|
|
|
|
\note This does not free the keydata itself, but any other memory alloc-ed by it.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pgp_keydata_free(pgp_key_t *keydata)
|
|
|
|
|
pgp_key_free(pgp_key_t *keydata)
|
|
|
|
|
{
|
|
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
|
@ -144,8 +144,21 @@ pgp_keydata_free(pgp_key_t *keydata)
|
|
|
|
|
pgp_seckey_free(&keydata->key.seckey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXX sigkey enckey ? */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\ingroup HighLevel_Keyring
|
|
|
|
|
|
|
|
|
|
\brief Frees keydata and its memory
|
|
|
|
|
|
|
|
|
|
\param keydata Key to be freed.
|
|
|
|
|
|
|
|
|
|
\note This frees the keydata itself, as well as any other memory alloc-ed by it.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pgp_keydata_free(pgp_key_t *keydata)
|
|
|
|
|
{
|
|
|
|
|
pgp_key_free(keydata);
|
|
|
|
|
free(keydata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -884,6 +897,26 @@ pgp_keyring_free(pgp_keyring_t *keyring)
|
|
|
|
|
keyring->keyc = keyring->keyvsize = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
|
deletekey( pgp_keyring_t *keyring, pgp_key_t *key, unsigned from)
|
|
|
|
|
{
|
|
|
|
|
/* 'from' is index of key to delete */
|
|
|
|
|
|
|
|
|
|
/* free key internals */
|
|
|
|
|
pgp_key_free(key);
|
|
|
|
|
|
|
|
|
|
/* decrement key count, vsize stays the same so no realloc needed */
|
|
|
|
|
keyring->keyc--;
|
|
|
|
|
|
|
|
|
|
/* Move following keys to fill the gap */
|
|
|
|
|
for ( ; keyring && from < keyring->keyc; from += 1) {
|
|
|
|
|
memcpy(&keyring->keys[from], &keyring->keys[from+1],
|
|
|
|
|
sizeof(pgp_key_t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\ingroup HighLevel_KeyringFind
|
|
|
|
|
|
|
|
|
@ -932,6 +965,78 @@ pgp_getkeybyid(pgp_io_t *io, const pgp_keyring_t *keyring,
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
pgp_deletekeybyid(pgp_io_t *io, pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *keyid)
|
|
|
|
|
{
|
|
|
|
|
unsigned from = 0;
|
|
|
|
|
pgp_key_t *key;
|
|
|
|
|
|
|
|
|
|
if ((key = (pgp_key_t *)pgp_getkeybyid(io, keyring, keyid,
|
|
|
|
|
&from, NULL)) == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* 'from' is now index of key to delete */
|
|
|
|
|
|
|
|
|
|
deletekey(keyring, key, from);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\ingroup HighLevel_KeyringFind
|
|
|
|
|
|
|
|
|
|
\brief Finds key in keyring from its Key Fingerprint
|
|
|
|
|
|
|
|
|
|
\param keyring Keyring to be searched
|
|
|
|
|
\param fpr fingerprint of required key
|
|
|
|
|
\param fpr length of required key
|
|
|
|
|
|
|
|
|
|
\return Pointer to key, if found; NULL, if not found
|
|
|
|
|
|
|
|
|
|
\note This returns a pointer to the key inside the given keyring,
|
|
|
|
|
not a copy. Do not free it after use.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const pgp_key_t *
|
|
|
|
|
pgp_getkeybyfpr(pgp_io_t *io, const pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *fpr, size_t length,
|
|
|
|
|
unsigned *from, pgp_pubkey_t **pubkey)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
pgp_fingerprint_t *kfp = &keyring->keys[*from].sigfingerprint;
|
|
|
|
|
|
|
|
|
|
for ( ; keyring && *from < keyring->keyc; *from += 1) {
|
|
|
|
|
if (kfp->length == length &&
|
|
|
|
|
memcmp(kfp, fpr, length) == 0) {
|
|
|
|
|
if (pubkey) {
|
|
|
|
|
*pubkey = &keyring->keys[*from].key.pubkey;
|
|
|
|
|
}
|
|
|
|
|
return &keyring->keys[*from];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
pgp_deletekeybyfpr(pgp_io_t *io, pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *fpr, size_t length)
|
|
|
|
|
{
|
|
|
|
|
unsigned from = 0;
|
|
|
|
|
pgp_key_t *key;
|
|
|
|
|
|
|
|
|
|
if ((key = (pgp_key_t *)pgp_getkeybyfpr(io, keyring, fpr, length,
|
|
|
|
|
&from, NULL)) == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* 'from' is now index of key to delete */
|
|
|
|
|
|
|
|
|
|
deletekey(keyring, key, from);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert a string keyid into a binary keyid */
|
|
|
|
|
static void
|
|
|
|
|
str2keyid(const char *userid, uint8_t *keyid, size_t len)
|
|
|
|
|