tests: Fix generation of keys without expiration

* tests/run-genkey.c (parse_expire_string): Support default expiration
and no expiration. Set flag for no expiration.
(main): Allow update of flags when generating new key.
--

This makes the parsing of different values for expiration match the
parsing done by gpg's --quick-gen-key. In particular, this makes it
possible again to generate keys without expiration.
This commit is contained in:
Ingo Klöcker 2022-01-13 16:30:56 +01:00
parent e4625885a8
commit e16729edcb

View File

@ -131,15 +131,23 @@ progress_cb (void *opaque, const char *what, int type, int current, int total)
static unsigned long
parse_expire_string (const char *string)
parse_expire_string (const char *string, unsigned int *flags)
{
unsigned long seconds;
unsigned long seconds = 0;
if (!string || !*string || !strcmp (string, "none")
|| !strcmp (string, "never") || !strcmp (string, "-"))
seconds = 0;
if (!string || !*string || !strcmp (string, "-"))
;
else if (!strcmp (string, "none") || !strcmp (string, "never"))
{
if (flags)
*flags |= GPGME_CREATE_NOEXPIRE;
}
else if (strspn (string, "01234567890") == strlen (string))
{
seconds = strtoul (string, NULL, 10);
if (!seconds && flags)
*flags |= GPGME_CREATE_NOEXPIRE;
}
else
{
fprintf (stderr, PGM ": invalid value '%s'\n", string);
@ -370,7 +378,7 @@ main (int argc, char **argv)
}
userid = argv[0];
argc--; argv++;
expire = parse_expire_string (argv[0]);
expire = parse_expire_string (argv[0], NULL);
argc--; argv++;
if (argc > 1)
{
@ -414,7 +422,7 @@ main (int argc, char **argv)
if (argc > 2)
flags |= parse_usage_string (argv[2]);
if (argc > 3)
expire = parse_expire_string (argv[3]);
expire = parse_expire_string (argv[3], &flags);
}
init_gpgme (protocol);