From 16c4687a9c9c104ef8bc6e1e5bd7cb449dd1f4b7 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 28 Apr 2003 21:28:22 +0000 Subject: [PATCH] 2003-04-28 Marcus Brinkmann * gpgsm/t-decrypt.c (main): Rewritten. --- tests/ChangeLog | 2 + tests/gpgsm/t-decrypt.c | 101 ++++++++++++++++++++-------------------- tests/gpgsm/t-import.c | 2 +- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index 4c24f9c4..11cd38cf 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,7 @@ 2003-04-28 Marcus Brinkmann + * gpgsm/t-decrypt.c (main): Rewritten. + * gpg/t-decrypt.c: Rewritten. * gpg/t-signers.c: Rewritten. diff --git a/tests/gpgsm/t-decrypt.c b/tests/gpgsm/t-decrypt.c index 7b8e186b..499d82e3 100644 --- a/tests/gpgsm/t-decrypt.c +++ b/tests/gpgsm/t-decrypt.c @@ -1,32 +1,31 @@ -/* t-encrypt.c - regression test - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001 g10 Code GmbH - * - * 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 - */ +/* t-encrypt.c - Regression test. + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2003 g10 Code GmbH + + 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 GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include +#include #include -#include #include #include + static const char test_text1[] = "Hallo Leute!\n"; static const char test_cip1[] = "-----BEGIN CMS OBJECT-----\n" @@ -51,13 +50,14 @@ static const char test_cip1[] = static void print_data (GpgmeData dh) { - char buf[100]; +#define BUF_SIZE 512 + char buf[BUF_SIZE + 1]; int ret; ret = gpgme_data_seek (dh, 0, SEEK_SET); if (ret) fail_if_err (GPGME_File_Error); - while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0) fwrite (buf, ret, 1, stdout); if (ret < 0) fail_if_err (GPGME_File_Error); @@ -65,39 +65,38 @@ print_data (GpgmeData dh) int -main (int argc, char **argv ) +main (int argc, char *argv[]) { - GpgmeCtx ctx; - GpgmeError err; - GpgmeData in, out, pwdata = NULL; + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeDecryptResult result; - do { - err = gpgme_new (&ctx); - fail_if_err (err); - gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); - err = gpgme_data_new_from_mem ( &in, - test_cip1, strlen (test_cip1), 0 ); - fail_if_err (err); + err = gpgme_data_new_from_mem (&in, test_cip1, strlen (test_cip1), 0); + fail_if_err (err); - err = gpgme_data_new ( &out ); - 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 ); + err = gpgme_op_decrypt (ctx, in, out); + fail_if_err (err); + result = gpgme_op_decrypt_result (ctx); + if (result->unsupported_algorithm) + { + fprintf (stderr, "%s:%i: unsupported algorithm: %s\n", + __FILE__, __LINE__, result->unsupported_algorithm); + exit (1); + } + print_data (out); - gpgme_data_release (in); - gpgme_data_release (out); - gpgme_data_release (pwdata); - gpgme_release (ctx); - } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); - - return 0; + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + return 0; } diff --git a/tests/gpgsm/t-import.c b/tests/gpgsm/t-import.c index 332b0407..219ce95b 100644 --- a/tests/gpgsm/t-import.c +++ b/tests/gpgsm/t-import.c @@ -1,4 +1,4 @@ -/* t-import.c - regression test +/* t-import.c - Regression test. Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2001, 2003 g10 Code GmbH