1
/* t-sign.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. */
21
/* We need to include config.h so that we know whether we are building
22
with large file system (LFS) support. */
34
#include "t-support.h"
38
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
40
if (result->invalid_signers)
42
fprintf (stderr, "Invalid signer found: %s\n",
43
result->invalid_signers->fpr);
46
if (!result->signatures || result->signatures->next)
48
fprintf (stderr, "Unexpected number of signatures created\n");
51
if (result->signatures->type != type)
53
fprintf (stderr, "Wrong type of signature created\n");
56
if (result->signatures->pubkey_algo != GPGME_PK_DSA)
58
fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
59
result->signatures->pubkey_algo);
62
if (result->signatures->hash_algo != GPGME_MD_SHA1)
64
fprintf (stderr, "Wrong hash algorithm reported: %i\n",
65
result->signatures->hash_algo);
68
if (result->signatures->sig_class != 1)
70
fprintf (stderr, "Wrong signature class reported: %u\n",
71
result->signatures->sig_class);
74
if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
75
result->signatures->fpr))
77
fprintf (stderr, "Wrong fingerprint reported: %s\n",
78
result->signatures->fpr);
85
main (int argc, char **argv)
90
gpgme_sign_result_t result;
93
init_gpgme (GPGME_PROTOCOL_OpenPGP);
95
err = gpgme_new (&ctx);
98
agent_info = getenv ("GPG_AGENT_INFO");
99
if (!(agent_info && strchr (agent_info, ':')))
100
gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
102
gpgme_set_textmode (ctx, 1);
103
gpgme_set_armor (ctx, 1);
105
err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
108
/* First a normal signature. */
109
err = gpgme_data_new (&out);
111
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
113
result = gpgme_op_sign_result (ctx);
114
check_result (result, GPGME_SIG_MODE_NORMAL);
116
gpgme_data_release (out);
118
/* Now a detached signature. */
119
gpgme_data_seek (in, 0, SEEK_SET);
120
err = gpgme_data_new (&out);
122
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
124
result = gpgme_op_sign_result (ctx);
125
check_result (result, GPGME_SIG_MODE_DETACH);
127
gpgme_data_release (out);
129
/* And finally a cleartext signature. */
130
gpgme_data_seek (in, 0, SEEK_SET);
131
err = gpgme_data_new (&out);
133
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_CLEAR);
135
result = gpgme_op_sign_result (ctx);
136
check_result (result, GPGME_SIG_MODE_CLEAR);
138
gpgme_data_release (out);
140
gpgme_data_release (in);