Browse Source

pgp_getkeybyfpr extended to support revoke/expired checks

master
Edouard Tisserant 7 years ago
parent
commit
b9781b1cf8
2 changed files with 29 additions and 18 deletions
  1. +24
    -16
      dist/src/lib/keyring.c
  2. +5
    -2
      dist/src/lib/keyring.h

+ 24
- 16
dist/src/lib/keyring.c View File

@ -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 */


+ 5
- 2
dist/src/lib/keyring.h View File

@ -87,8 +87,11 @@ const pgp_key_t *pgp_getkeybyfpr(pgp_io_t *,
const pgp_keyring_t *,
const uint8_t *fpr,
size_t length,
pgp_pubkey_t **);
unsigned pgp_deletekeybyfpr(pgp_io_t *,
unsigned *from,
pgp_pubkey_t **,
unsigned checkrevoke,
unsigned checkexpiry);
unsigned pgp_deletekeybyfpr(pgp_io_t *,
pgp_keyring_t *,
const uint8_t *fpr,
size_t length);


Loading…
Cancel
Save