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

          Line data    Source code
       1             : /* t-genkey.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             : #include <errno.h>
      32             : 
      33             : #include <gpgme.h>
      34             : #include "t-support.h"
      35             : 
      36             : 
      37             : /* True if progress function printed something on the screen.  */
      38             : static int progress_called;
      39             : 
      40             : static void
      41           0 : progress (void *self, const char *what, int type, int current, int total)
      42             : {
      43           0 :   if (!strcmp (what, "primegen") && !current && !total
      44           0 :       && (type == '.' || type == '+' || type == '!'
      45           0 :           || type == '^' || type == '<' || type == '>'))
      46             :     {
      47           0 :       printf ("%c", type);
      48           0 :       fflush (stdout);
      49           0 :       progress_called = 1;
      50             :     }
      51             :   else
      52             :     {
      53           0 :       fprintf (stderr, "unknown progress `%s' %d %d %d\n", what, type,
      54             :                current, total);
      55           0 :       exit (1);
      56             :     }
      57           0 : }
      58             : 
      59             : 
      60             : int 
      61           0 : main (int argc, char *argv[])
      62             : {
      63             :   gpgme_ctx_t ctx;
      64             :   gpgme_error_t err;
      65           0 :   const char *parms = "<GnupgKeyParms format=\"internal\">\n"
      66             :     "Key-Type: RSA\n"
      67             :     "Key-Length: 1024\n"
      68             :     "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
      69             :     "Name-Email: joe@foo.bar\n"
      70             :     "</GnupgKeyParms>\n";
      71             :   gpgme_genkey_result_t result;
      72             :   gpgme_data_t certreq;
      73             : 
      74           0 :   init_gpgme (GPGME_PROTOCOL_CMS);
      75             : 
      76           0 :   err = gpgme_data_new (&certreq);
      77           0 :   fail_if_err (err);
      78             : 
      79           0 :   err = gpgme_new (&ctx);
      80           0 :   fail_if_err (err);
      81             : 
      82           0 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
      83           0 :   gpgme_set_armor (ctx, 1);
      84             : 
      85           0 :   gpgme_set_progress_cb (ctx, progress, NULL);
      86             :   
      87           0 :   err = gpgme_op_genkey (ctx, parms, certreq, NULL);
      88           0 :   fail_if_err (err);
      89             : 
      90           0 :   result = gpgme_op_genkey_result (ctx);
      91           0 :   if (!result)
      92             :     {
      93           0 :       fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
      94             :                __FILE__, __LINE__);
      95           0 :       exit (1);
      96             :     }
      97           0 :   if (progress_called)
      98           0 :     printf ("\n");
      99             : 
     100           0 :   printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
     101           0 :           result->primary ? (result->sub ? "primary, sub" : "primary")
     102           0 :           : (result->sub ? "sub" : "none"));
     103             : 
     104           0 :   if (result->fpr)
     105             :     {
     106           0 :       fprintf (stderr, "%s:%d: generated key has (unexpectdly) a fingerprint\n",
     107             :                __FILE__, __LINE__);
     108           0 :       exit (1);
     109             :     }
     110           0 :   if (!result->primary)
     111             :     {
     112           0 :       fprintf (stderr, "%s:%d: primary key was not generated\n",
     113             :                __FILE__, __LINE__);
     114           0 :       exit (1);
     115             :     }
     116           0 :   if (result->sub)
     117             :     {
     118           0 :       fprintf (stderr, "%s:%d: sub key was (unexpectedly) generated\n",
     119             :                __FILE__, __LINE__);
     120           0 :       exit (1);
     121             :     }
     122           0 :   gpgme_release (ctx);
     123             : 
     124           0 :   print_data (certreq);
     125           0 :   gpgme_data_release (certreq);
     126             : 
     127           0 :   return 0;
     128             : }

Generated by: LCOV version 1.11