1 /* cms-keylist.c - Helper to show a key listing.
2 Copyright (C) 2008 g10 Code GmbH
4 This file is part of GPGME.
6 GPGME is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 GPGME is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* We need to include config.h so that we know whether we are building
21 with large file system (LFS) support. */
32 #define PGM "cms-keylist"
34 #include "t-support.h"
37 nonnull (const char *s)
39 return s? s :"[none]";
44 main (int argc, char **argv)
49 gpgme_keylist_result_t result;
56 fputs ("usage: " PGM " [USERID]\n", stderr);
60 init_gpgme (GPGME_PROTOCOL_CMS);
62 err = gpgme_new (&ctx);
64 gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
66 gpgme_set_keylist_mode (ctx, (gpgme_get_keylist_mode (ctx)
67 | GPGME_KEYLIST_MODE_VALIDATE));
69 err = gpgme_op_keylist_start (ctx, argc? argv[0]:NULL, 0);
72 while (!(err = gpgme_op_keylist_next (ctx, &key)))
77 for (nuids=0, uid=key->uids; uid; uid = uid->next)
80 printf ("serial : %s\n", nonnull (key->issuer_serial));
81 printf ("issuer : %s\n", nonnull (key->issuer_name));
82 printf ("chain-id: %s\n", nonnull (key->chain_id));
83 printf ("caps : %s%s%s%s\n",
84 key->can_encrypt? "e":"",
85 key->can_sign? "s":"",
86 key->can_certify? "c":"",
87 key->can_authenticate? "a":"");
88 printf ("flags :%s%s%s%s%s%s\n",
89 key->secret? " secret":"",
90 key->revoked? " revoked":"",
91 key->expired? " expired":"",
92 key->disabled? " disabled":"",
93 key->invalid? " invalid":"",
94 key->is_qualified? " qualifid":"");
95 for (nuids=0, uid=key->uids; uid; uid = uid->next, nuids++)
97 printf ("userid %d: %s\n", nuids, nonnull(uid->uid));
98 printf ("valid %d: %s\n", nuids,
99 uid->validity == GPGME_VALIDITY_UNKNOWN? "unknown":
100 uid->validity == GPGME_VALIDITY_UNDEFINED? "undefined":
101 uid->validity == GPGME_VALIDITY_NEVER? "never":
102 uid->validity == GPGME_VALIDITY_MARGINAL? "marginal":
103 uid->validity == GPGME_VALIDITY_FULL? "full":
104 uid->validity == GPGME_VALIDITY_ULTIMATE? "ultimate": "[?]");
109 gpgme_key_unref (key);
111 if (gpg_err_code (err) != GPG_ERR_EOF)
113 err = gpgme_op_keylist_end (ctx);
116 result = gpgme_op_keylist_result (ctx);
117 if (result->truncated)
119 fprintf (stderr, PGM ": key listing unexpectedly truncated\n");