diff options
author | Werner Koch <[email protected]> | 2016-08-25 09:38:03 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-08-25 09:38:03 +0000 |
commit | 9ee103957e4136337b92d238283f8ef30fd4a7c5 (patch) | |
tree | 28efd68346717ec611619c22bc9f3799f44d29bf /tests | |
parent | core: Adjust for TOFU_STATS change in gnupg 2.1.16. (diff) | |
download | gpgme-9ee103957e4136337b92d238283f8ef30fd4a7c5.tar.gz gpgme-9ee103957e4136337b92d238283f8ef30fd4a7c5.zip |
core: Add GPGME_KEYLIST_MODE_WITH_TOFU.
* src/gpgme.h.in (GPGME_KEYLIST_MODE_WITH_TOFU): New.
* src/engine-gpg.c (gpg_keylist_build_options): Use that.
* src/keylist.c: Include limits.h.
(parse_tfs_record): New.
(keylist_colon_handler): Support TFS record.
* tests/run-keylist.c: Include time.h.
(isotimestr): New.
(main): Add option --tofu. Print TOFU info.
* tests/run-verify.c: Include time.h.
(isotimestr): New.
(print_result): Use isotimestr for TOFU dates.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run-keylist.c | 60 | ||||
-rw-r--r-- | tests/run-verify.c | 25 |
2 files changed, 76 insertions, 9 deletions
diff --git a/tests/run-keylist.c b/tests/run-keylist.c index bae2dbb9..00f874da 100644 --- a/tests/run-keylist.c +++ b/tests/run-keylist.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <time.h> #include <gpgme.h> @@ -49,6 +50,7 @@ show_usage (int ex) " --local use GPGME_KEYLIST_MODE_LOCAL\n" " --extern use GPGME_KEYLIST_MODE_EXTERN\n" " --sigs use GPGME_KEYLIST_MODE_SIGS\n" + " --tofu use GPGME_KEYLIST_MODE_TOFU\n" " --sig-notations use GPGME_KEYLIST_MODE_SIG_NOTATIONS\n" " --ephemeral use GPGME_KEYLIST_MODE_EPHEMERAL\n" " --validate use GPGME_KEYLIST_MODE_VALIDATE\n" @@ -60,6 +62,26 @@ show_usage (int ex) } +static const char * +isotimestr (unsigned long value) +{ + time_t t; + static char buffer[25+5]; + struct tm *tp; + + if (!value) + return "none"; + t = value; + + tp = gmtime (&t); + snprintf (buffer, sizeof buffer, "%04d-%02d-%02d %02d:%02d:%02d", + 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec); + return buffer; +} + + + int main (int argc, char **argv) { @@ -120,6 +142,11 @@ main (int argc, char **argv) mode |= GPGME_KEYLIST_MODE_EXTERN; argc--; argv++; } + else if (!strcmp (*argv, "--tofu")) + { + mode |= GPGME_KEYLIST_MODE_WITH_TOFU; + argc--; argv++; + } else if (!strcmp (*argv, "--sigs")) { mode |= GPGME_KEYLIST_MODE_SIGS; @@ -181,6 +208,7 @@ main (int argc, char **argv) while (!(err = gpgme_op_keylist_next (ctx, &key))) { gpgme_user_id_t uid; + gpgme_tofu_info_t ti; int nuids; int nsub; @@ -233,24 +261,42 @@ main (int argc, char **argv) for (nuids=0, uid=key->uids; uid; uid = uid->next, nuids++) { printf ("userid %d: %s\n", nuids, nonnull(uid->uid)); - printf (" mbox %d: %s\n", nuids, nonnull(uid->address)); + printf (" mbox: %s\n", nonnull(uid->address)); if (uid->email && uid->email != uid->address) - printf (" email %d: %s\n", nuids, uid->email); + printf (" email: %s\n", uid->email); if (uid->name) - printf (" name %d: %s\n", nuids, uid->name); + printf (" name: %s\n", uid->name); if (uid->comment) - printf (" cmmnt %d: %s\n", nuids, uid->comment); - printf (" valid %d: %s\n", nuids, + printf (" cmmnt: %s\n", uid->comment); + printf (" valid: %s\n", uid->validity == GPGME_VALIDITY_UNKNOWN? "unknown": uid->validity == GPGME_VALIDITY_UNDEFINED? "undefined": uid->validity == GPGME_VALIDITY_NEVER? "never": uid->validity == GPGME_VALIDITY_MARGINAL? "marginal": uid->validity == GPGME_VALIDITY_FULL? "full": uid->validity == GPGME_VALIDITY_ULTIMATE? "ultimate": "[?]"); + if ((ti = uid->tofu)) + { + printf (" tofu: %u (%s)\n", ti->validity, + ti->validity == 0? "conflict" : + ti->validity == 1? "no history" : + ti->validity == 2? "little history" : + ti->validity == 3? "enough history" : + ti->validity == 4? "lot of history" : "?"); + printf (" policy: %u (%s)\n", ti->policy, + ti->policy == GPGME_TOFU_POLICY_NONE? "none" : + ti->policy == GPGME_TOFU_POLICY_AUTO? "auto" : + ti->policy == GPGME_TOFU_POLICY_GOOD? "good" : + ti->policy == GPGME_TOFU_POLICY_UNKNOWN? "unknown" : + ti->policy == GPGME_TOFU_POLICY_BAD? "bad" : + ti->policy == GPGME_TOFU_POLICY_ASK? "ask" : "?"); + printf (" nsigs: %hu\n", ti->signcount); + printf (" nencr: %hu\n", ti->encrcount); + printf (" first: %s\n", isotimestr (ti->firstseen)); + printf (" last: %s\n", isotimestr (ti->lastseen)); + } } - - putchar ('\n'); if (import) diff --git a/tests/run-verify.c b/tests/run-verify.c index ef4dd32e..3c18d3b6 100644 --- a/tests/run-verify.c +++ b/tests/run-verify.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <time.h> #include <gpgme.h> @@ -36,6 +37,26 @@ static int verbose; + +static const char * +isotimestr (unsigned long value) +{ + time_t t; + static char buffer[25+5]; + struct tm *tp; + + if (!value) + return "none"; + t = value; + + tp = gmtime (&t); + snprintf (buffer, sizeof buffer, "%04d-%02d-%02d %02d:%02d:%02d", + 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec); + return buffer; +} + + static gpg_error_t status_cb (void *opaque, const char *keyword, const char *value) { @@ -177,8 +198,8 @@ print_result (gpgme_verify_result_t result) ti->policy == GPGME_TOFU_POLICY_BAD? "bad" : ti->policy == GPGME_TOFU_POLICY_ASK? "ask" : "?"); printf (" sigcount : %hu\n", ti->signcount); - printf (" firstseen: %u\n", ti->firstseen); - printf (" lastseen : %u\n", ti->lastseen); + printf (" firstseen: %s\n", isotimestr (ti->firstseen)); + printf (" lastseen : %s\n", isotimestr (ti->lastseen)); printf (" desc ....: "); print_description (nonnull (ti->description), 15); } |