aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2000-11-16 13:15:48 +0000
committerWerner Koch <[email protected]>2000-11-16 13:15:48 +0000
commit7f8c3532e793512b52e1c07149668ec7c6d87a65 (patch)
tree533f3854dc1023dee1aed13ef9b751bbf4288601 /tests
parentNotation stuff added (diff)
downloadgpgme-7f8c3532e793512b52e1c07149668ec7c6d87a65.tar.gz
gpgme-7f8c3532e793512b52e1c07149668ec7c6d87a65.zip
Added decryption
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/cipher-1.asc15
-rw-r--r--tests/t-decrypt.c88
-rw-r--r--tests/t-encrypt.c4
-rw-r--r--tests/t-verify.c9
5 files changed, 114 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 74709b11..2f74e93f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,8 @@
## Process this file with automake to create Makefile.in
-TESTS = t-encrypt t-verify t-keylist
+TESTS = t-encrypt t-decrypt t-verify t-keylist
+
+EXTRA_DIST = cipher-1.asc
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
diff --git a/tests/cipher-1.asc b/tests/cipher-1.asc
new file mode 100644
index 00000000..f0a8ca45
--- /dev/null
+++ b/tests/cipher-1.asc
@@ -0,0 +1,15 @@
+-----BEGIN PGP MESSAGE-----
+Version: GnuPG v1.0.4-2 (GNU/Linux)
+Comment: For info see http://www.gnupg.org
+
+hQEOA2rm1+5GqHH4EAP/Tcqiuhvrjj+RFBKnWn2A7f1ztV17U2EngYFy8TbZYGNp
+JoMNdpA7GNZs7iqc/x1epaZDKfaQwWEtARZmK/4nlhB48N+oZeKTm7PXIkRPqrCZ
+3fxJjCJaU0yrNGuO345DOr0QwDImVhubVEkfgs8yXK2Szx2G8X3LmiaILHAqA2oD
+/1ZqjY8k+ovrLL/qe8un/NTwzSjKIPVGR6mhLFXmj8fnp2kSsbo+Bhh4MczTRR6l
+SA32z25vcakKu2qn5Wa4yDcx9NcMt8RHXzmfMDLj6UFq99QqKeLK2ywcIpY9p/GL
+fQyaf7r3HTVugBSaoOzegLJ+L7MfWohrStkMeLnJQnro0nYBjADVcUQuSS4N3lst
+Df3XrxxA/iJvxt4F9K27u4tp5U1HDg1CIxVrkMs92LBri3S6ZtfjdoqQ7QghFwGP
+Kw1lKiWayM6NH9rcCKSgk4kl4P/2l3f78XeFgiywN7UGeSoH3BLMSv9gSxl5KrAz
+d2imhTMrfEvZ
+=y4ng
+-----END PGP MESSAGE-----
diff --git a/tests/t-decrypt.c b/tests/t-decrypt.c
new file mode 100644
index 00000000..0b066f5e
--- /dev/null
+++ b/tests/t-decrypt.c
@@ -0,0 +1,88 @@
+/* t-encrypt.c - regression test
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GPGME is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include "../gpgme/gpgme.h"
+
+#define fail_if_err(a) do { if(a) { int my_errno = errno; \
+ fprintf (stderr, "%s:%d: GpgmeError %s\n", \
+ __FILE__, __LINE__, gpgme_strerror(a)); \
+ if ((a) == GPGME_File_Error) \
+ fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \
+ exit (1); } \
+ } while(0)
+
+static void
+print_data ( GpgmeData dh )
+{
+ char buf[100];
+ size_t nread;
+ GpgmeError err;
+
+ err = gpgme_data_rewind ( dh );
+ fail_if_err (err);
+ while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) {
+ fwrite ( buf, nread, 1, stdout );
+ }
+ if (err != GPGME_EOF)
+ fail_if_err (err);
+}
+
+
+
+int
+main (int argc, char **argv )
+{
+ GpgmeCtx ctx;
+ GpgmeError err;
+ GpgmeData in, out;
+
+ do {
+ err = gpgme_new (&ctx);
+ fail_if_err (err);
+
+ err = gpgme_data_new_from_file ( &in, "cipher-1.asc", 1 );
+ fail_if_err (err);
+
+ err = gpgme_data_new ( &out );
+ fail_if_err (err);
+
+ err = gpgme_op_decrypt (ctx, in, out );
+ fail_if_err (err);
+
+ fflush (NULL);
+ fputs ("Begin Result:\n", stdout );
+ print_data (out);
+ fputs ("End Result.\n", stdout );
+
+ gpgme_data_release (in);
+ gpgme_data_release (out);
+ gpgme_release (ctx);
+ } while ( argc > 1 && !strcmp( argv[1], "--loop" ) );
+
+ return 0;
+}
+
+
diff --git a/tests/t-encrypt.c b/tests/t-encrypt.c
index 88ceaeee..01c5379e 100644
--- a/tests/t-encrypt.c
+++ b/tests/t-encrypt.c
@@ -61,10 +61,10 @@ main (int argc, char **argv )
err = gpgme_new (&ctx);
fail_if_err (err);
- err = gpgme_data_new ( &in, "Hallo Leute\n", 12, 0 );
+ err = gpgme_data_new_from_mem ( &in, "Hallo Leute\n", 12, 0 );
fail_if_err (err);
- err = gpgme_data_new ( &out, NULL, 0,0 );
+ err = gpgme_data_new ( &out );
fail_if_err (err);
err = gpgme_recipients_new (&rset);
diff --git a/tests/t-verify.c b/tests/t-verify.c
index 5ab6bbca..bc997236 100644
--- a/tests/t-verify.c
+++ b/tests/t-verify.c
@@ -105,9 +105,11 @@ main (int argc, char **argv )
fail_if_err (err);
do {
- err = gpgme_data_new ( &text, test_text1, strlen (test_text1), 0 );
+ err = gpgme_data_new_from_mem ( &text,
+ test_text1, strlen (test_text1), 0 );
fail_if_err (err);
- err = gpgme_data_new ( &sig, test_sig1, strlen (test_sig1), 0 );
+ err = gpgme_data_new_from_mem ( &sig,
+ test_sig1, strlen (test_sig1), 0 );
fail_if_err (err);
puts ("checking a valid message:\n");
@@ -119,7 +121,8 @@ main (int argc, char **argv )
puts ("checking a manipulated message:\n");
gpgme_data_release (text);
- err = gpgme_data_new ( &text, test_text1f, strlen (test_text1f), 0 );
+ err = gpgme_data_new_from_mem ( &text,
+ test_text1f, strlen (test_text1f), 0 );
fail_if_err (err);
gpgme_data_rewind ( sig );
err = gpgme_op_verify (ctx, sig, text, &status );