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

Generated by: LCOV version 1.11