doc/
2003-04-28 Marcus Brinkmann <marcus@g10code.de> * gpgme.texi (Decrypt): Descript gpgme_op_decrypt_result and GpgmeDecryptResult. gpgme 2003-04-28 Marcus Brinkmann <marcus@g10code.de> * 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 <stdio.h>, <stdlib.h>, <string.h> and <assert.h>, "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 <string.h>, "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 <marcus@g10code.de> * gpg/t-decrypt.c: Rewritten.
This commit is contained in:
parent
66e29b068e
commit
174e293252
10
NEWS
10
NEWS
@ -86,6 +86,14 @@ Noteworthy changes in version 0.4.1 (unreleased)
|
|||||||
information about the result of an encryption operation in
|
information about the result of an encryption operation in
|
||||||
a GpgmeEncryptResult object.
|
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:
|
* Interface changes relative to the 0.4.0 release:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
GpgmeIOCb CHANGED: Return type from void to GpgmeError.
|
GpgmeIOCb CHANGED: Return type from void to GpgmeError.
|
||||||
@ -126,6 +134,8 @@ gpgme_pubkey_algo_name NEW
|
|||||||
gpgme_hash_algo_name NEW
|
gpgme_hash_algo_name NEW
|
||||||
GpgmeEncryptResult NEW
|
GpgmeEncryptResult NEW
|
||||||
gpgme_op_encrypt_result NEW
|
gpgme_op_encrypt_result NEW
|
||||||
|
GpgmeDecryptResult NEW
|
||||||
|
gpgme_op_decrypt_result NEW
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Noteworthy changes in version 0.4.0 (2002-12-23)
|
Noteworthy changes in version 0.4.0 (2002-12-23)
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2003-04-28 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
* gpgme.texi (Decrypt): Descript gpgme_op_decrypt_result and
|
||||||
|
GpgmeDecryptResult.
|
||||||
|
|
||||||
2003-04-27 Marcus Brinkmann <marcus@g10code.de>
|
2003-04-27 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
* gpgme.texi (Encrypting a Plaintext): Add info about
|
* gpgme.texi (Encrypting a Plaintext): Add info about
|
||||||
|
@ -2774,6 +2774,30 @@ started successfully, and @code{GPGME_Invalid_Value} if @var{cipher}
|
|||||||
or @var{plain} is not a valid pointer.
|
or @var{plain} is not a valid pointer.
|
||||||
@end deftypefun
|
@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
|
@node Verify
|
||||||
@subsection Verify
|
@subsection Verify
|
||||||
|
@ -1,3 +1,34 @@
|
|||||||
|
2003-04-28 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
* 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 <stdio.h>, <stdlib.h>,
|
||||||
|
<string.h> and <assert.h>, "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 <string.h>, "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 <marcus@g10code.de>
|
2003-04-27 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
* encrypt-sign.c: Do not include <stddef.h>, <stdio.h>,
|
* encrypt-sign.c: Do not include <stddef.h>, <stdio.h>,
|
||||||
|
@ -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) 2000 Werner Koch (dd9jn)
|
||||||
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
|
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
|
||||||
|
|
||||||
@ -21,56 +21,69 @@
|
|||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
#include "gpgme.h"
|
||||||
#include "context.h"
|
|
||||||
#include "ops.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
|
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);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
return _gpgme_verify_status_handler (ctx, code, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
|
||||||
gpgme_op_decrypt_verify_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain)
|
|
||||||
{
|
|
||||||
return _gpgme_decrypt_start (ctx, 0, ciph, plain,
|
|
||||||
decrypt_verify_status_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
**/
|
|
||||||
GpgmeError
|
|
||||||
gpgme_op_decrypt_verify (GpgmeCtx ctx, GpgmeData in, GpgmeData out)
|
|
||||||
{
|
{
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
|
|
||||||
gpgme_data_release (ctx->notation);
|
err = _gpgme_op_reset (ctx, synchronous);
|
||||||
ctx->notation = NULL;
|
if (err)
|
||||||
|
return err;
|
||||||
err = _gpgme_decrypt_start (ctx, 1, in, out,
|
|
||||||
decrypt_verify_status_handler);
|
err = _gpgme_op_decrypt_init_result (ctx);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
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 cipher, GpgmeData plain)
|
||||||
|
{
|
||||||
|
return _gpgme_op_decrypt_verify_start (ctx, 0, cipher, plain);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 cipher, GpgmeData plain)
|
||||||
|
{
|
||||||
|
GpgmeError err = _gpgme_op_decrypt_verify_start (ctx, 1, cipher, plain);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = _gpgme_wait_one (ctx);
|
err = _gpgme_wait_one (ctx);
|
||||||
return err;
|
return err;
|
||||||
|
208
gpgme/decrypt.c
208
gpgme/decrypt.c
@ -22,148 +22,133 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "gpgme.h"
|
||||||
|
#include "util.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
|
|
||||||
|
|
||||||
struct decrypt_result
|
typedef struct
|
||||||
{
|
{
|
||||||
|
struct _gpgme_op_decrypt_result result;
|
||||||
|
|
||||||
int okay;
|
int okay;
|
||||||
int failed;
|
int failed;
|
||||||
};
|
} *op_data_t;
|
||||||
typedef struct decrypt_result *DecryptResult;
|
|
||||||
|
|
||||||
|
|
||||||
/* Check whether STRING starts with TOKEN and return true in this
|
static void
|
||||||
case. This is case insensitive. If NEXT is not NULL return the
|
release_op_data (void *hook)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
op_data_t opd = (op_data_t) hook;
|
||||||
|
|
||||||
for (;*string && *token && *string == *token; string++, token++, n++)
|
if (opd->result.unsupported_algorithm)
|
||||||
;
|
free (opd->result.unsupported_algorithm);
|
||||||
if (*token || (*string != ' ' && !*string))
|
|
||||||
return 0;
|
|
||||||
if (next)
|
|
||||||
{
|
|
||||||
for (; *string == ' '; string++, n++)
|
|
||||||
;
|
|
||||||
*next = n;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
GpgmeDecryptResult
|
||||||
skip_token (const char *string, size_t *next)
|
gpgme_op_decrypt_result (GpgmeCtx ctx)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
op_data_t opd;
|
||||||
|
GpgmeError err;
|
||||||
|
|
||||||
for (;*string && *string != ' '; string++, n++)
|
err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &opd, -1, NULL);
|
||||||
;
|
if (err || !opd)
|
||||||
for (;*string == ' '; string++, n++)
|
return NULL;
|
||||||
;
|
|
||||||
if (!*string)
|
return &opd->result;
|
||||||
return 0;
|
|
||||||
if (next)
|
|
||||||
*next = n;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
_gpgme_decrypt_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args)
|
_gpgme_decrypt_status_handler (void *priv, GpgmeStatusCode code, char *args)
|
||||||
{
|
{
|
||||||
DecryptResult result;
|
GpgmeCtx ctx = (GpgmeCtx) priv;
|
||||||
GpgmeError err = 0;
|
GpgmeError err;
|
||||||
size_t n;
|
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)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case GPGME_STATUS_EOF:
|
case GPGME_STATUS_EOF:
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result,
|
if (opd->failed)
|
||||||
-1, NULL);
|
return GPGME_Decryption_Failed;
|
||||||
if (!err)
|
else if (!opd->okay)
|
||||||
{
|
return GPGME_No_Data;
|
||||||
if (result && result->failed)
|
|
||||||
err = GPGME_Decryption_Failed;
|
|
||||||
else if (!result || !result->okay)
|
|
||||||
err = GPGME_No_Data;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GPGME_STATUS_DECRYPTION_OKAY:
|
case GPGME_STATUS_DECRYPTION_OKAY:
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result,
|
opd->okay = 1;
|
||||||
sizeof (*result), NULL);
|
|
||||||
if (!err)
|
|
||||||
result->okay = 1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GPGME_STATUS_DECRYPTION_FAILED:
|
case GPGME_STATUS_DECRYPTION_FAILED:
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, (void **) &result,
|
opd->failed = 1;
|
||||||
sizeof (*result), NULL);
|
|
||||||
if (!err)
|
|
||||||
result->failed = 1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GPGME_STATUS_ERROR:
|
case GPGME_STATUS_ERROR:
|
||||||
if (is_token (args, "decrypt.algorithm", &n) && n)
|
{
|
||||||
{
|
const char d_alg[] = "decrypt.algorithm";
|
||||||
args += n;
|
const char u_alg[] = "Unsupported_Algorithm";
|
||||||
if (is_token (args, "Unsupported_Algorithm", &n))
|
if (!strncmp (args, d_alg, sizeof (d_alg) - 1))
|
||||||
{
|
{
|
||||||
GpgmeData dh;
|
args += sizeof (d_alg);
|
||||||
|
while (*args == ' ')
|
||||||
|
args++;
|
||||||
|
|
||||||
args += n;
|
if (!strncmp (args, u_alg, sizeof (u_alg) - 1))
|
||||||
/* Fixme: This won't work when used with decrypt+verify */
|
{
|
||||||
if (!gpgme_data_new (&dh))
|
char *end;
|
||||||
{
|
|
||||||
_gpgme_data_append_string (dh,
|
args += sizeof (u_alg);
|
||||||
"<GnupgOperationInfo>\n"
|
while (*args == ' ')
|
||||||
" <decryption>\n"
|
args++;
|
||||||
" <error>\n"
|
|
||||||
" <unsupportedAlgorithm>");
|
end = strchr (args, ' ');
|
||||||
if (skip_token (args, &n))
|
if (end)
|
||||||
{
|
*end = '\0';
|
||||||
int c = args[n];
|
|
||||||
args[n] = 0;
|
if (!(*args == '?' && *(args + 1) == '\0'))
|
||||||
_gpgme_data_append_percentstring_for_xml (dh, args);
|
{
|
||||||
args[n] = c;
|
opd->result.unsupported_algorithm = strdup (args);
|
||||||
}
|
if (!opd->result.unsupported_algorithm)
|
||||||
else
|
return GPGME_Out_Of_Core;
|
||||||
_gpgme_data_append_percentstring_for_xml (dh, args);
|
}
|
||||||
|
}
|
||||||
_gpgme_data_append_string (dh,
|
}
|
||||||
"</unsupportedAlgorithm>\n"
|
}
|
||||||
" </error>\n"
|
|
||||||
" </decryption>\n"
|
|
||||||
"</GnupgOperationInfo>\n");
|
|
||||||
_gpgme_set_op_info (ctx, dh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
_gpgme_decrypt_start (GpgmeCtx ctx, int synchronous,
|
_gpgme_op_decrypt_init_result (GpgmeCtx ctx)
|
||||||
GpgmeData cipher, GpgmeData plain, void *status_handler)
|
{
|
||||||
|
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;
|
GpgmeError err;
|
||||||
|
|
||||||
@ -171,6 +156,10 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous,
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
err = _gpgme_op_decrypt_init_result (ctx);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
if (!cipher)
|
if (!cipher)
|
||||||
return GPGME_No_Data;
|
return GPGME_No_Data;
|
||||||
if (!plain)
|
if (!plain)
|
||||||
@ -188,38 +177,27 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous,
|
|||||||
return err;
|
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);
|
return _gpgme_engine_op_decrypt (ctx->engine, cipher, plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
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,
|
return decrypt_start (ctx, 0, cipher, plain);
|
||||||
_gpgme_decrypt_status_handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* Decrypt ciphertext CIPHER within CTX and store the resulting
|
||||||
* gpgme_op_decrypt:
|
plaintext in PLAIN. */
|
||||||
* @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.
|
|
||||||
**/
|
|
||||||
GpgmeError
|
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,
|
GpgmeError err = decrypt_start (ctx, 1, cipher, plain);
|
||||||
_gpgme_decrypt_status_handler);
|
|
||||||
if (!err)
|
if (!err)
|
||||||
err = _gpgme_wait_one (ctx);
|
err = _gpgme_wait_one (ctx);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -798,6 +798,16 @@ GpgmeError gpgme_op_encrypt_sign (GpgmeCtx ctx,
|
|||||||
GpgmeData plain, GpgmeData cipher);
|
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
|
/* Decrypt ciphertext CIPHER within CTX and store the resulting
|
||||||
plaintext in PLAIN. */
|
plaintext in PLAIN. */
|
||||||
GpgmeError gpgme_op_decrypt_start (GpgmeCtx ctx,
|
GpgmeError gpgme_op_decrypt_start (GpgmeCtx ctx,
|
||||||
|
@ -77,12 +77,11 @@ GpgmeError _gpgme_parse_inv_userid (char *args, GpgmeInvalidUserID *userid);
|
|||||||
GpgmeError _gpgme_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code,
|
GpgmeError _gpgme_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code,
|
||||||
char *args);
|
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);
|
char *args);
|
||||||
GpgmeError _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous,
|
|
||||||
GpgmeData ciph, GpgmeData plain,
|
|
||||||
void *status_handler);
|
|
||||||
|
|
||||||
|
|
||||||
/* From sign.c. */
|
/* From sign.c. */
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
2003-04-28 Marcus Brinkmann <marcus@g10code.de>
|
2003-04-28 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
* gpg/t-signers.c (print_data): Rewritten.
|
* gpg/t-decrypt.c: Rewritten.
|
||||||
|
|
||||||
|
* gpg/t-signers.c: Rewritten.
|
||||||
|
|
||||||
2003-04-27 Marcus Brinkmann <marcus@g10code.de>
|
2003-04-27 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
@ -1,56 +1,54 @@
|
|||||||
/* t-decrypt.c - regression test
|
/* t-decrypt.c - regression test
|
||||||
* Copyright (C) 2000 Werner Koch (dd9jn)
|
Copyright (C) 2000 Werner Koch (dd9jn)
|
||||||
* Copyright (C) 2001, 2003 g10 Code GmbH
|
Copyright (C) 2001, 2003 g10 Code GmbH
|
||||||
*
|
|
||||||
* This file is part of GPGME.
|
This file is part of GPGME.
|
||||||
*
|
|
||||||
* GPGME is free software; you can redistribute it and/or modify
|
GPGME is free software; you can redistribute it and/or modify it
|
||||||
* it under the terms of the GNU General Public License as published by
|
under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
(at your option) any later version.
|
||||||
*
|
|
||||||
* GPGME is distributed in the hope that it will be useful,
|
GPGME is distributed in the hope that it will be useful, but
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* GNU General Public License for more details.
|
General Public License for more details.
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
along with GPGME; if not, write to the Free Software Foundation,
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <gpgme.h>
|
#include <gpgme.h>
|
||||||
|
|
||||||
struct passphrase_cb_info_s {
|
#define fail_if_err(err) \
|
||||||
GpgmeCtx c;
|
do \
|
||||||
int did_it;
|
{ \
|
||||||
};
|
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
|
static void
|
||||||
print_data (GpgmeData dh)
|
print_data (GpgmeData dh)
|
||||||
{
|
{
|
||||||
char buf[100];
|
#define BUF_SIZE 512
|
||||||
|
char buf[BUF_SIZE + 1];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = gpgme_data_seek (dh, 0, SEEK_SET);
|
ret = gpgme_data_seek (dh, 0, SEEK_SET);
|
||||||
if (ret)
|
if (ret)
|
||||||
fail_if_err (GPGME_File_Error);
|
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);
|
fwrite (buf, ret, 1, stdout);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
fail_if_err (GPGME_File_Error);
|
fail_if_err (GPGME_File_Error);
|
||||||
@ -58,81 +56,75 @@ print_data (GpgmeData dh)
|
|||||||
|
|
||||||
|
|
||||||
static GpgmeError
|
static GpgmeError
|
||||||
passphrase_cb (void *opaque, const char *desc,
|
passphrase_cb (void *opaque, const char *desc, void **hd, const char **result)
|
||||||
void **r_hd, const char **result)
|
|
||||||
{
|
{
|
||||||
|
/* Cleanup by looking at *hd. */
|
||||||
if (!desc)
|
if (!desc)
|
||||||
/* Cleanup by looking at *r_hd. */
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*result = "abc";
|
*result = "abc";
|
||||||
fprintf (stderr, "%% requesting passphrase for `%s': ", desc);
|
|
||||||
fprintf (stderr, "sending `%s'\n", *result);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
mk_fname ( const char *fname )
|
make_filename (const char *fname)
|
||||||
{
|
{
|
||||||
const char *srcdir = getenv ("srcdir");
|
const char *srcdir = getenv ("srcdir");
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
if (!srcdir)
|
if (!srcdir)
|
||||||
srcdir = ".";
|
srcdir = ".";
|
||||||
buf = malloc (strlen(srcdir) + strlen(fname) + 2 );
|
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
|
||||||
if (!buf )
|
if (!buf)
|
||||||
exit (8);
|
{
|
||||||
strcpy (buf, srcdir);
|
fprintf (stderr, "%s:%d: could not allocate string: %s\n",
|
||||||
strcat (buf, "/");
|
__FILE__, __LINE__, strerror (errno));
|
||||||
strcat (buf, fname );
|
exit (1);
|
||||||
return buf;
|
}
|
||||||
|
strcpy (buf, srcdir);
|
||||||
|
strcat (buf, "/");
|
||||||
|
strcat (buf, fname);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv )
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GpgmeCtx ctx;
|
GpgmeCtx ctx;
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
GpgmeData in, out, pwdata = NULL;
|
GpgmeData in, out;
|
||||||
struct passphrase_cb_info_s info;
|
GpgmeDecryptResult result;
|
||||||
const char *cipher_1_asc = mk_fname ("cipher-1.asc");
|
const char *cipher_1_asc = make_filename ("cipher-1.asc");
|
||||||
char *p;
|
char *agent_info;
|
||||||
|
|
||||||
do {
|
err = gpgme_new (&ctx);
|
||||||
err = gpgme_new (&ctx);
|
fail_if_err (err);
|
||||||
fail_if_err (err);
|
|
||||||
|
|
||||||
p = getenv("GPG_AGENT_INFO");
|
agent_info = getenv("GPG_AGENT_INFO");
|
||||||
if (!(p && strchr (p, ':')))
|
if (!(agent_info && strchr (agent_info, ':')))
|
||||||
{
|
gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
|
||||||
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 );
|
err = gpgme_data_new_from_file (&in, cipher_1_asc, 1);
|
||||||
fail_if_err (err);
|
fail_if_err (err);
|
||||||
|
|
||||||
err = gpgme_data_new ( &out );
|
err = gpgme_data_new (&out);
|
||||||
fail_if_err (err);
|
fail_if_err (err);
|
||||||
|
|
||||||
err = gpgme_op_decrypt (ctx, in, out );
|
err = gpgme_op_decrypt (ctx, in, out);
|
||||||
fail_if_err (err);
|
fail_if_err (err);
|
||||||
|
result = gpgme_op_decrypt_result (ctx);
|
||||||
fflush (NULL);
|
if (result->unsupported_algorithm)
|
||||||
fputs ("Begin Result:\n", stdout );
|
{
|
||||||
print_data (out);
|
fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
|
||||||
fputs ("End Result.\n", stdout );
|
__FILE__, __LINE__, result->unsupported_algorithm);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
print_data (out);
|
||||||
|
|
||||||
gpgme_data_release (in);
|
gpgme_data_release (in);
|
||||||
gpgme_data_release (out);
|
gpgme_data_release (out);
|
||||||
gpgme_data_release (pwdata);
|
gpgme_release (ctx);
|
||||||
gpgme_release (ctx);
|
return 0;
|
||||||
} while ( argc > 1 && !strcmp( argv[1], "--loop" ) );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
while (0)
|
while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
make_filename (const char *fname)
|
make_filename (const char *fname)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user