1 /* t-decrypt.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. */
29 #define fail_if_err(err) \
34 fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
35 __FILE__, __LINE__, gpgme_strerror (err)); \
43 print_data (gpgme_data_t dh)
46 char buf[BUF_SIZE + 1];
49 ret = gpgme_data_seek (dh, 0, SEEK_SET);
51 fail_if_err (GPGME_File_Error);
52 while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
53 fwrite (buf, ret, 1, stdout);
55 fail_if_err (GPGME_File_Error);
60 passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
61 int last_was_bad, int fd)
63 write (fd, "abc\n", 4);
69 make_filename (const char *fname)
71 const char *srcdir = getenv ("srcdir");
76 buf = malloc (strlen(srcdir) + strlen(fname) + 2);
79 fprintf (stderr, "%s:%d: could not allocate string: %s\n",
80 __FILE__, __LINE__, strerror (errno));
91 main (int argc, char *argv[])
96 gpgme_decrypt_result_t result;
97 const char *cipher_1_asc = make_filename ("cipher-1.asc");
100 err = gpgme_new (&ctx);
103 agent_info = getenv("GPG_AGENT_INFO");
104 if (!(agent_info && strchr (agent_info, ':')))
105 gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
107 err = gpgme_data_new_from_file (&in, cipher_1_asc, 1);
110 err = gpgme_data_new (&out);
113 err = gpgme_op_decrypt (ctx, in, out);
115 result = gpgme_op_decrypt_result (ctx);
116 if (result->unsupported_algorithm)
118 fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
119 __FILE__, __LINE__, result->unsupported_algorithm);
124 gpgme_data_release (in);
125 gpgme_data_release (out);