1 /* t-decrypt-verify.c - regression test
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001 g10 Code GmbH
5 * This file is part of GPGME.
7 * GPGME is free software; you can redistribute it and/or modify
8 * it 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,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
31 struct passphrase_cb_info_s
38 #define fail_if_err(a) do { if(a) { int my_errno = errno; \
39 fprintf (stderr, "%s:%d: GpgmeError %s\n", \
40 __FILE__, __LINE__, gpgme_strerror(a)); \
41 if ((a) == GPGME_File_Error) \
42 fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \
47 print_data (GpgmeData dh)
53 err = gpgme_data_rewind (dh);
55 while (!(err = gpgme_data_read (dh, buf, 100, &nread)))
56 fwrite ( buf, nread, 1, stdout );
62 passphrase_cb (void *opaque, const char *desc, void *r_hd)
68 /* Cleanup by looking at *r_hd. */
73 fprintf (stderr, "%% requesting passphrase for `%s': ", desc);
74 fprintf (stderr, "sending `%s'\n", pass);
80 mk_fname (const char *fname)
82 const char *srcdir = getenv ("srcdir");
87 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
97 main (int argc, char **argv)
101 GpgmeData in, out, pwdata = NULL;
102 struct passphrase_cb_info_s info;
103 const char *cipher_2_asc = mk_fname ("cipher-2.asc");
108 err = gpgme_new (&ctx);
110 if (!getenv("GPG_AGENT_INFO"))
112 memset (&info, 0, sizeof info);
114 gpgme_set_passphrase_cb (ctx, passphrase_cb, &info);
117 err = gpgme_data_new_from_file (&in, cipher_2_asc, 1);
120 err = gpgme_data_new (&out);
123 err = gpgme_op_decrypt_verify (ctx, in, out, &stat);
127 fputs ("Begin Result:\n", stdout);
129 fputs ("End Result.\n", stdout);
131 if (stat != GPGME_SIG_STAT_GOOD)
133 fprintf (stderr, "Signature check failed unexpectedly.\n");
137 gpgme_data_release (in);
138 gpgme_data_release (out);
139 gpgme_data_release (pwdata);
142 while (argc > 1 && !strcmp (argv[1], "--loop"));