LCOV - code coverage report
Current view: top level - tests/gpgsm - cms-decrypt.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 37 0.0 %
Date: 2016-11-29 15:07:43 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* cms-decrypt.c  - Helper to debug the decrupt operation.
       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 <https://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-decrypt"
      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_data_t in, out;
      49             :   gpgme_decrypt_result_t result;
      50             :   gpgme_recipient_t recp;
      51             : 
      52           0 :   if (argc)
      53           0 :     { argc--; argv++; }
      54             : 
      55           0 :   if (argc != 1)
      56             :     {
      57           0 :       fputs ("usage: " PGM " FILE\n", stderr);
      58           0 :       exit (1);
      59             :     }
      60             : 
      61           0 :   init_gpgme (GPGME_PROTOCOL_CMS);
      62             : 
      63           0 :   err = gpgme_new (&ctx);
      64           0 :   fail_if_err (err);
      65           0 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
      66             : 
      67             : 
      68           0 :   err = gpgme_data_new_from_file (&in, *argv, 1);
      69           0 :   fail_if_err (err);
      70             : 
      71           0 :   err = gpgme_data_new (&out);
      72           0 :   fail_if_err (err);
      73             : 
      74           0 :   err = gpgme_op_decrypt (ctx, in, out);
      75           0 :   printf ("gpgme_op_decrypt: %s <%s> (%u)\n",
      76             :           gpgme_strerror (err), gpgme_strsource (err), err);
      77           0 :   result = gpgme_op_decrypt_result (ctx);
      78           0 :   if (!result)
      79             :     {
      80           0 :       fputs (PGM ": error: decryption result missing\n", stderr);
      81           0 :       exit (1);
      82             :     }
      83             :   
      84           0 :   printf ("unsupported_algorithm: %s\n", 
      85           0 :           nonnull (result->unsupported_algorithm));
      86           0 :   printf ("wrong_key_usage: %u\n",  result->wrong_key_usage);
      87           0 :   printf ("file_name: %s\n", nonnull (result->file_name));
      88           0 :   for (recp = result->recipients; recp; recp = recp->next)
      89             :     {
      90           0 :       printf ("recipient.status: %s <%s> (%u)\n",
      91             :               gpgme_strerror (recp->status), gpgme_strsource (recp->status),
      92             :               recp->status);
      93           0 :       printf ("recipient.pkalgo: %d\n", recp->pubkey_algo);
      94           0 :       printf ("recipient.keyid : %s\n", nonnull (recp->keyid));
      95             :     }
      96             : 
      97           0 :   if (!err)
      98             :     {
      99           0 :       puts ("plaintext:");
     100           0 :       print_data (out);
     101           0 :       gpgme_data_release (out);
     102             :     }
     103             : 
     104           0 :   gpgme_data_release (in);
     105             : 
     106           0 :   gpgme_release (ctx);
     107           0 :   return 0;
     108             : }

Generated by: LCOV version 1.11