From dc52995d85048ed12ae8b9f330e9ca41a4030aae Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 22 Dec 2015 14:21:18 +0100 Subject: 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 --- g10/pkclist.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'g10/pkclist.c') 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 ) -- cgit v1.2.3