1 /* t-sign.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. */
33 #include "t-support.h"
37 check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
39 if (result->invalid_signers)
41 fprintf (stderr, "Invalid signer found: %s\n",
42 result->invalid_signers->fpr);
45 if (!result->signatures || result->signatures->next)
47 fprintf (stderr, "Unexpected number of signatures created\n");
50 if (result->signatures->type != type)
52 fprintf (stderr, "Wrong type of signature created\n");
55 if (result->signatures->pubkey_algo != GPGME_PK_RSA)
57 fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
58 result->signatures->pubkey_algo);
61 if (result->signatures->hash_algo != GPGME_MD_SHA1)
63 fprintf (stderr, "Wrong hash algorithm reported: %i\n",
64 result->signatures->hash_algo);
67 if (result->signatures->sig_class != 0)
69 fprintf (stderr, "Wrong signature class reported: %u\n",
70 result->signatures->sig_class);
73 if (strcmp ("3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
74 result->signatures->fpr))
76 fprintf (stderr, "Wrong fingerprint reported: %s\n",
77 result->signatures->fpr);
84 main (int argc, char *argv[])
89 gpgme_sign_result_t result;
91 init_gpgme (GPGME_PROTOCOL_CMS);
93 err = gpgme_new (&ctx);
96 gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
97 gpgme_set_textmode (ctx, 1);
98 gpgme_set_armor (ctx, 1);
100 err = gpgme_data_new_from_mem (&in, "Hallo Leute!\n", 13, 0);
103 /* First a normal signature. */
104 err = gpgme_data_new (&out);
106 err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
108 result = gpgme_op_sign_result (ctx);
109 check_result (result, GPGME_SIG_MODE_NORMAL);
111 gpgme_data_release (out);
113 /* Now a detached signature. */
114 gpgme_data_seek (in, 0, SEEK_SET);
115 err = gpgme_data_new (&out);
117 err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
119 result = gpgme_op_sign_result (ctx);
120 check_result (result, GPGME_SIG_MODE_DETACH);
122 gpgme_data_release (out);
124 gpgme_data_release (in);