LCOV - code coverage report
Current view: top level - tests/gpgsm - t-sign.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 39 58 67.2 %
Date: 2016-09-12 12:35:26 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-sign.c - Regression test.
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 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             : 
      32             : #include <gpgme.h>
      33             : #include "t-support.h"
      34             : 
      35             : 
      36             : static void
      37           2 : check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
      38             : {
      39           2 :   if (result->invalid_signers)
      40             :     {
      41           0 :       fprintf (stderr, "Invalid signer found: %s\n",
      42           0 :                result->invalid_signers->fpr);
      43           0 :       exit (1);
      44             :     }
      45           2 :   if (!result->signatures || result->signatures->next)
      46             :     {
      47           0 :       fprintf (stderr, "Unexpected number of signatures created\n");
      48           0 :       exit (1);
      49             :     }
      50           2 :   if (result->signatures->type != type)
      51             :     {
      52           0 :       fprintf (stderr, "Wrong type of signature created\n");
      53           0 :       exit (1);
      54             :     }
      55           2 :   if (result->signatures->pubkey_algo != GPGME_PK_RSA)
      56             :     {
      57           0 :       fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
      58           0 :                result->signatures->pubkey_algo);
      59           0 :       exit (1);
      60             :     }
      61           2 :   if (result->signatures->hash_algo != GPGME_MD_SHA1)
      62             :     {
      63           0 :       fprintf (stderr, "Wrong hash algorithm reported: %i\n",
      64           0 :                result->signatures->hash_algo);
      65           0 :       exit (1);
      66             :     }
      67           2 :   if (result->signatures->sig_class != 0)
      68             :     {
      69           0 :       fprintf (stderr, "Wrong signature class reported: %u\n",
      70           0 :                result->signatures->sig_class);
      71           0 :       exit (1);
      72             :     }
      73           2 :   if (strcmp ("3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
      74           2 :               result->signatures->fpr))
      75             :     {
      76           0 :       fprintf (stderr, "Wrong fingerprint reported: %s\n",
      77           0 :                result->signatures->fpr);
      78           0 :       exit (1);
      79             :     }
      80           2 : }
      81             : 
      82             : 
      83             : int 
      84           1 : main (int argc, char *argv[])
      85             : {
      86             :   gpgme_ctx_t ctx;
      87             :   gpgme_error_t err;
      88             :   gpgme_data_t in, out;
      89             :   gpgme_sign_result_t result;
      90             : 
      91           1 :   init_gpgme (GPGME_PROTOCOL_CMS);
      92             : 
      93           1 :   err = gpgme_new (&ctx);
      94           1 :   fail_if_err (err);
      95             : 
      96           1 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
      97           1 :   gpgme_set_textmode (ctx, 1);
      98           1 :   gpgme_set_armor (ctx, 1);
      99             : 
     100           1 :   err = gpgme_data_new_from_mem (&in, "Hallo Leute!\n", 13, 0);
     101           1 :   fail_if_err (err);
     102             : 
     103             :   /* First a normal signature.  */
     104           1 :   err = gpgme_data_new (&out);
     105           1 :   fail_if_err (err);
     106           1 :   err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
     107           1 :   fail_if_err (err);
     108           1 :   result = gpgme_op_sign_result (ctx);
     109           1 :   check_result (result, GPGME_SIG_MODE_NORMAL);
     110           1 :   print_data (out);
     111           1 :   gpgme_data_release (out);
     112             :     
     113             :   /* Now a detached signature.  */ 
     114           1 :   gpgme_data_seek (in, 0, SEEK_SET);
     115           1 :   err = gpgme_data_new (&out);
     116           1 :   fail_if_err (err);
     117           1 :   err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
     118           1 :   fail_if_err (err);
     119           1 :   result = gpgme_op_sign_result (ctx);
     120           1 :   check_result (result, GPGME_SIG_MODE_DETACH);
     121           1 :   print_data (out);
     122           1 :   gpgme_data_release (out);
     123             : 
     124           1 :   gpgme_data_release (in);
     125           1 :   gpgme_release (ctx);
     126           1 :   return 0;
     127             : }

Generated by: LCOV version 1.11