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. */
32
#include "t-support.h"
36
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
38
if (result->invalid_signers)
40
fprintf (stderr, "Invalid signer found: %s\n",
41
result->invalid_signers->fpr);
44
if (!result->signatures || result->signatures->next)
46
fprintf (stderr, "Unexpected number of signatures created\n");
49
if (result->signatures->type != type)
51
fprintf (stderr, "Wrong type of signature created\n");
54
if (result->signatures->pubkey_algo != GPGME_PK_RSA)
56
fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
57
result->signatures->pubkey_algo);
60
if (result->signatures->hash_algo != GPGME_MD_SHA1)
62
fprintf (stderr, "Wrong hash algorithm reported: %i\n",
63
result->signatures->hash_algo);
66
if (result->signatures->sig_class != 0)
68
fprintf (stderr, "Wrong signature class reported: %u\n",
69
result->signatures->sig_class);
72
if (strcmp ("3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
73
result->signatures->fpr))
75
fprintf (stderr, "Wrong fingerprint reported: %s\n",
76
result->signatures->fpr);
83
main (int argc, char *argv[])
88
gpgme_sign_result_t result;
90
init_gpgme (GPGME_PROTOCOL_CMS);
92
err = gpgme_new (&ctx);
95
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
96
gpgme_set_textmode (ctx, 1);
97
gpgme_set_armor (ctx, 1);
99
err = gpgme_data_new_from_mem (&in, "Hallo Leute!\n", 13, 0);
102
/* First a normal signature. */
103
err = gpgme_data_new (&out);
105
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_NORMAL);
107
result = gpgme_op_sign_result (ctx);
108
check_result (result, GPGME_SIG_MODE_NORMAL);
110
gpgme_data_release (out);
112
/* Now a detached signature. */
113
gpgme_data_seek (in, 0, SEEK_SET);
114
err = gpgme_data_new (&out);
116
err = gpgme_op_sign (ctx, in, out, GPGME_SIG_MODE_DETACH);
118
result = gpgme_op_sign_result (ctx);
119
check_result (result, GPGME_SIG_MODE_DETACH);
121
gpgme_data_release (out);
123
gpgme_data_release (in);