diff options
author | Kevin McCarthy <kevin@8t8.us> | 2018-12-06 19:22:59 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2018-12-06 19:22:59 -0800 |
commit | 59625f545d2e8975c335b79cfc9d5b0d26b61f98 (patch) | |
tree | b44467839f55bbb591b84e07f7cbed5a6966029d /gnupgparse.c | |
parent | 2cb3454401325f5265c01e4b6332eb58da74af9e (diff) |
Fix classic gpg date parsing in list-keys.
GnuPG changed the format of their --with-colons output in 2.0.10.
Dates are now seconds since epoch. Update the parse_pub_line() code
to detect the new format.
The GnuPG changes also separated pub and the first uid. Since mutt
allows an empty uid field, the output is a bit less friendly now, with
an initial key without an uid. I think that's acceptable, but
eventually we'll want to change the parsing behavior.
Diffstat (limited to 'gnupgparse.c')
-rw-r--r-- | gnupgparse.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/gnupgparse.c b/gnupgparse.c index fd754a00..9a2e0cb7 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -246,37 +246,46 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) } case 6: /* timestamp (1998-02-28) */ { - char tstr[11]; - struct tm time; - dprint (2, (debugfile, "time stamp: %s\n", p)); - if (!p) - break; - time.tm_sec = 0; - time.tm_min = 0; - time.tm_hour = 12; - strncpy (tstr, p, 11); - tstr[4] = '\0'; - tstr[7] = '\0'; - if (mutt_atoi (tstr, &time.tm_year) < 0) - { - p = tstr; - goto bail; - } - time.tm_year -= 1900; - if (mutt_atoi (tstr+5, &time.tm_mon) < 0) - { - p = tstr+5; - goto bail; - } - time.tm_mon -= 1; - if (mutt_atoi (tstr+8, &time.tm_mday) < 0) - { - p = tstr+8; - goto bail; - } - tmp.gen_time = mutt_mktime (&time, 0); + if (strchr (p, '-')) /* gpg pre-2.0.10 used format (yyyy-mm-dd) */ + { + char tstr[11]; + struct tm time; + + time.tm_sec = 0; + time.tm_min = 0; + time.tm_hour = 12; + strncpy (tstr, p, 11); + tstr[4] = '\0'; + tstr[7] = '\0'; + if (mutt_atoi (tstr, &time.tm_year) < 0) + { + p = tstr; + goto bail; + } + time.tm_year -= 1900; + if (mutt_atoi (tstr+5, &time.tm_mon) < 0) + { + p = tstr+5; + goto bail; + } + time.tm_mon -= 1; + if (mutt_atoi (tstr+8, &time.tm_mday) < 0) + { + p = tstr+8; + goto bail; + } + tmp.gen_time = mutt_mktime (&time, 0); + } + else /* gpg 2.0.10+ uses seconds since 1970-01-01 */ + { + unsigned long long secs; + + if (mutt_atoull (p, &secs) < 0) + goto bail; + tmp.gen_time = (time_t)secs; + } break; } case 7: /* valid for n days */ |