1 /* t-genkey.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2003, 2004 g10 Code GmbH
5 This file is part of GPGME.
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.
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.
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
22 /* We need to include config.h so that we know whether we are building
23 with large file system (LFS) support. */
34 #include "t-support.h"
37 /* True if progress function printed something on the screen. */
38 static int progress_called;
41 progress (void *self, const char *what, int type, int current, int total)
43 if (!strcmp (what, "primegen") && !current && !total
44 && (type == '.' || type == '+' || type == '!'
45 || type == '^' || type == '<' || type == '>'))
53 fprintf (stderr, "unknown progress `%s' %d %d %d\n", what, type,
61 main (int argc, char *argv[])
65 const char *parms = "<GnupgKeyParms format=\"internal\">\n"
68 "Name-DN: C=de,O=g10 code,OU=Testlab,CN=Joe 2 Tester\n"
69 "Name-Email: joe@foo.bar\n"
71 gpgme_genkey_result_t result;
74 init_gpgme (GPGME_PROTOCOL_CMS);
76 err = gpgme_data_new (&certreq);
79 err = gpgme_new (&ctx);
82 gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
83 gpgme_set_armor (ctx, 1);
85 gpgme_set_progress_cb (ctx, progress, NULL);
87 err = gpgme_op_genkey (ctx, parms, certreq, NULL);
90 result = gpgme_op_genkey_result (ctx);
93 fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
100 printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
101 result->primary ? (result->sub ? "primary, sub" : "primary")
102 : (result->sub ? "sub" : "none"));
106 fprintf (stderr, "%s:%d: generated key has (unexpectdly) a fingerprint\n",
110 if (!result->primary)
112 fprintf (stderr, "%s:%d: primary key was not generated\n",
118 fprintf (stderr, "%s:%d: sub key was (unexpectedly) generated\n",
124 print_data (certreq);
125 gpgme_data_release (certreq);