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-12-01 18:45:36 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             :   (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 (int argc, char **argv)
      64             : {
      65             :   gpgme_ctx_t ctx;
      66             :   gpgme_error_t err;
      67           0 :   const char *parms = "<GnupgKeyParms format=\"internal\">\n"
      68             :     "Key-Type: DSA\n"
      69             :     "Key-Length: 1024\n"
      70             :     "Subkey-Type: ELG-E\n"
      71             :     "Subkey-Length: 1024\n"
      72             :     "Name-Real: Joe Tester\n"
      73             :     "Name-Comment: (pp=abc)\n"
      74             :     "Name-Email: joe@foo.bar\n"
      75             :     "Expire-Date: 0\n"
      76             :     "Passphrase: abc\n"
      77             :     "</GnupgKeyParms>\n";
      78             :   gpgme_genkey_result_t result;
      79             : 
      80             :   (void)argc;
      81             :   (void)argv;
      82             : 
      83           0 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
      84             : 
      85           0 :   err = gpgme_new (&ctx);
      86           0 :   fail_if_err (err);
      87             : 
      88           0 :   gpgme_set_progress_cb (ctx, progress, NULL);
      89             : 
      90           0 :   err = gpgme_op_genkey (ctx, parms, NULL, NULL);
      91           0 :   fail_if_err (err);
      92             : 
      93           0 :   result = gpgme_op_genkey_result (ctx);
      94           0 :   if (!result)
      95             :     {
      96           0 :       fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
      97             :                __FILE__, __LINE__);
      98           0 :       exit (1);
      99             :     }
     100           0 :   if (progress_called)
     101           0 :     printf ("\n");
     102             : 
     103           0 :   printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
     104           0 :           result->primary ? (result->sub ? "primary, sub" : "primary")
     105           0 :           : (result->sub ? "sub" : "none"));
     106             : 
     107           0 :   if (result->fpr && strlen (result->fpr) != 40)
     108             :     {
     109           0 :       fprintf (stderr, "%s:%d: generated key has unexpected fingerprint\n",
     110             :                __FILE__, __LINE__);
     111           0 :       exit (1);
     112             :     }
     113           0 :   if (!result->primary)
     114             :     {
     115           0 :       fprintf (stderr, "%s:%d: primary key was not generated\n",
     116             :                __FILE__, __LINE__);
     117           0 :       exit (1);
     118             :     }
     119           0 :   if (!result->sub)
     120             :     {
     121           0 :       fprintf (stderr, "%s:%d: sub key was not generated\n",
     122             :                __FILE__, __LINE__);
     123           0 :       exit (1);
     124             :     }
     125           0 :   gpgme_release (ctx);
     126           0 :   return 0;
     127             : }

Generated by: LCOV version 1.11