diff options
author | Neal H. Walfield <[email protected]> | 2015-12-22 13:21:18 +0000 |
---|---|---|
committer | Neal H. Walfield <[email protected]> | 2015-12-22 14:03:54 +0000 |
commit | dc52995d85048ed12ae8b9f330e9ca41a4030aae (patch) | |
tree | 3c22fc598e33f3038f360f2752e6dd948c0e3b9d /g10/pkclist.c | |
parent | gpg: Remove unused parameter. (diff) | |
download | gnupg-dc52995d85048ed12ae8b9f330e9ca41a4030aae.tar.gz gnupg-dc52995d85048ed12ae8b9f330e9ca41a4030aae.zip |
gpg: Lazily evaluate --default-key.
* g10/gpg.c (main): If --encrypt-to-default-key is specified, don't
add --default-key's value to REMUSR here...
* g10/pkclist.c (build_pk_list): ... do it here.
* tests/openpgp/Makefile.am (TESTS): Add default-key.test.
* tests/openpgp/default-key.test: New file.
--
Signed-off-by: Neal H. Walfield <[email protected]>
Diffstat (limited to 'g10/pkclist.c')
-rw-r--r-- | g10/pkclist.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/g10/pkclist.c b/g10/pkclist.c index 39a24f717..b6a213fe2 100644 --- a/g10/pkclist.c +++ b/g10/pkclist.c @@ -914,6 +914,53 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list) else remusr = rcpts; + if (opt.encrypt_to_default_key) + { + static int warned; + + const char *default_key = parse_def_secret_key (ctrl); + if (default_key) + { + PK_LIST r = xmalloc_clear (sizeof *r); + + r->pk = xmalloc_clear (sizeof *r->pk); + r->pk->req_usage = PUBKEY_USAGE_ENC; + + rc = get_pubkey_byname (ctrl, NULL, r->pk, default_key, + NULL, NULL, 0, 1); + if (rc) + { + xfree (r->pk); + xfree (r); + + log_error (_("Can't encrypt to '%s'.\n"), default_key); + if (!opt.quiet) + log_info (_("(check argument of option '%s')\n"), + "--default-key"); + } + else + { + r->next = pk_list; + r->flags = 0; + pk_list = r; + } + } + else if (opt.def_secret_key) + { + if (! warned) + log_info (_("option '%s' given, but no valid default keys given\n"), + "--encrypt-to-default-key"); + warned = 1; + } + else + { + if (! warned) + log_info (_("option '%s' given, but option '%s' not given\n"), + "--encrypt-to-default-key", "--default-key"); + warned = 1; + } + } + /* Check whether there are any recipients in the list and build the * list of the encrypt-to ones (we always trust them). */ for ( rov = remusr; rov; rov = rov->next ) |