diff options
author | Neal H. Walfield <neal@g10code.com> | 2015-09-15 15:21:17 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@g10code.com> | 2015-09-16 15:15:26 +0200 |
commit | 3940f10af7915b080bf4ed25ceb7e20b52e3cd3e (patch) | |
tree | 0e0e23d70891a6985dfab712ac3cede42418851f /g10/getkey.c | |
parent | g10: Don't skip legacy keys if the search mode is KEYDB_SEARCH_MODE_NEXT (diff) | |
download | gnupg2-3940f10af7915b080bf4ed25ceb7e20b52e3cd3e.tar.xz gnupg2-3940f10af7915b080bf4ed25ceb7e20b52e3cd3e.zip |
g10: Break out of the loop earlier.
* g10/getkey.c (have_secret_key_with_kid): Once we find the relevent
key or subkey, stop searching.
--
Signed-off-by: Neal H. Walfield <neal@g10code.com>.
Only a single key or subkey will ever be selected per keyblock.
Diffstat (limited to 'g10/getkey.c')
-rw-r--r-- | g10/getkey.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/g10/getkey.c b/g10/getkey.c index 7e47b5625..20c344dfa 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -2942,17 +2942,20 @@ have_secret_key_with_kid (u32 *keyid) for (node = keyblock; node; node = node->next) { /* Bit 0 of the flags is set if the search found the key - using that key or subkey. */ + using that key or subkey. Note: a search will only ever + match a single key or subkey. */ if ((node->flag & 1)) { assert (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_PUBLIC_SUBKEY); - if (!agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) - { - result = 1; - break; - } + if (agent_probe_secret_key (NULL, node->pkt->pkt.public_key) == 0) + /* Not available. */ + result = 1; + else + result = 0; + + break; } } release_kbnode (keyblock); |