[Pkg-gnupg-commit] [gnupg2] 103/241: gpg: Add --encrypt-to-default-key.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Dec 9 20:32:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit de9b2340153d70b083494d1a277a384dcf43bff0
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Nov 3 23:39:46 2015 +0100

    gpg: Add --encrypt-to-default-key.
    
    * g10/getkey.c (parse_def_secret_key): Drop the static qualifier and
    export the function.
    * g10/gpg.c (enum cmd_and_opt_values): Add value oEncryptToDefaultKey.
    (opts): Handle oEncryptToDefaultKey.
    (main): Likewise.
    * g10/options.h (opt): Add field encrypt_to_default_key.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
    GnuPG-bug-id: 807
---
 doc/gpg.texi  |  5 +++++
 g10/getkey.c  |  2 +-
 g10/gpg.c     | 19 +++++++++++++++++++
 g10/keydb.h   |  4 ++++
 g10/options.h |  1 +
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/doc/gpg.texi b/doc/gpg.texi
index efbeef2..246b441 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -1916,6 +1916,11 @@ recipients given either by use of @option{--recipient} or by the asked user id.
 No trust checking is performed for these user ids and even disabled
 keys can be used.
 
+ at item --encrypt-to-default-key
+ at opindex encrypt-to-default-key
+If the default secret key is taken from @option{--default-key}, then
+also encrypt to that key.
+
 @item --no-encrypt-to
 @opindex no-encrypt-to
 Disable the use of all @option{--encrypt-to} and
diff --git a/g10/getkey.c b/g10/getkey.c
index d3ce7d2..b4086a2 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1121,7 +1121,7 @@ get_pubkey_byfprint_fast (PKT_public_key * pk,
   return 0;
 }
 
-static const char *
+const char *
 parse_def_secret_key (ctrl_t ctrl)
 {
   KEYDB_HANDLE hd = NULL;
diff --git a/g10/gpg.c b/g10/gpg.c
index e61f90d..7338ac9 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -303,6 +303,7 @@ enum cmd_and_opt_values
     oEncryptTo,
     oHiddenEncryptTo,
     oNoEncryptTo,
+    oEncryptToDefaultKey,
     oLoggerFD,
     oLoggerFile,
     oUtf8Strings,
@@ -500,6 +501,7 @@ static ARGPARSE_OPTS opts[] = {
   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 @@ main (int argc, char **argv)
 	    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 @@ main (int argc, char **argv)
         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 )
       {
diff --git a/g10/keydb.h b/g10/keydb.h
index 7d14fb8..76136c1 100644
--- a/g10/keydb.h
+++ b/g10/keydb.h
@@ -582,6 +582,10 @@ int get_pubkey_byfprint_fast (PKT_public_key *pk,
    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
diff --git a/g10/options.h b/g10/options.h
index 7485985..bc92dd7 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -175,6 +175,7 @@ struct
   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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list