From e16729edcbdf2c35e3729b6d54c21b9b27250326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Thu, 13 Jan 2022 16:30:56 +0100 Subject: [PATCH] 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. --- tests/run-genkey.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/run-genkey.c b/tests/run-genkey.c index f0f6e302..8572db26 100644 --- a/tests/run-genkey.c +++ b/tests/run-genkey.c @@ -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); + { + 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);