g10: Improve and unify key selection for -r and --locate-keys.
authorJustus Winter <justus@g10code.com>
Thu, 27 Oct 2016 16:48:51 +0000 (18:48 +0200)
committerJustus Winter <justus@g10code.com>
Thu, 3 Nov 2016 14:04:18 +0000 (15:04 +0100)
commitab89164be02012f1bf159c971853b8610e966301
tree98026764c92c0b2d34134a327738b65f0c896386
parent1ec07cbc209f247fd85704f5701564e31aa56d0b
g10: Improve and unify key selection for -r and --locate-keys.

* g10/getkey.c (struct pubkey_cmp_cookie): New type.
(key_is_ok, uid_is_ok, subkey_is_ok): New functions.
(pubkey_cmp): Likewise.
(get_best_pubkey_byname): Likewise.
* g10/keydb.h (get_best_pubkey_byname): New prototype.
* g10/keylist.c (locate_one): Use the new function.
* g10/pkclist.c (find_and_check_key): Likewise.
* tests/openpgp/Makefile.am (XTESTS): Add new test.
(TEST_FILES): Add new files.
* tests/openpgp/key-selection.scm: New file.
* tests/openpgp/key-selection/0.asc: Likewise.
* tests/openpgp/key-selection/1.asc: Likewise.
* tests/openpgp/key-selection/2.asc: Likewise.
* tests/openpgp/key-selection/3.asc: Likewise.
* tests/openpgp/key-selection/4.asc: Likewise.
--

When a name resembling a mail address is given to either --locate-keys
or --recipient, rank the search results and use only the most relevant
key.

This also lets us query which key will be used for encryption using
--locate-keys.  However, note that --locate-keys may also return keys
incapable of encryption, though it will prefer keys that have an
encryption subkey.

GnuPG-bug-id: 2359
Signed-off-by: Justus Winter <justus@g10code.com>
g10/getkey.c
g10/keydb.h
g10/keylist.c
g10/pkclist.c
tests/openpgp/Makefile.am
tests/openpgp/key-selection.scm [new file with mode: 0644]
tests/openpgp/key-selection/0.asc [new file with mode: 0644]
tests/openpgp/key-selection/1.asc [new file with mode: 0644]
tests/openpgp/key-selection/2.asc [new file with mode: 0644]
tests/openpgp/key-selection/3.asc [new file with mode: 0644]
tests/openpgp/key-selection/4.asc [new file with mode: 0644]