|
|
|
@ -1147,33 +1147,41 @@ pgp_deletekeybyid(pgp_io_t *io, pgp_keyring_t *keyring,
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const pgp_key_t *
|
|
|
|
|
getkeybyfpr(pgp_io_t *io, const pgp_keyring_t *keyring,
|
|
|
|
|
pgp_getkeybyfpr(pgp_io_t *io, const pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *fpr, size_t length,
|
|
|
|
|
unsigned *from, pgp_pubkey_t **pubkey)
|
|
|
|
|
unsigned *from,
|
|
|
|
|
pgp_pubkey_t **pubkey,
|
|
|
|
|
unsigned checkrevoke,
|
|
|
|
|
unsigned checkexpiry)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for ( ; keyring && *from < keyring->keyc; *from += 1) {
|
|
|
|
|
pgp_fingerprint_t *kfp = &keyring->keys[*from].pubkeyfpr;
|
|
|
|
|
pgp_key_t *key = &keyring->keys[*from];
|
|
|
|
|
|
|
|
|
|
pgp_fingerprint_t *kfp = &key->pubkeyfpr;
|
|
|
|
|
|
|
|
|
|
if (kfp->length == length &&
|
|
|
|
|
memcmp(kfp->fingerprint, fpr, length) == 0) {
|
|
|
|
|
|
|
|
|
|
if(checkrevoke || checkexpiry){
|
|
|
|
|
int32_t subkeyidx;
|
|
|
|
|
|
|
|
|
|
subkeyidx = pgp_key_find_key_conds(key,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
checkrevoke, checkexpiry);
|
|
|
|
|
|
|
|
|
|
if (subkeyidx == -2) return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (pubkey) {
|
|
|
|
|
*pubkey = &keyring->keys[*from].key.pubkey;
|
|
|
|
|
*pubkey = &key->key.pubkey;
|
|
|
|
|
}
|
|
|
|
|
return &keyring->keys[*from];
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pgp_key_t *
|
|
|
|
|
pgp_getkeybyfpr(pgp_io_t *io, const pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *fpr, size_t length,
|
|
|
|
|
pgp_pubkey_t **pubkey)
|
|
|
|
|
{
|
|
|
|
|
unsigned from = 0;
|
|
|
|
|
return getkeybyfpr(io,keyring,fpr,length,&from,pubkey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
pgp_deletekeybyfpr(pgp_io_t *io, pgp_keyring_t *keyring,
|
|
|
|
|
const uint8_t *fpr, size_t length)
|
|
|
|
@ -1181,8 +1189,8 @@ pgp_deletekeybyfpr(pgp_io_t *io, pgp_keyring_t *keyring,
|
|
|
|
|
unsigned from = 0;
|
|
|
|
|
pgp_key_t *key;
|
|
|
|
|
|
|
|
|
|
if ((key = (pgp_key_t *)getkeybyfpr(io, keyring, fpr, length,
|
|
|
|
|
&from, NULL)) == NULL) {
|
|
|
|
|
if ((key = (pgp_key_t *)pgp_getkeybyfpr(io, keyring, fpr, length,
|
|
|
|
|
&from, NULL,0,0)) == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/* 'from' is now index of key to delete */
|
|
|
|
|