From: Marcus Brinkmann Date: Mon, 28 Apr 2003 21:17:15 +0000 (+0000) Subject: doc/ X-Git-Tag: gpgme-1.2.0@1385~655 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3eac6d6d7b5217aaf47afbcef7535e6424df40ca;p=gpgme.git doc/ 2003-04-28 Marcus Brinkmann * gpgme.texi (Decrypt): Descript gpgme_op_decrypt_result and GpgmeDecryptResult. gpgme 2003-04-28 Marcus Brinkmann * gpgme.h (struct _gpgme_op_decrypt_result): New structure. (GpgmeDecryptResult): New type. (gpgme_op_decrypt_result): New prototype. * ops.h (_gpgme_op_decrypt_init_result): New prototype. (_gpgme_decrypt_status_handler): Fix prototype. (_gpgme_decrypt_start): Remove prototype. * decrypt-verify.c: Do not include , , and , "util.h" and "context.h", but "gpgme.h". (decrypt_verify_status_handler): Change first argument to void *, and rework error handling. (_gpgme_op_decrypt_verify_start): New function. (gpgme_op_decrypt_verify_start): Rewrite using _gpgme_op_decrypt_verify_start. (gpgme_op_decrypt_verify): Likewise. * decrypt.c: Include , "gpgme.h" and "util.h". (struct decrypt_result): Change to typedef op_data_t, rewritten. (is_token): Remove function. (release_op_data): New function. (skip_token): Remove function. (gpgme_op_decrypt_result): New function. (_gpgme_decrypt_status_handler): Change first argument to void *. Rework error handling. (_gpgme_decrypt_start): Rename to ... (decrypt_start): ... this. Call _gpgme_op_decrypt_init_result. (_gpgme_op_decrypt_init_result): New function. (gpgme_op_decrypt_start): Use decrypt_start. (gpgme_op_decrypt): Likewise. tests/ 2003-04-28 Marcus Brinkmann * gpg/t-decrypt.c: Rewritten. --- diff --git a/trunk/NEWS b/trunk/NEWS index fb15c63..b6c166f 100644 --- a/trunk/NEWS +++ b/trunk/NEWS @@ -86,6 +86,14 @@ Noteworthy changes in version 0.4.1 (unreleased) information about the result of an encryption operation in a GpgmeEncryptResult object. + * The new gpgme_op_encrypt_result function provides detailed + information about the result of an encryption operation in + a GpgmeEncryptResult object. + + * The new gpgme_op_decrypt_result function provides detailed + information about the result of an encryption operation in + a GpgmeDecryptResult object. + * Interface changes relative to the 0.4.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GpgmeIOCb CHANGED: Return type from void to GpgmeError. @@ -126,6 +134,8 @@ gpgme_pubkey_algo_name NEW gpgme_hash_algo_name NEW GpgmeEncryptResult NEW gpgme_op_encrypt_result NEW +GpgmeDecryptResult NEW +gpgme_op_decrypt_result NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 0.4.0 (2002-12-23) diff --git a/trunk/doc/ChangeLog b/trunk/doc/ChangeLog index 00055c8..778625e 100644 --- a/trunk/doc/ChangeLog +++ b/trunk/doc/ChangeLog @@ -1,3 +1,8 @@ +2003-04-28 Marcus Brinkmann + + * gpgme.texi (Decrypt): Descript gpgme_op_decrypt_result and + GpgmeDecryptResult. + 2003-04-27 Marcus Brinkmann * gpgme.texi (Encrypting a Plaintext): Add info about diff --git a/trunk/doc/gpgme.texi b/trunk/doc/gpgme.texi index 137e967..4e15fa0 100644 --- a/trunk/doc/gpgme.texi +++ b/trunk/doc/gpgme.texi @@ -2774,6 +2774,30 @@ started successfully, and @code{GPGME_Invalid_Value} if @var{cipher} or @var{plain} is not a valid pointer. @end deftypefun +@deftp {Data type} {GpgmeDecryptResult} +This is a pointer to a structure used to store the result of a +@code{gpgme_op_decrypt} operation. After successfully encrypting +data, you can retrieve the pointer to the result with +@code{gpgme_op_decrypt_result}. The structure contains the following +members: + +@table @code +@item char *unsupported_algorithm +If an unsupported algorithm was encountered, this string describes the +algorithm that is not supported. +@end table +@end deftp + +@deftypefun GpgmeDecryptResult gpgme_op_decrypt_result (@w{GpgmeCtx @var{ctx}}) +The function @code{gpgme_op_decrypt_result} returns a +@code{GpgmeDecryptResult} pointer to a structure holding the result of +a @code{gpgme_op_decrypt} operation. The pointer is only valid if the +last operation on the context was a @code{gpgme_op_decrypt} or +@code{gpgme_op_decrypt_start} operation, and if this operation +finished successfully. The returned pointer is only valid until the +next operation is started on the context. +@end deftypefun + @node Verify @subsection Verify diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 0a798c6..720dc7b 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,34 @@ +2003-04-28 Marcus Brinkmann + + * gpgme.h (struct _gpgme_op_decrypt_result): New structure. + (GpgmeDecryptResult): New type. + (gpgme_op_decrypt_result): New prototype. + * ops.h (_gpgme_op_decrypt_init_result): New prototype. + (_gpgme_decrypt_status_handler): Fix prototype. + (_gpgme_decrypt_start): Remove prototype. + * decrypt-verify.c: Do not include , , + and , "util.h" and "context.h", but + "gpgme.h". + (decrypt_verify_status_handler): Change first argument to void *, + and rework error handling. + (_gpgme_op_decrypt_verify_start): New function. + (gpgme_op_decrypt_verify_start): Rewrite using + _gpgme_op_decrypt_verify_start. + (gpgme_op_decrypt_verify): Likewise. + * decrypt.c: Include , "gpgme.h" and "util.h". + (struct decrypt_result): Change to typedef op_data_t, rewritten. + (is_token): Remove function. + (release_op_data): New function. + (skip_token): Remove function. + (gpgme_op_decrypt_result): New function. + (_gpgme_decrypt_status_handler): Change first argument to void *. + Rework error handling. + (_gpgme_decrypt_start): Rename to ... + (decrypt_start): ... this. Call _gpgme_op_decrypt_init_result. + (_gpgme_op_decrypt_init_result): New function. + (gpgme_op_decrypt_start): Use decrypt_start. + (gpgme_op_decrypt): Likewise. + 2003-04-27 Marcus Brinkmann * encrypt-sign.c: Do not include , , diff --git a/trunk/gpgme/decrypt-verify.c b/trunk/gpgme/decrypt-verify.c index d2939f6..0a94522 100644 --- a/trunk/gpgme/decrypt-verify.c +++ b/trunk/gpgme/decrypt-verify.c @@ -1,4 +1,4 @@ -/* decrypt-verify.c - decrypt and verify functions +/* decrypt-verify.c - Decrypt and verify function. Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2001, 2002, 2003 g10 Code GmbH @@ -21,56 +21,69 @@ #if HAVE_CONFIG_H #include #endif -#include -#include -#include -#include -#include "util.h" -#include "context.h" +#include "gpgme.h" #include "ops.h" + +static GpgmeError +decrypt_verify_status_handler (void *priv, GpgmeStatusCode code, char *args) +{ + return _gpgme_decrypt_status_handler (priv, code, args) + || _gpgme_verify_status_handler (priv, code, args); +} + static GpgmeError -decrypt_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) +_gpgme_op_decrypt_verify_start (GpgmeCtx ctx, int synchronous, + GpgmeData cipher, GpgmeData plain) { - GpgmeError err = _gpgme_decrypt_status_handler (ctx, code, args); + GpgmeError err; + + err = _gpgme_op_reset (ctx, synchronous); + if (err) + return err; + + err = _gpgme_op_decrypt_init_result (ctx); if (err) return err; - return _gpgme_verify_status_handler (ctx, code, args); + + if (!cipher) + return GPGME_No_Data; + if (!plain) + return GPGME_Invalid_Value; + + if (ctx->passphrase_cb) + { + err = _gpgme_engine_set_command_handler (ctx->engine, + _gpgme_passphrase_command_handler, + ctx, NULL); + if (err) + return err; + } + + _gpgme_engine_set_status_handler (ctx->engine, + decrypt_verify_status_handler, ctx); + + return _gpgme_engine_op_decrypt (ctx->engine, cipher, plain); } +/* Decrypt ciphertext CIPHER and make a signature verification within + CTX and store the resulting plaintext in PLAIN. */ GpgmeError -gpgme_op_decrypt_verify_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain) +gpgme_op_decrypt_verify_start (GpgmeCtx ctx, GpgmeData cipher, GpgmeData plain) { - return _gpgme_decrypt_start (ctx, 0, ciph, plain, - decrypt_verify_status_handler); + return _gpgme_op_decrypt_verify_start (ctx, 0, cipher, plain); } -/** - * gpgme_op_decrypt_verify: - * @ctx: The context - * @in: ciphertext input - * @out: plaintext output - * - * This function decrypts @in to @out and performs a signature check. - * Other parameters are take from the context @c. - * The function does wait for the result. - * - * Return value: 0 on success or an errorcode. - **/ +/* Decrypt ciphertext CIPHER and make a signature verification within + CTX and store the resulting plaintext in PLAIN. */ GpgmeError -gpgme_op_decrypt_verify (GpgmeCtx ctx, GpgmeData in, GpgmeData out) +gpgme_op_decrypt_verify (GpgmeCtx ctx, GpgmeData cipher, GpgmeData plain) { - GpgmeError err; - - gpgme_data_release (ctx->notation); - ctx->notation = NULL; - - err = _gpgme_decrypt_start (ctx, 1, in, out, - decrypt_verify_status_handler); + GpgmeError err = _gpgme_op_decrypt_verify_start (ctx, 1, cipher, plain); if (!err) err = _gpgme_wait_one (ctx); return err; diff --git a/trunk/gpgme/decrypt.c b/trunk/gpgme/decrypt.c index e10a16d..5d591f6 100644 --- a/trunk/gpgme/decrypt.c +++ b/trunk/gpgme/decrypt.c @@ -22,148 +22,133 @@ #include #endif #include +#include +#include "gpgme.h" +#include "util.h" #include "context.h" #include "ops.h" - -struct decrypt_result + +typedef struct { + struct _gpgme_op_decrypt_result result; + int okay; int failed; -}; -typedef struct decrypt_result *DecryptResult; +} *op_data_t; -/* Check whether STRING starts with TOKEN and return true in this - case. This is case insensitive. If NEXT is not NULL return the - number of bytes to be added to STRING to get to the next token; a - returned value of 0 indicates end of line. - Fixme: Duplicated from verify.c. */ -static int -is_token (const char *string, const char *token, size_t *next) +static void +release_op_data (void *hook) { - size_t n = 0; + op_data_t opd = (op_data_t) hook; - for (;*string && *token && *string == *token; string++, token++, n++) - ; - if (*token || (*string != ' ' && !*string)) - return 0; - if (next) - { - for (; *string == ' '; string++, n++) - ; - *next = n; - } - return 1; + if (opd->result.unsupported_algorithm) + free (opd->result.unsupported_algorithm); } -static int -skip_token (const char *string, size_t *next) +GpgmeDecryptResult +gpgme_op_decrypt_result (GpgmeCtx ctx) { - size_t n = 0; - - for (;*string && *string != ' '; string++, n++) - ; - for (;*string == ' '; string++, n++) - ; - if (!*string) - return 0; - if (next) - *next = n; - return 1; -} + op_data_t opd; + GpgmeError err; + err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &opd, -1, NULL); + if (err || !opd) + return NULL; + return &opd->result; +} + + GpgmeError -_gpgme_decrypt_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) +_gpgme_decrypt_status_handler (void *priv, GpgmeStatusCode code, char *args) { - DecryptResult result; - GpgmeError err = 0; - size_t n; + GpgmeCtx ctx = (GpgmeCtx) priv; + GpgmeError err; + op_data_t opd; - err = _gpgme_passphrase_status_handler (ctx, code, args); + err = _gpgme_passphrase_status_handler (priv, code, args); + if (err) + return err; + + err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &opd, -1, NULL); if (err) return err; switch (code) { case GPGME_STATUS_EOF: - err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result, - -1, NULL); - if (!err) - { - if (result && result->failed) - err = GPGME_Decryption_Failed; - else if (!result || !result->okay) - err = GPGME_No_Data; - } + if (opd->failed) + return GPGME_Decryption_Failed; + else if (!opd->okay) + return GPGME_No_Data; break; case GPGME_STATUS_DECRYPTION_OKAY: - err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result, - sizeof (*result), NULL); - if (!err) - result->okay = 1; + opd->okay = 1; break; case GPGME_STATUS_DECRYPTION_FAILED: - err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result, - sizeof (*result), NULL); - if (!err) - result->failed = 1; + opd->failed = 1; break; case GPGME_STATUS_ERROR: - if (is_token (args, "decrypt.algorithm", &n) && n) - { - args += n; - if (is_token (args, "Unsupported_Algorithm", &n)) - { - GpgmeData dh; - - args += n; - /* Fixme: This won't work when used with decrypt+verify */ - if (!gpgme_data_new (&dh)) - { - _gpgme_data_append_string (dh, - "\n" - " \n" - " \n" - " "); - if (skip_token (args, &n)) - { - int c = args[n]; - args[n] = 0; - _gpgme_data_append_percentstring_for_xml (dh, args); - args[n] = c; - } - else - _gpgme_data_append_percentstring_for_xml (dh, args); - - _gpgme_data_append_string (dh, - "\n" - " \n" - " \n" - "\n"); - _gpgme_set_op_info (ctx, dh); - } - } - } + { + const char d_alg[] = "decrypt.algorithm"; + const char u_alg[] = "Unsupported_Algorithm"; + if (!strncmp (args, d_alg, sizeof (d_alg) - 1)) + { + args += sizeof (d_alg); + while (*args == ' ') + args++; + + if (!strncmp (args, u_alg, sizeof (u_alg) - 1)) + { + char *end; + + args += sizeof (u_alg); + while (*args == ' ') + args++; + + end = strchr (args, ' '); + if (end) + *end = '\0'; + + if (!(*args == '?' && *(args + 1) == '\0')) + { + opd->result.unsupported_algorithm = strdup (args); + if (!opd->result.unsupported_algorithm) + return GPGME_Out_Of_Core; + } + } + } + } break; default: break; } - return err; + return 0; } GpgmeError -_gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, - GpgmeData cipher, GpgmeData plain, void *status_handler) +_gpgme_op_decrypt_init_result (GpgmeCtx ctx) +{ + op_data_t opd; + + return _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &opd, + sizeof (*opd), release_op_data); +} + + +static GpgmeError +decrypt_start (GpgmeCtx ctx, int synchronous, + GpgmeData cipher, GpgmeData plain) { GpgmeError err; @@ -171,6 +156,10 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, if (err) return err; + err = _gpgme_op_decrypt_init_result (ctx); + if (err) + return err; + if (!cipher) return GPGME_No_Data; if (!plain) @@ -188,38 +177,27 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, return err; } - _gpgme_engine_set_status_handler (ctx->engine, status_handler, ctx); + _gpgme_engine_set_status_handler (ctx->engine, + _gpgme_decrypt_status_handler, ctx); return _gpgme_engine_op_decrypt (ctx->engine, cipher, plain); } GpgmeError -gpgme_op_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain) +gpgme_op_decrypt_start (GpgmeCtx ctx, GpgmeData cipher, GpgmeData plain) { - return _gpgme_decrypt_start (ctx, 0, ciph, plain, - _gpgme_decrypt_status_handler); + return decrypt_start (ctx, 0, cipher, plain); } -/** - * gpgme_op_decrypt: - * @ctx: The context - * @in: ciphertext input - * @out: plaintext output - * - * This function decrypts @in to @out. - * Other parameters are take from the context @ctx. - * The function does wait for the result. - * - * Return value: 0 on success or an errorcode. - **/ +/* Decrypt ciphertext CIPHER within CTX and store the resulting + plaintext in PLAIN. */ GpgmeError -gpgme_op_decrypt (GpgmeCtx ctx, GpgmeData in, GpgmeData out) +gpgme_op_decrypt (GpgmeCtx ctx, GpgmeData cipher, GpgmeData plain) { - GpgmeError err = _gpgme_decrypt_start (ctx, 1, in, out, - _gpgme_decrypt_status_handler); + GpgmeError err = decrypt_start (ctx, 1, cipher, plain); if (!err) - err = _gpgme_wait_one (ctx); + err = _gpgme_wait_one (ctx); return err; } diff --git a/trunk/gpgme/gpgme.h b/trunk/gpgme/gpgme.h index ef0434b..0071f06 100644 --- a/trunk/gpgme/gpgme.h +++ b/trunk/gpgme/gpgme.h @@ -798,6 +798,16 @@ GpgmeError gpgme_op_encrypt_sign (GpgmeCtx ctx, GpgmeData plain, GpgmeData cipher); +/* Decryption. */ +struct _gpgme_op_decrypt_result +{ + char *unsupported_algorithm; +}; +typedef struct _gpgme_op_decrypt_result *GpgmeDecryptResult; + +/* Retrieve a pointer to the result of the decrypt operation. */ +GpgmeDecryptResult gpgme_op_decrypt_result (GpgmeCtx ctx); + /* Decrypt ciphertext CIPHER within CTX and store the resulting plaintext in PLAIN. */ GpgmeError gpgme_op_decrypt_start (GpgmeCtx ctx, diff --git a/trunk/gpgme/ops.h b/trunk/gpgme/ops.h index 4812bfe..165a517 100644 --- a/trunk/gpgme/ops.h +++ b/trunk/gpgme/ops.h @@ -77,12 +77,11 @@ GpgmeError _gpgme_parse_inv_userid (char *args, GpgmeInvalidUserID *userid); GpgmeError _gpgme_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args); -/*-- decrypt.c --*/ -GpgmeError _gpgme_decrypt_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, + +/* From decrypt.c. */ +GpgmeError _gpgme_op_decrypt_init_result (GpgmeCtx ctx); +GpgmeError _gpgme_decrypt_status_handler (void *priv, GpgmeStatusCode code, char *args); -GpgmeError _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, - GpgmeData ciph, GpgmeData plain, - void *status_handler); /* From sign.c. */ diff --git a/trunk/tests/ChangeLog b/trunk/tests/ChangeLog index 091986f..4c24f9c 100644 --- a/trunk/tests/ChangeLog +++ b/trunk/tests/ChangeLog @@ -1,6 +1,8 @@ 2003-04-28 Marcus Brinkmann - * gpg/t-signers.c (print_data): Rewritten. + * gpg/t-decrypt.c: Rewritten. + + * gpg/t-signers.c: Rewritten. 2003-04-27 Marcus Brinkmann diff --git a/trunk/tests/gpg/t-decrypt.c b/trunk/tests/gpg/t-decrypt.c index 39f534f..6aaacab 100644 --- a/trunk/tests/gpg/t-decrypt.c +++ b/trunk/tests/gpg/t-decrypt.c @@ -1,56 +1,54 @@ /* t-decrypt.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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + 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 -struct passphrase_cb_info_s { - GpgmeCtx c; - int did_it; -}; +#define fail_if_err(err) \ + do \ + { \ + if (err) \ + { \ + fprintf (stderr, "%s:%d: GpgmeError %s\n", \ + __FILE__, __LINE__, gpgme_strerror (err)); \ + exit (1); \ + } \ + } \ + while (0) -#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]; +#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); @@ -58,81 +56,75 @@ print_data (GpgmeData dh) static GpgmeError -passphrase_cb (void *opaque, const char *desc, - void **r_hd, const char **result) +passphrase_cb (void *opaque, const char *desc, void **hd, const char **result) { + /* Cleanup by looking at *hd. */ if (!desc) - /* Cleanup by looking at *r_hd. */ return 0; *result = "abc"; - fprintf (stderr, "%% requesting passphrase for `%s': ", desc); - fprintf (stderr, "sending `%s'\n", *result); - return 0; } static char * -mk_fname ( const char *fname ) +make_filename (const char *fname) { - const char *srcdir = getenv ("srcdir"); - char *buf; - - if (!srcdir) - srcdir = "."; - buf = malloc (strlen(srcdir) + strlen(fname) + 2 ); - if (!buf ) - exit (8); - strcpy (buf, srcdir); - strcat (buf, "/"); - strcat (buf, fname ); - return buf; + const char *srcdir = getenv ("srcdir"); + char *buf; + + if (!srcdir) + srcdir = "."; + buf = malloc (strlen(srcdir) + strlen(fname) + 2); + if (!buf) + { + fprintf (stderr, "%s:%d: could not allocate string: %s\n", + __FILE__, __LINE__, strerror (errno)); + exit (1); + } + strcpy (buf, srcdir); + strcat (buf, "/"); + strcat (buf, fname); + return buf; } + int -main (int argc, char **argv ) +main (int argc, char *argv[]) { - GpgmeCtx ctx; - GpgmeError err; - GpgmeData in, out, pwdata = NULL; - struct passphrase_cb_info_s info; - const char *cipher_1_asc = mk_fname ("cipher-1.asc"); - char *p; - - do { - err = gpgme_new (&ctx); - fail_if_err (err); - - p = getenv("GPG_AGENT_INFO"); - if (!(p && strchr (p, ':'))) - { - memset ( &info, 0, sizeof info ); - info.c = ctx; - gpgme_set_passphrase_cb ( ctx, passphrase_cb, &info ); - } - - 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_data_release (pwdata); - gpgme_release (ctx); - } while ( argc > 1 && !strcmp( argv[1], "--loop" ) ); - - return 0; -} + GpgmeCtx ctx; + GpgmeError err; + GpgmeData in, out; + GpgmeDecryptResult result; + const char *cipher_1_asc = make_filename ("cipher-1.asc"); + char *agent_info; + + err = gpgme_new (&ctx); + fail_if_err (err); + agent_info = getenv("GPG_AGENT_INFO"); + if (!(agent_info && strchr (agent_info, ':'))) + gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); + 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); + 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_release (ctx); + return 0; +} diff --git a/trunk/tests/gpgsm/t-import.c b/trunk/tests/gpgsm/t-import.c index 125e87f..332b040 100644 --- a/trunk/tests/gpgsm/t-import.c +++ b/trunk/tests/gpgsm/t-import.c @@ -39,7 +39,6 @@ while (0) - static char * make_filename (const char *fname) {