Index: b/g10/getkey.c =================================================================== --- b/g10/getkey.c +++ b/g10/getkey.c @@ -1121,7 +1121,7 @@ return 0; } -static const char * +const char * parse_def_secret_key (ctrl_t ctrl) { KEYDB_HANDLE hd = NULL; Index: b/g10/gpg.c =================================================================== --- b/g10/gpg.c +++ b/g10/gpg.c @@ -303,6 +303,7 @@ oEncryptTo, oHiddenEncryptTo, oNoEncryptTo, + oEncryptToDefaultKey, oLoggerFD, oLoggerFile, oUtf8Strings, @@ -500,6 +501,7 @@ ARGPARSE_s_s (oEncryptTo, "encrypt-to", "@"), ARGPARSE_s_n (oNoEncryptTo, "no-encrypt-to", "@"), ARGPARSE_s_s (oHiddenEncryptTo, "hidden-encrypt-to", "@"), + ARGPARSE_s_n (oEncryptToDefaultKey, "encrypt-to-default-key", "@"), ARGPARSE_s_s (oLocalUser, "local-user", N_("|USER-ID|use USER-ID to sign or decrypt")), @@ -2776,6 +2778,9 @@ sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); sl->flags = 1|2; break; + case oEncryptToDefaultKey: + opt.encrypt_to_default_key = 1; + break; case oRecipient: /* store the recipient */ add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings ); any_explicit_recipient = 1; @@ -3727,6 +3732,20 @@ break; } + 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 = 1; + } + else if (opt.def_secret_key) + log_info (_("--encrypt-to-default-key specified, but no valid default keys specified.\n")); + else + log_info (_("--encrypt-to-default-key specified, but --default-key not specified.\n")); + } + /* The command dispatcher. */ switch( cmd ) { Index: b/g10/keydb.h =================================================================== --- b/g10/keydb.h +++ b/g10/keydb.h @@ -582,6 +582,10 @@ with the specified key id. */ int have_secret_key_with_kid (u32 *keyid); +/* Parse the --default-key parameter. Returns the last key (in terms + of when the option is given) that is available. */ +const char *parse_def_secret_key (ctrl_t ctrl); + /* Look up a secret key. If PK is not NULL, the public key of the first result is returned Index: b/g10/options.h =================================================================== --- b/g10/options.h +++ b/g10/options.h @@ -174,6 +174,7 @@ int no_mdc_warn; char *temp_dir; int no_encrypt_to; + int encrypt_to_default_key; int interactive; struct notation *sig_notations; struct notation *cert_notations;