LCOV - code coverage report
Current view: top level - tests/gpg - t-decrypt-verify.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 54 63.0 %
Date: 2015-11-05 17:14:26 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-decrypt-verify.c - Regression test.
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             :  
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             :    
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : /* We need to include config.h so that we know whether we are building
      23             :    with large file system (LFS) support. */
      24             : #ifdef HAVE_CONFIG_H
      25             : #include <config.h>
      26             : #endif
      27             : 
      28             : #include <stdlib.h>
      29             : #include <stdio.h>
      30             : #include <string.h>
      31             : #include <errno.h>
      32             : #include <unistd.h>
      33             : 
      34             : #include <gpgme.h>
      35             : 
      36             : #include "t-support.h"
      37             : 
      38             : 
      39             : static void
      40           1 : check_verify_result (gpgme_verify_result_t result, unsigned int summary,
      41             :                      char *fpr, gpgme_error_t status)
      42             : {
      43             :   gpgme_signature_t sig;
      44             : 
      45           1 :   sig = result->signatures;
      46           1 :   if (!sig || sig->next)
      47             :     {
      48           0 :       fprintf (stderr, "%s:%i: Unexpected number of signatures\n",
      49             :                __FILE__, __LINE__);
      50           0 :       exit (1);
      51             :     }
      52           1 :   if (sig->summary != summary)
      53             :     {
      54           0 :       fprintf (stderr, "%s:%i: Unexpected signature summary: 0x%x\n",
      55           0 :                __FILE__, __LINE__, sig->summary);
      56           0 :       exit (1);
      57             :     }
      58           1 :   if (strcmp (sig->fpr, fpr))
      59             :     {
      60           0 :       fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n",
      61             :                __FILE__, __LINE__, sig->fpr);
      62           0 :       exit (1);
      63             :     }
      64           1 :   if (gpgme_err_code (sig->status) != status)
      65             :     {
      66           0 :       fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
      67             :                __FILE__, __LINE__, gpgme_strerror (sig->status));
      68           0 :       exit (1);
      69             :     }
      70           1 :   if (sig->notations)
      71             :     {
      72           0 :       fprintf (stderr, "%s:%i: Unexpected notation data\n",
      73             :                __FILE__, __LINE__);
      74           0 :       exit (1);
      75             :     }
      76           1 :   if (sig->wrong_key_usage)
      77             :     {
      78           0 :       fprintf (stderr, "%s:%i: Unexpectedly wrong key usage\n",
      79             :                __FILE__, __LINE__);
      80           0 :       exit (1);
      81             :     }
      82           1 :   if (sig->validity != GPGME_VALIDITY_UNKNOWN)
      83             :     {
      84           0 :       fprintf (stderr, "%s:%i: Unexpected validity: %i\n",
      85           0 :                __FILE__, __LINE__, sig->validity);
      86           0 :       exit (1);
      87             :     }
      88           1 :   if (gpgme_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
      89             :     {
      90           0 :       fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
      91             :                __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
      92           0 :       exit (1);
      93             :     }
      94           1 : }
      95             : 
      96             : 
      97             : int 
      98           1 : main (int argc, char *argv[])
      99             : {
     100             :   gpgme_ctx_t ctx;
     101             :   gpgme_error_t err;
     102             :   gpgme_data_t in, out;
     103             :   gpgme_decrypt_result_t decrypt_result;
     104             :   gpgme_verify_result_t verify_result;
     105           1 :   const char *cipher_2_asc = make_filename ("cipher-2.asc");
     106             :   char *agent_info;
     107             : 
     108           1 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
     109             : 
     110           1 :   err = gpgme_new (&ctx);
     111           1 :   fail_if_err (err);
     112             : 
     113           1 :   agent_info = getenv("GPG_AGENT_INFO");
     114           1 :   if (!(agent_info && strchr (agent_info, ':')))
     115           1 :     gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
     116             : 
     117           1 :   err = gpgme_data_new_from_file (&in, cipher_2_asc, 1);
     118           1 :   fail_if_err (err);
     119           1 :   err = gpgme_data_new (&out);
     120           1 :   fail_if_err (err);
     121             : 
     122           1 :   err = gpgme_op_decrypt_verify (ctx, in, out);
     123           1 :   fail_if_err (err);
     124           1 :   decrypt_result = gpgme_op_decrypt_result (ctx);
     125           1 :   if (decrypt_result->unsupported_algorithm)
     126             :     {
     127           0 :       fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
     128             :                __FILE__, __LINE__, decrypt_result->unsupported_algorithm);
     129           0 :       exit (1);
     130             :     }    
     131           1 :   print_data (out);
     132           1 :   verify_result = gpgme_op_verify_result (ctx);
     133           1 :   check_verify_result (verify_result, 0,
     134             :                        "A0FF4590BB6122EDEF6E3C542D727CC768697734",
     135             :                        GPG_ERR_NO_ERROR);
     136             : 
     137           1 :   gpgme_data_release (in);
     138           1 :   gpgme_data_release (out);
     139           1 :   gpgme_release (ctx);
     140           1 :   return 0;
     141             : }

Generated by: LCOV version 1.11