1 /* t-signers.c - Regression tests for the multiple signers interface.
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. */
35 #include "t-support.h"
39 check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
41 gpgme_new_signature_t signature;
43 if (result->invalid_signers)
45 fprintf (stderr, "Invalid signer found: %s\n",
46 result->invalid_signers->fpr);
49 if (!result->signatures || !result->signatures->next
50 || result->signatures->next->next)
52 fprintf (stderr, "Unexpected number of signatures created\n");
56 signature = result->signatures;
59 if (signature->type != type)
61 fprintf (stderr, "Wrong type of signature created\n");
64 if (signature->pubkey_algo != GPGME_PK_DSA)
66 fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
67 signature->pubkey_algo);
70 if (signature->hash_algo != GPGME_MD_SHA1)
72 fprintf (stderr, "Wrong hash algorithm reported: %i\n",
73 signature->hash_algo);
76 if (signature->sig_class != 1)
78 fprintf (stderr, "Wrong signature class reported: %u\n",
79 signature->sig_class);
82 if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
84 && strcmp ("23FD347A419429BACCD5E72D6BC4778054ACD246",
87 fprintf (stderr, "Wrong fingerprint reported: %s\n",
91 signature = signature->next;
97 main (int argc, char *argv[])
101 gpgme_data_t in, out;
103 gpgme_sign_result_t result;
109 init_gpgme (GPGME_PROTOCOL_OpenPGP);
111 err = gpgme_new (&ctx);
114 agent_info = getenv("GPG_AGENT_INFO");
115 if (!(agent_info && strchr (agent_info, ':')))
116 gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
118 gpgme_set_textmode (ctx, 1);
119 gpgme_set_armor (ctx, 1);
121 err = gpgme_op_keylist_start (ctx, NULL, 1);
123 err = gpgme_op_keylist_next (ctx, &key[0]);
125 err = gpgme_op_keylist_next (ctx, &key[1]);
127 err = gpgme_op_keylist_end (ctx);
130 err = gpgme_signers_add (ctx, key[0]);
132 err = gpgme_signers_add (ctx, key[1]);
135 err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
138 /* First a normal signature. */
139 err = gpgme_data_new (&out);
141 err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
143 result = gpgme_op_sign_result (ctx);
144 check_result (result, GPGME_SIG_MODE_NORMAL);
146 gpgme_data_release (out);
148 /* Now a detached signature. */
149 gpgme_data_seek (in, 0, SEEK_SET);
150 err = gpgme_data_new (&out);
152 err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
154 result = gpgme_op_sign_result (ctx);
155 check_result (result, GPGME_SIG_MODE_DETACH);
157 gpgme_data_release (out);
159 /* And finally a cleartext signature. */
160 gpgme_data_seek (in, 0, SEEK_SET);
161 err = gpgme_data_new (&out);
163 err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR);
165 result = gpgme_op_sign_result (ctx);
166 check_result (result, GPGME_SIG_MODE_CLEAR);
168 gpgme_data_release (out);
169 gpgme_data_seek (in, 0, SEEK_SET);
171 gpgme_data_release (in);
174 gpgme_key_unref (key[0]);
175 gpgme_key_unref (key[1]);