1 /* t-genkey.c - regression test
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2003 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 General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (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 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GPGME; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #define fail_if_err(err) \
31 fprintf (stderr, "%s:%d: GpgmeError %s\n", \
32 __FILE__, __LINE__, gpgme_strerror (err)); \
38 /* True if progress function printed something on the screen. */
42 progress (void *self, const char *what, int type, int current, int total)
44 if (!strcmp (what, "primegen") && !current && !total
45 && (type == '.' || type == '+' || type == '!'
46 || type == '^' || type == '<' || type == '>'))
54 fprintf (stderr, "unknown progress `%s' %d %d %d\n", what, type,
62 main (int argc, char **argv)
66 const char *parms = "<GnupgKeyParms format=\"internal\">\n"
69 "Subkey-Type: ELG-E\n"
70 "Subkey-Length: 1024\n"
71 "Name-Real: Joe Tester\n"
72 "Name-Comment: (pp=abc)\n"
73 "Name-Email: joe@foo.bar\n"
77 GpgmeGenKeyResult result;
79 err = gpgme_new (&ctx);
82 gpgme_set_progress_cb (ctx, progress, NULL);
84 err = gpgme_op_genkey (ctx, parms, NULL, NULL);
87 result = gpgme_op_genkey_result (ctx);
90 fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
97 printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
98 result->primary ? (result->sub ? "primary, sub" : "primary")
99 : (result->sub ? "sub" : "none"));
101 if (strlen (result->fpr) != 40)
103 fprintf (stderr, "%s:%d: generated key has unexpected fingerprint\n",
107 if (!result->primary)
109 fprintf (stderr, "%s:%d: primary key was not generated\n",
115 fprintf (stderr, "%s:%d: sub key was not generated\n",