LCOV - code coverage report
Current view: top level - tests/gpg - t-thread-keylist-verify.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 41 85.4 %
Date: 2018-11-15 08:49:49 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* t-thread-verify.c - Regression test.
       2             :    Copyright (C) 2015 by Bundesamt für Sicherheit in der Informationstechnik
       3             :    Software engineering by Intevation 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             : #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             : #include <pthread.h>
      33             : 
      34             : #include "t-support.h"
      35             : 
      36             : #define THREAD_COUNT 10
      37             : 
      38             : static const char test_text1[] = "Just GNU it!\n";
      39             : static const char test_sig1[] =
      40             : "-----BEGIN PGP SIGNATURE-----\n"
      41             : "\n"
      42             : "iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt\n"
      43             : "bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv\n"
      44             : "b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw\n"
      45             : "Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc\n"
      46             : "dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==\n"
      47             : "=nts1\n"
      48             : "-----END PGP SIGNATURE-----\n";
      49             : 
      50             : void *
      51          10 : start_keylist (void *arg)
      52             : {
      53             :   gpgme_error_t err;
      54             :   gpgme_ctx_t ctx;
      55             :   gpgme_key_t key;
      56             : 
      57             :   (void)arg;
      58          10 :   err = gpgme_new (&ctx);
      59          10 :   fail_if_err (err);
      60             : 
      61          10 :   err = gpgme_op_keylist_start (ctx, NULL, 0);
      62          10 :   fail_if_err (err);
      63             : 
      64         290 :   while (!(err = gpgme_op_keylist_next (ctx, &key)))
      65             :     {
      66         270 :       gpgme_key_unref (key);
      67             :     }
      68             : 
      69          10 :   gpgme_release (ctx);
      70          10 :   return NULL;
      71             : }
      72             : 
      73             : void *
      74          10 : start_verify (void *arg)
      75             : {
      76             :   gpgme_ctx_t ctx;
      77             :   gpgme_error_t err;
      78             :   gpgme_data_t sig, text;
      79             :   gpgme_verify_result_t result;
      80             :   gpgme_signature_t signature;
      81             : 
      82             :   (void)arg;
      83             : 
      84          10 :   err = gpgme_new (&ctx);
      85          10 :   fail_if_err (err);
      86             : 
      87             :   /* Checking a valid message.  */
      88          10 :   err = gpgme_data_new_from_mem (&text, test_text1, strlen (test_text1), 0);
      89          10 :   fail_if_err (err);
      90          10 :   err = gpgme_data_new_from_mem (&sig, test_sig1, strlen (test_sig1), 0);
      91          10 :   fail_if_err (err);
      92          10 :   err = gpgme_op_verify (ctx, sig, text, NULL);
      93          10 :   fail_if_err (err);
      94          10 :   result = gpgme_op_verify_result (ctx);
      95             : 
      96          10 :   signature = result->signatures;
      97             : 
      98          10 :   if (strcmp (signature->fpr, "A0FF4590BB6122EDEF6E3C542D727CC768697734"))
      99             :     {
     100           0 :       fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n",
     101             :                __FILE__, __LINE__, signature->fpr);
     102           0 :       exit (1);
     103             :     }
     104          10 :   if (gpgme_err_code (signature->status) != GPG_ERR_NO_ERROR)
     105             :     {
     106           0 :       fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
     107             :                __FILE__, __LINE__, gpgme_strerror (signature->status));
     108           0 :       exit (1);
     109             :     }
     110          10 :   gpgme_free (text);
     111          10 :   gpgme_free (sig);
     112          10 :   gpgme_release (ctx);
     113          10 :   return NULL;
     114             : }
     115             : 
     116             : int
     117           1 : main (int argc, char *argv[])
     118             : {
     119             :   int i;
     120             :   pthread_t verify_threads[THREAD_COUNT];
     121             :   pthread_t keylist_threads[THREAD_COUNT];
     122           1 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
     123             : 
     124             :   (void)argc;
     125             :   (void)argv;
     126             : 
     127          11 :   for (i = 0; i < THREAD_COUNT; i++)
     128             :     {
     129          20 :       if (pthread_create(&verify_threads[i], NULL, start_verify, NULL) ||
     130          10 :           pthread_create(&keylist_threads[i], NULL, start_keylist, NULL))
     131             :         {
     132           0 :           fprintf(stderr, "%s:%i: failed to create threads \n",
     133             :                        __FILE__, __LINE__);
     134           0 :           exit(1);
     135             :         }
     136             :    }
     137          11 :   for (i = 0; i < THREAD_COUNT; i++)
     138             :     {
     139          10 :       pthread_join (verify_threads[i], NULL);
     140          10 :       pthread_join (keylist_threads[i], NULL);
     141             :     }
     142           1 :   return 0;
     143             : }

Generated by: LCOV version 1.13