LCOV - code coverage report
Current view: top level - tests/gpg - t-genkey.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 38 0.0 %
Date: 2016-09-12 12:35:26 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             : 
      32             : #include <gpgme.h>
      33             : 
      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: DSA\n"
      67             :     "Key-Length: 1024\n"
      68             :     "Subkey-Type: ELG-E\n"
      69             :     "Subkey-Length: 1024\n"
      70             :     "Name-Real: Joe Tester\n"
      71             :     "Name-Comment: (pp=abc)\n"
      72             :     "Name-Email: joe@foo.bar\n"
      73             :     "Expire-Date: 0\n"
      74             :     "Passphrase: abc\n"
      75             :     "</GnupgKeyParms>\n";
      76             :   gpgme_genkey_result_t result;
      77             : 
      78           0 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
      79             : 
      80           0 :   err = gpgme_new (&ctx);
      81           0 :   fail_if_err (err);
      82             : 
      83           0 :   gpgme_set_progress_cb (ctx, progress, NULL);
      84             :   
      85           0 :   err = gpgme_op_genkey (ctx, parms, NULL, NULL);
      86           0 :   fail_if_err (err);
      87             : 
      88           0 :   result = gpgme_op_genkey_result (ctx);
      89           0 :   if (!result)
      90             :     {
      91           0 :       fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
      92             :                __FILE__, __LINE__);
      93           0 :       exit (1);
      94             :     }
      95           0 :   if (progress_called)
      96           0 :     printf ("\n");
      97             : 
      98           0 :   printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
      99           0 :           result->primary ? (result->sub ? "primary, sub" : "primary")
     100           0 :           : (result->sub ? "sub" : "none"));
     101             : 
     102           0 :   if (result->fpr && strlen (result->fpr) != 40)
     103             :     {
     104           0 :       fprintf (stderr, "%s:%d: generated key has unexpected fingerprint\n",
     105             :                __FILE__, __LINE__);
     106           0 :       exit (1);
     107             :     }
     108           0 :   if (!result->primary)
     109             :     {
     110           0 :       fprintf (stderr, "%s:%d: primary key was not generated\n",
     111             :                __FILE__, __LINE__);
     112           0 :       exit (1);
     113             :     }
     114           0 :   if (!result->sub)
     115             :     {
     116           0 :       fprintf (stderr, "%s:%d: sub key was not generated\n",
     117             :                __FILE__, __LINE__);
     118           0 :       exit (1);
     119             :     }
     120           0 :   gpgme_release (ctx);
     121           0 :   return 0;
     122             : }

Generated by: LCOV version 1.11