1 /* t-encrypt-sign.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 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 if (result->invalid_signers)
43 fprintf (stderr, "Invalid signer found: %s\n",
44 result->invalid_signers->fpr);
47 if (!result->signatures || result->signatures->next)
49 fprintf (stderr, "Unexpected number of signatures created\n");
52 if (result->signatures->type != type)
54 fprintf (stderr, "Wrong type of signature created\n");
57 if (result->signatures->pubkey_algo != GPGME_PK_DSA)
59 fprintf (stderr, "Wrong pubkey algorithm reported: %i\n",
60 result->signatures->pubkey_algo);
63 if (result->signatures->hash_algo != GPGME_MD_SHA1
64 && result->signatures->hash_algo != GPGME_MD_RMD160)
66 fprintf (stderr, "Wrong hash algorithm reported: %i\n",
67 result->signatures->hash_algo);
70 if (result->signatures->sig_class != 0)
72 fprintf (stderr, "Wrong signature class reported: %u\n",
73 result->signatures->sig_class);
76 if (strcmp ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
77 result->signatures->fpr))
79 fprintf (stderr, "Wrong fingerprint reported: %s\n",
80 result->signatures->fpr);
87 main (int argc, char **argv)
92 gpgme_key_t key[3] = { NULL, NULL, NULL };
93 gpgme_encrypt_result_t result;
94 gpgme_sign_result_t sign_result;
97 init_gpgme (GPGME_PROTOCOL_OpenPGP);
99 err = gpgme_new (&ctx);
101 gpgme_set_textmode (ctx, 1);
102 gpgme_set_armor (ctx, 1);
104 agent_info = getenv("GPG_AGENT_INFO");
105 if (!(agent_info && strchr (agent_info, ':')))
106 gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
108 err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
111 err = gpgme_data_new (&out);
114 err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
117 err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
121 err = gpgme_op_encrypt_sign (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
123 result = gpgme_op_encrypt_result (ctx);
124 if (result->invalid_recipients)
126 fprintf (stderr, "Invalid recipient encountered: %s\n",
127 result->invalid_recipients->fpr);
130 sign_result = gpgme_op_sign_result (ctx);
131 check_result (sign_result, GPGME_SIG_MODE_NORMAL);
134 gpgme_key_unref (key[0]);
135 gpgme_key_unref (key[1]);
136 gpgme_data_release (in);
137 gpgme_data_release (out);
139 /* Now a second time using symmetric encryption. */
140 err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
143 err = gpgme_data_new (&out);
146 err = gpgme_op_encrypt_sign (ctx, NULL, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
148 sign_result = gpgme_op_sign_result (ctx);
149 check_result (sign_result, GPGME_SIG_MODE_NORMAL);
152 gpgme_data_release (in);
153 gpgme_data_release (out);