common,gpg: Move the compliance option printer.
authorJustus Winter <justus@g10code.com>
Wed, 7 Jun 2017 10:33:36 +0000 (12:33 +0200)
committerJustus Winter <justus@g10code.com>
Wed, 7 Jun 2017 14:53:32 +0000 (16:53 +0200)
* common/compliance.c (gnupg_compliance_option_string): New function.
* common/compliance.h (gnupg_compliance_option_string): New prototype.
* g10/encrypt.c (write_pubkey_enc_from_list): Update callsite.
* g10/gpg.c (main): Likewise.
* g10/keyedit.c (keyedit_menu): Likewise.
* g10/pkclist.c (build_pk_list): Likewise.
* g10/main.h (compliance_option_string): Remove prototype.
* g10/misc.c (compliance_option_string): Remove function.

GnuPG-bug-id: 3191
Signed-off-by: Justus Winter <justus@g10code.com>
common/compliance.c
common/compliance.h
g10/encrypt.c
g10/gpg.c
g10/keyedit.c
g10/main.h
g10/misc.c
g10/pkclist.c

index d81a503..0acaf21 100644 (file)
@@ -243,3 +243,22 @@ gnupg_parse_compliance_option (const char *string,
     log_info (_ ("(use \"help\" to list choices)\n"));
   return -1;
 }
+
+
+/* Return the command line option for the given COMPLIANCE mode.  */
+const char *
+gnupg_compliance_option_string (enum gnupg_compliance_mode compliance)
+{
+  switch (compliance)
+    {
+    case CO_GNUPG:   return "--compliance=gnupg";
+    case CO_RFC4880: return "--compliance=openpgp";
+    case CO_RFC2440: return "--compliance=rfc2440";
+    case CO_PGP6:    return "--compliance=pgp6";
+    case CO_PGP7:    return "--compliance=pgp7";
+    case CO_PGP8:    return "--compliance=pgp8";
+    case CO_DE_VS:   return "--compliance=de-vs";
+    }
+
+  log_assert (!"invalid compliance mode");
+}
index 198447c..9cbcced 100644 (file)
@@ -58,5 +58,7 @@ int gnupg_parse_compliance_option (const char *string,
                                    struct gnupg_compliance_option options[],
                                    size_t length,
                                    int quiet);
+const char *gnupg_compliance_option_string (enum gnupg_compliance_mode compliance);
+
 
 #endif /*GNUPG_COMMON_COMPLIANCE_H*/
index 57ac8ad..66f49f4 100644 (file)
@@ -932,7 +932,7 @@ write_pubkey_enc_from_list (ctrl_t ctrl, PK_LIST pk_list, DEK *dek, iobuf_t out)
   if (opt.throw_keyids && (PGP6 || PGP7 || PGP8))
     {
       log_info(_("you may not use %s while in %s mode\n"),
-               "--throw-keyids",compliance_option_string());
+               "--throw-keyids", gnupg_compliance_option_string (opt.compliance));
       compliance_failure();
     }
 
index 686fcd7..fbda424 100644 (file)
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -3843,17 +3843,17 @@ main (int argc, char **argv)
              case PREFTYPE_SYM:
                log_info(_("you may not use cipher algorithm '%s'"
                           " while in %s mode\n"),
-                        badalg,compliance_option_string());
+                        badalg, gnupg_compliance_option_string (opt.compliance));
                break;
              case PREFTYPE_HASH:
                log_info(_("you may not use digest algorithm '%s'"
                           " while in %s mode\n"),
-                        badalg,compliance_option_string());
+                        badalg, gnupg_compliance_option_string (opt.compliance));
                break;
              case PREFTYPE_ZIP:
                log_info(_("you may not use compression algorithm '%s'"
                           " while in %s mode\n"),
-                        badalg,compliance_option_string());
+                        badalg, gnupg_compliance_option_string (opt.compliance));
                break;
              default:
                BUG();
@@ -4072,7 +4072,8 @@ main (int argc, char **argv)
                      " with --s2k-mode 0\n"));
        else if(PGP6 || PGP7)
          log_error(_("you cannot use --symmetric --encrypt"
-                     " while in %s mode\n"),compliance_option_string());
+                     " while in %s mode\n"),
+                   gnupg_compliance_option_string (opt.compliance));
        else
          {
            if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 1, NULL, -1)) )
@@ -4132,7 +4133,8 @@ main (int argc, char **argv)
                      " with --s2k-mode 0\n"));
        else if(PGP6 || PGP7)
          log_error(_("you cannot use --symmetric --sign --encrypt"
-                     " while in %s mode\n"),compliance_option_string());
+                     " while in %s mode\n"),
+                   gnupg_compliance_option_string (opt.compliance));
        else
          {
            if( argc )
index ba08d88..9f6add1 100644 (file)
@@ -2314,7 +2314,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
          if (RFC2440)
            {
              tty_printf (_("This command is not allowed while in %s mode.\n"),
-                         compliance_option_string ());
+                         gnupg_compliance_option_string (opt.compliance));
              break;
            }
          photo = 1;
index c406113..33116d2 100644 (file)
@@ -155,7 +155,6 @@ int string_to_compress_algo(const char *string);
 int check_compress_algo(int algo);
 int default_cipher_algo(void);
 int default_compress_algo(void);
-const char *compliance_option_string(void);
 void compliance_failure(void);
 
 struct parse_options
index d485c94..77c8f26 100644 (file)
@@ -1242,24 +1242,6 @@ default_compress_algo(void)
     return DEFAULT_COMPRESS_ALGO;
 }
 
-const char *
-compliance_option_string(void)
-{
-  char *ver="???";
-
-  switch(opt.compliance)
-    {
-    case CO_GNUPG:   return "--gnupg";
-    case CO_RFC4880: return "--openpgp";
-    case CO_RFC2440: return "--rfc2440";
-    case CO_PGP6:    return "--pgp6";
-    case CO_PGP7:    return "--pgp7";
-    case CO_PGP8:    return "--pgp8";
-    case CO_DE_VS:   return "--compliance=de-vs";
-    }
-
-  return ver;
-}
 
 void
 compliance_failure(void)
index ab024d9..48cfe45 100644 (file)
@@ -1028,7 +1028,7 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
             {
               log_info(_("you may not use %s while in %s mode\n"),
                        "--hidden-recipient",
-                       compliance_option_string());
+                       gnupg_compliance_option_string (opt.compliance));
 
               compliance_failure();
             }
@@ -1079,7 +1079,7 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
                     {
                       log_info(_("you may not use %s while in %s mode\n"),
                                "--hidden-encrypt-to",
-                               compliance_option_string());
+                               gnupg_compliance_option_string (opt.compliance));
 
                       compliance_failure();
                     }