LCOV - code coverage report
Current view: top level - tests/gpgsm - cms-keylist.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 54 0.0 %
Date: 2016-09-12 13:07:23 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* cms-keylist.c  - Helper to show a key listing.
       2             :    Copyright (C) 2008 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             :  
       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.
      10             :    
      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.
      15             :    
      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/>.
      18             : */
      19             : 
      20             : /* We need to include config.h so that we know whether we are building
      21             :    with large file system (LFS) support. */
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <stdlib.h>
      27             : #include <stdio.h>
      28             : #include <string.h>
      29             : 
      30             : #include <gpgme.h>
      31             : 
      32             : #define PGM "cms-keylist"
      33             : 
      34             : #include "t-support.h"
      35             : 
      36             : static const char *
      37           0 : nonnull (const char *s)
      38             : {
      39           0 :   return s? s :"[none]";
      40             : }
      41             : 
      42             : 
      43             : int 
      44           0 : main (int argc, char **argv)
      45             : {
      46             :   gpgme_error_t err;
      47             :   gpgme_ctx_t ctx;
      48             :   gpgme_key_t key;
      49             :   gpgme_keylist_result_t result;
      50             : 
      51           0 :   if (argc)
      52           0 :     { argc--; argv++; }
      53             : 
      54           0 :   if (argc > 1)
      55             :     {
      56           0 :       fputs ("usage: " PGM " [USERID]\n", stderr);
      57           0 :       exit (1);
      58             :     }
      59             : 
      60           0 :   init_gpgme (GPGME_PROTOCOL_CMS);
      61             : 
      62           0 :   err = gpgme_new (&ctx);
      63           0 :   fail_if_err (err);
      64           0 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
      65             : 
      66           0 :   gpgme_set_keylist_mode (ctx, (gpgme_get_keylist_mode (ctx)
      67             :                                 | GPGME_KEYLIST_MODE_VALIDATE));
      68             : 
      69           0 :   err = gpgme_op_keylist_start (ctx, argc? argv[0]:NULL, 0);
      70           0 :   fail_if_err (err);
      71             :     
      72           0 :   while (!(err = gpgme_op_keylist_next (ctx, &key)))
      73             :     {
      74             :       gpgme_user_id_t uid;
      75             :       int nuids;
      76             :       
      77           0 :       for (nuids=0, uid=key->uids; uid; uid = uid->next)
      78           0 :         nuids++;
      79             : 
      80           0 :       printf ("serial  : %s\n", nonnull (key->issuer_serial));
      81           0 :       printf ("issuer  : %s\n", nonnull (key->issuer_name));
      82           0 :       printf ("chain-id: %s\n", nonnull (key->chain_id));
      83           0 :       printf ("caps    : %s%s%s%s\n",
      84           0 :               key->can_encrypt? "e":"",
      85           0 :               key->can_sign? "s":"",
      86           0 :               key->can_certify? "c":"",
      87           0 :               key->can_authenticate? "a":"");
      88           0 :       printf ("flags   :%s%s%s%s%s%s\n",
      89           0 :               key->secret? " secret":"",
      90           0 :               key->revoked? " revoked":"",
      91           0 :               key->expired? " expired":"",
      92           0 :               key->disabled? " disabled":"",
      93           0 :               key->invalid? " invalid":"",
      94           0 :               key->is_qualified? " qualifid":"");
      95           0 :       for (nuids=0, uid=key->uids; uid; uid = uid->next, nuids++)
      96             :         {
      97           0 :           printf ("userid %d: %s\n", nuids, nonnull(uid->uid));
      98           0 :           printf ("valid  %d: %s\n", nuids, 
      99           0 :                   uid->validity == GPGME_VALIDITY_UNKNOWN? "unknown":
     100           0 :                   uid->validity == GPGME_VALIDITY_UNDEFINED? "undefined":
     101           0 :                   uid->validity == GPGME_VALIDITY_NEVER? "never":
     102           0 :                   uid->validity == GPGME_VALIDITY_MARGINAL? "marginal":
     103           0 :                   uid->validity == GPGME_VALIDITY_FULL? "full":
     104           0 :                   uid->validity == GPGME_VALIDITY_ULTIMATE? "ultimate": "[?]");
     105             :         }
     106             : 
     107           0 :       putchar ('\n');
     108             : 
     109           0 :       gpgme_key_unref (key);
     110             :     }
     111           0 :   if (gpgme_err_code (err) != GPG_ERR_EOF)
     112           0 :     fail_if_err (err);
     113           0 :   err = gpgme_op_keylist_end (ctx);
     114           0 :   fail_if_err (err);
     115             : 
     116           0 :   result = gpgme_op_keylist_result (ctx);
     117           0 :   if (result->truncated)
     118             :     {
     119           0 :       fprintf (stderr, PGM ": key listing unexpectedly truncated\n");
     120           0 :       exit (1);
     121             :     }
     122             : 
     123           0 :   gpgme_release (ctx);
     124           0 :   return 0;
     125             : }

Generated by: LCOV version 1.11