Copyright (C) 2001, 2002, 2003, 2004 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 Lesser General Public License as
published by the Free Software Foundation; either version 2.1 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
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include <string.h>
#include <errno.h>
+#include "debug.h"
#include "gpgme.h"
#include "util.h"
#include "context.h"
#include "ops.h"
+
\f
typedef struct
{
int okay;
int failed;
-
+
/* A pointer to the next pointer of the last recipient in the list.
This makes appending new invalid signers painless while
preserving the order. */
op_data_t opd;
gpgme_error_t err;
+ TRACE_BEG (DEBUG_CTX, "gpgme_op_decrypt_result", ctx);
+
err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, &hook, -1, NULL);
opd = hook;
if (err || !opd)
- return NULL;
+ {
+ TRACE_SUC0 ("result=(null)");
+ return NULL;
+ }
+
+ if (_gpgme_debug_trace ())
+ {
+ gpgme_recipient_t rcp;
+
+ if (opd->result.unsupported_algorithm)
+ {
+ TRACE_LOG1 ("result: unsupported_algorithm: %s",
+ opd->result.unsupported_algorithm);
+ }
+ if (opd->result.wrong_key_usage)
+ {
+ TRACE_LOG ("result: wrong key usage");
+ }
+ rcp = opd->result.recipients;
+ while (rcp)
+ {
+ TRACE_LOG3 ("result: recipient: keyid=%s, pubkey_algo=%i, "
+ "status=%s", rcp->keyid, rcp->pubkey_algo,
+ gpg_strerror (rcp->status));
+ rcp = rcp->next;
+ }
+ if (opd->result.file_name)
+ {
+ TRACE_LOG1 ("result: original file name: %s", opd->result.file_name);
+ }
+ }
+ TRACE_SUC1 ("result=%p", &opd->result);
return &opd->result;
}
rec = malloc (sizeof (*rec));
if (!rec)
- return gpg_error_from_errno (errno);
+ return gpg_error_from_syserror ();
rec->next = NULL;
rec->keyid = rec->_keyid;
if (*args)
{
- errno = 0;
+ gpg_err_set_errno (0);
rec->pubkey_algo = strtol (args, &tail, 0);
if (errno || args == tail || *tail != ' ')
{
return gpg_error (GPG_ERR_NO_DATA);
break;
+ case GPGME_STATUS_DECRYPTION_INFO:
+ /* Fixme: Provide a way to return the used symmetric algorithm. */
+ break;
+
case GPGME_STATUS_DECRYPTION_OKAY:
opd->okay = 1;
break;
related to the backend. */
{
const char d_alg[] = "decrypt.algorithm";
- const char u_alg[] = "Unsupported_Algorithm";
const char k_alg[] = "decrypt.keyusage";
if (!strncmp (args, d_alg, sizeof (d_alg) - 1))
while (*args == ' ')
args++;
- if (!strncmp (args, u_alg, sizeof (u_alg) - 1))
+ if (gpg_err_code (atoi (args)) == GPG_ERR_UNSUPPORTED_ALGORITHM)
{
char *end;
- args += sizeof (u_alg) - 1;
+ while (*args && *args != ' ')
+ args++;
while (*args == ' ')
args++;
{
opd->result.unsupported_algorithm = strdup (args);
if (!opd->result.unsupported_algorithm)
- return gpg_error_from_errno (errno);
+ return gpg_error_from_syserror ();
}
}
}
while (*args == ' ')
args++;
- err = _gpgme_map_gnupg_error (args);
- if (gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE)
+ if (gpg_err_code (atoi (args)) == GPG_ERR_WRONG_KEY_USAGE)
opd->result.wrong_key_usage = 1;
}
}
err = _gpgme_parse_plaintext (args, &opd->result.file_name);
if (err)
return err;
-
+
default:
break;
}
gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher,
gpgme_data_t plain)
{
- return decrypt_start (ctx, 0, cipher, plain);
+ gpgme_error_t err;
+
+ TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_start", ctx,
+ "cipher=%p, plain=%p", cipher, plain);
+
+ if (!ctx)
+ return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+ err = decrypt_start (ctx, 0, cipher, plain);
+ return TRACE_ERR (err);
}
gpgme_error_t
gpgme_op_decrypt (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain)
{
- gpgme_error_t err = decrypt_start (ctx, 1, cipher, plain);
+ gpgme_error_t err;
+
+ TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt", ctx,
+ "cipher=%p, plain=%p", cipher, plain);
+
+ if (!ctx)
+ return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+ err = decrypt_start (ctx, 1, cipher, plain);
if (!err)
err = _gpgme_wait_one (ctx);
- return err;
+ return TRACE_ERR (err);
}