mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-28 22:49:59 +01:00
g10: Simplify some complicated boolean expressions.
* g10/getkey.c (finish_lookup): Simplify logic. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>.
This commit is contained in:
parent
77c2ad4a81
commit
c31e089129
37
g10/getkey.c
37
g10/getkey.c
@ -2413,19 +2413,32 @@ finish_lookup (GETKEY_CTX ctx, KBNODE keyblock)
|
|||||||
|
|
||||||
latest_date = 0;
|
latest_date = 0;
|
||||||
latest_key = NULL;
|
latest_key = NULL;
|
||||||
/* Do not look at subkeys if a certification key is requested. */
|
/* Set latest_key to the latest (the one with the most recent
|
||||||
if ((!foundk || foundk->pkt->pkttype == PKT_PUBLIC_SUBKEY) && !req_prim)
|
timestamp) good (valid, not revoked, not expired, etc.) subkey.
|
||||||
|
|
||||||
|
Don't bother if we are only looking for a primary key or we need
|
||||||
|
an exact match and the exact match is not a subkey. */
|
||||||
|
if (req_prim || (foundk && foundk->pkt->pkttype != PKT_PUBLIC_SUBKEY))
|
||||||
|
;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
KBNODE nextk;
|
KBNODE nextk;
|
||||||
|
|
||||||
/* Either start a loop or check just this one subkey. */
|
/* Either start a loop or check just this one subkey. */
|
||||||
for (k = foundk ? foundk : keyblock; k; k = nextk)
|
for (k = foundk ? foundk : keyblock; k; k = nextk)
|
||||||
{
|
{
|
||||||
PKT_public_key *pk;
|
PKT_public_key *pk;
|
||||||
nextk = k->next;
|
|
||||||
|
if (foundk)
|
||||||
|
/* If FOUNDK is not NULL, then only consider that exact
|
||||||
|
key, i.e., don't iterate. */
|
||||||
|
nextk = NULL;
|
||||||
|
else
|
||||||
|
nextk = k->next;
|
||||||
|
|
||||||
if (k->pkt->pkttype != PKT_PUBLIC_SUBKEY)
|
if (k->pkt->pkttype != PKT_PUBLIC_SUBKEY)
|
||||||
continue;
|
continue;
|
||||||
if (foundk)
|
|
||||||
nextk = NULL; /* what a hack */
|
|
||||||
pk = k->pkt->pkt.public_key;
|
pk = k->pkt->pkt.public_key;
|
||||||
if (DBG_LOOKUP)
|
if (DBG_LOOKUP)
|
||||||
log_debug ("\tchecking subkey %08lX\n",
|
log_debug ("\tchecking subkey %08lX\n",
|
||||||
@ -2477,9 +2490,17 @@ finish_lookup (GETKEY_CTX ctx, KBNODE keyblock)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Okay now try the primary key unless we want an exact
|
/* Check if the primary key is ok (valid, not revoke, not expire,
|
||||||
* key ID match on a subkey */
|
matches requested usage) if:
|
||||||
if ((!latest_key && !(ctx->exact && foundk != keyblock)) || req_prim)
|
|
||||||
|
- we didn't find an appropriate subkey and we're not doing an
|
||||||
|
exact search,
|
||||||
|
|
||||||
|
- we're doing an exact match and the exact match was the
|
||||||
|
primary key, or,
|
||||||
|
|
||||||
|
- we're just considering the primary key. */
|
||||||
|
if ((!latest_key && !ctx->exact) || foundk == keyblock || req_prim)
|
||||||
{
|
{
|
||||||
PKT_public_key *pk;
|
PKT_public_key *pk;
|
||||||
if (DBG_LOOKUP && !foundk && !req_prim)
|
if (DBG_LOOKUP && !foundk && !req_prim)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user