aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/gpg.c21
-rw-r--r--g10/pkclist.c47
2 files changed, 47 insertions, 21 deletions
diff --git a/g10/gpg.c b/g10/gpg.c
index 11dbf5631..71f44eddf 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -4281,8 +4281,6 @@ main (int argc, char **argv)
}
{
- int have_def_secret_key = opt.def_secret_key != NULL;
-
rc = check_user_ids (&locusr, 1, 1);
if (rc)
g10_exit (1);
@@ -4292,25 +4290,6 @@ main (int argc, char **argv)
rc = check_user_ids (&opt.def_secret_key, 1, 0);
if (rc)
g10_exit (1);
-
- if (opt.encrypt_to_default_key)
- {
- const char *default_key = parse_def_secret_key (ctrl);
- if (default_key)
- {
- sl = add_to_strlist2 (&remusr, default_key, utf8_strings);
- sl->flags = ((oEncryptToDefaultKey << PK_LIST_SHIFT)
- | PK_LIST_ENCRYPT_TO);
- if (opt.encrypt_to_default_key == 2)
- sl->flags |= PK_LIST_CONFIG;
- }
- else if (have_def_secret_key)
- log_info (_("option '%s' given, but no valid default keys given\n"),
- "--encrypt-to-default-key");
- else
- log_info (_("option '%s' given, but option '%s' not given\n"),
- "--encrypt-to-default-key", "--default-key");
- }
}
/* The command dispatcher. */
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 )