1 /* t-decrypt-verify.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 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. */
29 #include "t-support.h"
33 check_verify_result (gpgme_verify_result_t result, int summary, char *fpr,
36 gpgme_signature_t sig;
38 sig = result->signatures;
39 if (!sig || sig->next)
41 fprintf (stderr, "%s:%i: Unexpected number of signatures\n",
45 if (sig->summary != summary)
47 fprintf (stderr, "%s:%i: Unexpected signature summary: 0x%x\n",
48 __FILE__, __LINE__, sig->summary);
51 if (strcmp (sig->fpr, fpr))
53 fprintf (stderr, "%s:%i: Unexpected fingerprint: %s\n",
54 __FILE__, __LINE__, sig->fpr);
57 if (gpg_err_code (sig->status) != status)
59 fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
60 __FILE__, __LINE__, gpgme_strerror (sig->status));
65 fprintf (stderr, "%s:%i: Unexpected notation data\n",
69 if (sig->wrong_key_usage)
71 fprintf (stderr, "%s:%i: Unexpectedly wrong key usage\n",
75 if (sig->validity != GPGME_VALIDITY_UNKNOWN)
77 fprintf (stderr, "%s:%i: Unexpected validity: %i\n",
78 __FILE__, __LINE__, sig->validity);
81 if (gpg_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
83 fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
84 __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
91 main (int argc, char *argv[])
96 gpgme_decrypt_result_t decrypt_result;
97 gpgme_verify_result_t verify_result;
98 const char *cipher_2_asc = make_filename ("cipher-2.asc");
101 err = gpgme_new (&ctx);
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_file (&in, cipher_2_asc, 1);
110 err = gpgme_data_new (&out);
113 err = gpgme_op_decrypt_verify (ctx, in, out);
115 decrypt_result = gpgme_op_decrypt_result (ctx);
116 if (decrypt_result->unsupported_algorithm)
118 fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
119 __FILE__, __LINE__, decrypt_result->unsupported_algorithm);
123 verify_result = gpgme_op_verify_result (ctx);
124 check_verify_result (verify_result, 0,
125 "A0FF4590BB6122EDEF6E3C542D727CC768697734",
128 gpgme_data_release (in);
129 gpgme_data_release (out);