aboutsummaryrefslogtreecommitdiffstats
path: root/common/compliance.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2017-06-07 09:50:54 +0000
committerJustus Winter <[email protected]>2017-06-07 14:53:31 +0000
commit842d233d408457cfa9a8473a6748472956f44e84 (patch)
treee9805a911bb19472f463f6a0fe47aed7fef8ab9b /common/compliance.c
parentgpg: Improve compliance with CO_DE_VS. (diff)
downloadgnupg-842d233d408457cfa9a8473a6748472956f44e84.tar.gz
gnupg-842d233d408457cfa9a8473a6748472956f44e84.zip
common,gpg,sm: Move the compliance option parser.
* common/compliance.c (gnupg_parse_compliance_option): New function. * common/compliance.h (struct gnupg_compliance_option): New type. (gnupg_parse_compliance_option): New prototype. * g10/gpg.c (parse_compliance_option): Remove function. (compliance_options): New variable. (main): Adapt callsite. * sm/gpgsm.c (main): Use the new common function. * sm/gpgsm.h (opt): New field 'compliance'. GnuPG-bug-id: 3191 Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'common/compliance.c')
-rw-r--r--common/compliance.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/common/compliance.c b/common/compliance.c
index 14ba0970d..d81a50385 100644
--- a/common/compliance.c
+++ b/common/compliance.c
@@ -33,6 +33,7 @@
#include "openpgpdefs.h"
#include "logging.h"
#include "util.h"
+#include "i18n.h"
#include "compliance.h"
/* Return true if ALGO with a key of KEYLENGTH is compliant to the
@@ -210,3 +211,35 @@ gnupg_status_compliance_flag (enum gnupg_compliance_mode compliance)
}
log_assert (!"invalid compliance mode");
}
+
+
+/* Parse the value of --compliance. Returns the value corresponding
+ * to the given STRING according to OPTIONS of size LENGTH, or -1
+ * indicating that the lookup was unsuccessful, or the list of options
+ * was printed. If quiet is false, an additional hint to use 'help'
+ * is printed on unsuccessful lookups. */
+int
+gnupg_parse_compliance_option (const char *string,
+ struct gnupg_compliance_option options[],
+ size_t length,
+ int quiet)
+{
+ size_t i;
+
+ if (! ascii_strcasecmp (string, "help"))
+ {
+ log_info (_ ("valid values for option '%s':\n"), "--compliance");
+ for (i = 0; i < length; i++)
+ log_info (" %s\n", options[i].keyword);
+ return -1;
+ }
+
+ for (i = 0; i < length; i++)
+ if (! ascii_strcasecmp (string, options[i].keyword))
+ return options[i].value;
+
+ log_error (_ ("invalid value for option '%s'\n"), "--compliance");
+ if (! quiet)
+ log_info (_ ("(use \"help\" to list choices)\n"));
+ return -1;
+}