mirror of
git://git.gnupg.org/gnupg.git
synced 2025-05-19 09:02:22 +02:00
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 <justus@g10code.com>
This commit is contained in:
parent
027ce4ba37
commit
842d233d40
@ -33,6 +33,7 @@
|
|||||||
#include "openpgpdefs.h"
|
#include "openpgpdefs.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "i18n.h"
|
||||||
#include "compliance.h"
|
#include "compliance.h"
|
||||||
|
|
||||||
/* Return true if ALGO with a key of KEYLENGTH is compliant to the
|
/* 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");
|
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;
|
||||||
|
}
|
||||||
|
@ -48,4 +48,15 @@ int gnupg_digest_is_compliant (enum gnupg_compliance_mode compliance,
|
|||||||
digest_algo_t digest);
|
digest_algo_t digest);
|
||||||
const char *gnupg_status_compliance_flag (enum gnupg_compliance_mode compliance);
|
const char *gnupg_status_compliance_flag (enum gnupg_compliance_mode compliance);
|
||||||
|
|
||||||
|
struct gnupg_compliance_option
|
||||||
|
{
|
||||||
|
const char *keyword;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
int gnupg_parse_compliance_option (const char *string,
|
||||||
|
struct gnupg_compliance_option options[],
|
||||||
|
size_t length,
|
||||||
|
int quiet);
|
||||||
|
|
||||||
#endif /*GNUPG_COMMON_COMPLIANCE_H*/
|
#endif /*GNUPG_COMMON_COMPLIANCE_H*/
|
||||||
|
35
g10/gpg.c
35
g10/gpg.c
@ -2073,11 +2073,8 @@ parse_tofu_policy (const char *policystr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Parse the value of --compliance. */
|
static struct gnupg_compliance_option compliance_options[] =
|
||||||
static int
|
|
||||||
parse_compliance_option (const char *string)
|
|
||||||
{
|
{
|
||||||
struct { const char *keyword; enum cmd_and_opt_values option; } list[] = {
|
|
||||||
{ "gnupg", oGnuPG },
|
{ "gnupg", oGnuPG },
|
||||||
{ "openpgp", oOpenPGP },
|
{ "openpgp", oOpenPGP },
|
||||||
{ "rfc4880bis", oRFC4880bis },
|
{ "rfc4880bis", oRFC4880bis },
|
||||||
@ -2088,26 +2085,6 @@ parse_compliance_option (const char *string)
|
|||||||
{ "pgp8", oPGP8 },
|
{ "pgp8", oPGP8 },
|
||||||
{ "de-vs", oDE_VS }
|
{ "de-vs", oDE_VS }
|
||||||
};
|
};
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!ascii_strcasecmp (string, "help"))
|
|
||||||
{
|
|
||||||
log_info (_("valid values for option '%s':\n"), "--compliance");
|
|
||||||
for (i=0; i < DIM (list); i++)
|
|
||||||
log_info (" %s\n", list[i].keyword);
|
|
||||||
g10_exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0; i < DIM (list); i++)
|
|
||||||
if (!ascii_strcasecmp (string, list[i].keyword))
|
|
||||||
return list[i].option;
|
|
||||||
|
|
||||||
log_error (_("invalid value for option '%s'\n"), "--compliance");
|
|
||||||
if (!opt.quiet)
|
|
||||||
log_info (_("(use \"help\" to list choices)\n"));
|
|
||||||
g10_exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Helper to set compliance related options. This is a separate
|
/* Helper to set compliance related options. This is a separate
|
||||||
@ -2862,7 +2839,15 @@ main (int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case oCompliance:
|
case oCompliance:
|
||||||
set_compliance_option (parse_compliance_option (pargs.r.ret_str));
|
{
|
||||||
|
int compliance = gnupg_parse_compliance_option (pargs.r.ret_str,
|
||||||
|
compliance_options,
|
||||||
|
DIM (compliance_options),
|
||||||
|
opt.quiet);
|
||||||
|
if (compliance < 0)
|
||||||
|
g10_exit (1);
|
||||||
|
set_compliance_option (compliance);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case oOpenPGP:
|
case oOpenPGP:
|
||||||
case oRFC2440:
|
case oRFC2440:
|
||||||
|
15
sm/gpgsm.c
15
sm/gpgsm.c
@ -41,6 +41,7 @@
|
|||||||
#include "../common/gc-opt-flags.h"
|
#include "../common/gc-opt-flags.h"
|
||||||
#include "../common/asshelp.h"
|
#include "../common/asshelp.h"
|
||||||
#include "../common/init.h"
|
#include "../common/init.h"
|
||||||
|
#include "../common/compliance.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
@ -1443,7 +1444,19 @@ main ( int argc, char **argv)
|
|||||||
case oNoAutostart: opt.autostart = 0; break;
|
case oNoAutostart: opt.autostart = 0; break;
|
||||||
|
|
||||||
case oCompliance:
|
case oCompliance:
|
||||||
/* Dummy option for now. */
|
{
|
||||||
|
struct gnupg_compliance_option compliance_options[] =
|
||||||
|
{
|
||||||
|
{ "de-vs", CO_DE_VS }
|
||||||
|
};
|
||||||
|
int compliance = gnupg_parse_compliance_option (pargs.r.ret_str,
|
||||||
|
compliance_options,
|
||||||
|
DIM (compliance_options),
|
||||||
|
opt.quiet);
|
||||||
|
if (compliance < 0)
|
||||||
|
gpgsm_exit (1);
|
||||||
|
opt.compliance = compliance;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "../common/audit.h"
|
#include "../common/audit.h"
|
||||||
#include "../common/session-env.h"
|
#include "../common/session-env.h"
|
||||||
#include "../common/ksba-io-support.h"
|
#include "../common/ksba-io-support.h"
|
||||||
|
#include "../common/compliance.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_DIGEST_LEN 64
|
#define MAX_DIGEST_LEN 64
|
||||||
@ -144,6 +145,7 @@ struct
|
|||||||
OID per string. */
|
OID per string. */
|
||||||
strlist_t ignored_cert_extensions;
|
strlist_t ignored_cert_extensions;
|
||||||
|
|
||||||
|
enum gnupg_compliance_mode compliance;
|
||||||
} opt;
|
} opt;
|
||||||
|
|
||||||
/* Debug values and macros. */
|
/* Debug values and macros. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user