2001-11-16 Marcus Brinkmann <marcus@g10code.de>
* passphrase.c: New file. * Makefile.am (libgpgme_la_SOURCES): Add passphrase.c. * ops.h (_gpgme_passphrase_result): Add prototypes from passphrase.c. * types.h: Likewise. * context.h: Add member passphrase to result. * gpgme.c (_gpgme_release_result): Release passphrase member. * decrypt.c: Some formatting and variable name changes (like CTX instead C). (struct decrypt_result_s): Remove members now found in passphrase result. (_gpgme_release_decrypt_result): Don't release removed members. (decrypt_status_handler): Call _gpgme_passphrase_status_handler, and don't handle the cases catched there. (command_handler): Removed. (gpgme_op_decrypt_start): Don't set command handler, but invoke _gpgme_passphrase_start which does it. (gpgme_op_decrypt): Invoke _gpgme_passphrase_result and drop the cases covered by it. * sign.c Some formatting and variable name changes (like CTX instead C). (struct sign_result_s): Remove members now found in passphrase result. (_gpgme_release_sign_result): Don't release removed members. (sign_status_handler): Call _gpgme_passphrase_status_handler, and don't handle the cases catched there. (command_handler): Removed. (gpgme_op_sign_start): Don't set command handler, but invoke _gpgme_passphrase_start which does it. (gpgme_op_sign): Invoke _gpgme_passphrase_result and drop the cases covered by it.
This commit is contained in:
parent
4374f7c57f
commit
550bc31b44
@ -1,3 +1,39 @@
|
|||||||
|
2001-11-16 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
* passphrase.c: New file.
|
||||||
|
* Makefile.am (libgpgme_la_SOURCES): Add passphrase.c.
|
||||||
|
* ops.h (_gpgme_passphrase_result): Add prototypes from
|
||||||
|
passphrase.c.
|
||||||
|
* types.h: Likewise.
|
||||||
|
* context.h: Add member passphrase to result.
|
||||||
|
* gpgme.c (_gpgme_release_result): Release passphrase member.
|
||||||
|
|
||||||
|
* decrypt.c: Some formatting and variable name changes (like
|
||||||
|
CTX instead C).
|
||||||
|
(struct decrypt_result_s): Remove members now found in
|
||||||
|
passphrase result.
|
||||||
|
(_gpgme_release_decrypt_result): Don't release removed members.
|
||||||
|
(decrypt_status_handler): Call _gpgme_passphrase_status_handler,
|
||||||
|
and don't handle the cases catched there.
|
||||||
|
(command_handler): Removed.
|
||||||
|
(gpgme_op_decrypt_start): Don't set command handler, but invoke
|
||||||
|
_gpgme_passphrase_start which does it.
|
||||||
|
(gpgme_op_decrypt): Invoke _gpgme_passphrase_result and drop the
|
||||||
|
cases covered by it.
|
||||||
|
|
||||||
|
* sign.c Some formatting and variable name changes (like
|
||||||
|
CTX instead C).
|
||||||
|
(struct sign_result_s): Remove members now found in
|
||||||
|
passphrase result.
|
||||||
|
(_gpgme_release_sign_result): Don't release removed members.
|
||||||
|
(sign_status_handler): Call _gpgme_passphrase_status_handler,
|
||||||
|
and don't handle the cases catched there.
|
||||||
|
(command_handler): Removed.
|
||||||
|
(gpgme_op_sign_start): Don't set command handler, but invoke
|
||||||
|
_gpgme_passphrase_start which does it.
|
||||||
|
(gpgme_op_sign): Invoke _gpgme_passphrase_result and drop the
|
||||||
|
cases covered by it.
|
||||||
|
|
||||||
2001-11-15 Marcus Brinkmann <marcus@g10code.de>
|
2001-11-15 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
* decrypt.c (command_handler): Fix last change.
|
* decrypt.c (command_handler): Fix last change.
|
||||||
|
@ -41,6 +41,7 @@ libgpgme_la_SOURCES = \
|
|||||||
decrypt.c \
|
decrypt.c \
|
||||||
verify.c \
|
verify.c \
|
||||||
sign.c \
|
sign.c \
|
||||||
|
passphrase.c \
|
||||||
key.c key.h \
|
key.c key.h \
|
||||||
keylist.c \
|
keylist.c \
|
||||||
trustlist.c \
|
trustlist.c \
|
||||||
|
@ -67,6 +67,7 @@ struct gpgme_context_s {
|
|||||||
DecryptResult decrypt;
|
DecryptResult decrypt;
|
||||||
SignResult sign;
|
SignResult sign;
|
||||||
EncryptResult encrypt;
|
EncryptResult encrypt;
|
||||||
|
PassphraseResult passphrase;
|
||||||
} result;
|
} result;
|
||||||
|
|
||||||
GpgmeData notation; /* last signature notation */
|
GpgmeData notation; /* last signature notation */
|
||||||
|
206
gpgme/decrypt.c
206
gpgme/decrypt.c
@ -31,13 +31,8 @@
|
|||||||
|
|
||||||
struct decrypt_result_s
|
struct decrypt_result_s
|
||||||
{
|
{
|
||||||
int no_passphrase;
|
|
||||||
int okay;
|
int okay;
|
||||||
int failed;
|
int failed;
|
||||||
void *last_pw_handle;
|
|
||||||
char *userid_hint;
|
|
||||||
char *passphrase_info;
|
|
||||||
int bad_passphrase;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -45,8 +40,6 @@ _gpgme_release_decrypt_result (DecryptResult result)
|
|||||||
{
|
{
|
||||||
if (!result)
|
if (!result)
|
||||||
return;
|
return;
|
||||||
xfree (result->passphrase_info);
|
|
||||||
xfree (result->userid_hint);
|
|
||||||
xfree (result);
|
xfree (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +56,11 @@ create_result_struct (GpgmeCtx ctx)
|
|||||||
static void
|
static void
|
||||||
decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
||||||
{
|
{
|
||||||
|
_gpgme_passphrase_status_handler (ctx, code, args);
|
||||||
|
|
||||||
if (ctx->out_of_core)
|
if (ctx->out_of_core)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (! ctx->result.decrypt)
|
if (! ctx->result.decrypt)
|
||||||
{
|
{
|
||||||
if (create_result_struct (ctx))
|
if (create_result_struct (ctx))
|
||||||
@ -74,36 +70,11 @@ decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (code) {
|
switch (code)
|
||||||
|
{
|
||||||
case STATUS_EOF:
|
case STATUS_EOF:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS_USERID_HINT:
|
|
||||||
xfree (ctx->result.decrypt->userid_hint);
|
|
||||||
if (!(ctx->result.decrypt->userid_hint = xtrystrdup (args)) )
|
|
||||||
ctx->out_of_core = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_BAD_PASSPHRASE:
|
|
||||||
ctx->result.decrypt->bad_passphrase++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_GOOD_PASSPHRASE:
|
|
||||||
ctx->result.decrypt->bad_passphrase = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_NEED_PASSPHRASE:
|
|
||||||
case STATUS_NEED_PASSPHRASE_SYM:
|
|
||||||
xfree (ctx->result.decrypt->passphrase_info);
|
|
||||||
if (!(ctx->result.decrypt->passphrase_info = xtrystrdup (args)) )
|
|
||||||
ctx->out_of_core = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_MISSING_PASSPHRASE:
|
|
||||||
DEBUG0 ("missing passphrase - stop\n");;
|
|
||||||
ctx->result.decrypt->no_passphrase = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_DECRYPTION_OKAY:
|
case STATUS_DECRYPTION_OKAY:
|
||||||
ctx->result.decrypt->okay = 1;
|
ctx->result.decrypt->okay = 1;
|
||||||
break;
|
break;
|
||||||
@ -112,171 +83,112 @@ decrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
|||||||
ctx->result.decrypt->failed = 1;
|
ctx->result.decrypt->failed = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* ignore all other codes */
|
/* Ignore all other codes. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
command_handler (void *opaque, GpgStatusCode code, const char *key)
|
|
||||||
{
|
|
||||||
GpgmeCtx c = opaque;
|
|
||||||
|
|
||||||
if (! c->result.decrypt)
|
|
||||||
{
|
|
||||||
if (create_result_struct (c))
|
|
||||||
{
|
|
||||||
c->out_of_core = 1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !code ) {
|
|
||||||
/* We have been called for cleanup */
|
|
||||||
if ( c->passphrase_cb ) {
|
|
||||||
/* Fixme: take the key in account */
|
|
||||||
c->passphrase_cb (c->passphrase_cb_value, NULL,
|
|
||||||
&c->result.decrypt->last_pw_handle );
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !key || !c->passphrase_cb )
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if ( code == STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter") ) {
|
|
||||||
const char *userid_hint = c->result.decrypt->userid_hint;
|
|
||||||
const char *passphrase_info = c->result.decrypt->passphrase_info;
|
|
||||||
int bad_passphrase = c->result.decrypt->bad_passphrase;
|
|
||||||
char *buf;
|
|
||||||
const char *s;
|
|
||||||
|
|
||||||
c->result.decrypt->bad_passphrase = 0;
|
|
||||||
if (!userid_hint)
|
|
||||||
userid_hint = "[User ID hint missing]";
|
|
||||||
if (!passphrase_info)
|
|
||||||
passphrase_info = "[passphrase info missing]";
|
|
||||||
buf = xtrymalloc ( 20 + strlen (userid_hint)
|
|
||||||
+ strlen (passphrase_info) + 3);
|
|
||||||
if (!buf) {
|
|
||||||
c->out_of_core = 1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
sprintf (buf, "%s\n%s\n%s",
|
|
||||||
bad_passphrase? "TRY_AGAIN":"ENTER",
|
|
||||||
userid_hint, passphrase_info );
|
|
||||||
|
|
||||||
s = c->passphrase_cb (c->passphrase_cb_value,
|
|
||||||
buf, &c->result.decrypt->last_pw_handle );
|
|
||||||
xfree (buf);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_decrypt_start ( GpgmeCtx c,
|
gpgme_op_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain)
|
||||||
GpgmeData ciph, GpgmeData plain )
|
|
||||||
{
|
{
|
||||||
int rc = 0;
|
GpgmeError err = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fail_on_pending_request( c );
|
fail_on_pending_request (ctx);
|
||||||
c->pending = 1;
|
ctx->pending = 1;
|
||||||
|
|
||||||
_gpgme_release_result (c);
|
_gpgme_release_result (ctx);
|
||||||
c->out_of_core = 0;
|
ctx->out_of_core = 0;
|
||||||
|
|
||||||
/* do some checks */
|
/* Do some checks. */
|
||||||
|
|
||||||
/* create a process object */
|
/* Create a process object. */
|
||||||
_gpgme_gpg_release ( c->gpg );
|
_gpgme_gpg_release (ctx->gpg);
|
||||||
rc = _gpgme_gpg_new ( &c->gpg );
|
err = _gpgme_gpg_new (&ctx->gpg);
|
||||||
if (rc)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
_gpgme_gpg_set_status_handler ( c->gpg, decrypt_status_handler, c );
|
_gpgme_gpg_set_status_handler (ctx->gpg, decrypt_status_handler, ctx);
|
||||||
if (c->passphrase_cb) {
|
|
||||||
rc = _gpgme_gpg_set_command_handler ( c->gpg, command_handler, c );
|
err = _gpgme_passphrase_start (ctx);
|
||||||
if (rc)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
|
||||||
|
|
||||||
/* build the commandline */
|
/* Build the commandline. */
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--decrypt" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--decrypt");
|
||||||
for ( i=0; i < c->verbosity; i++ )
|
for (i = 0; i < ctx->verbosity; i++)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--verbose");
|
||||||
|
|
||||||
/* Check the supplied data */
|
/* Check the supplied data. */
|
||||||
if ( !ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE ) {
|
if (!ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE)
|
||||||
rc = mk_error (No_Data);
|
{
|
||||||
|
err = mk_error (No_Data);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
_gpgme_data_set_mode (ciph, GPGME_DATA_MODE_OUT);
|
_gpgme_data_set_mode (ciph, GPGME_DATA_MODE_OUT);
|
||||||
|
|
||||||
if ( gpgme_data_get_type (plain) != GPGME_DATA_TYPE_NONE ) {
|
if (gpgme_data_get_type (plain) != GPGME_DATA_TYPE_NONE)
|
||||||
rc = mk_error (Invalid_Value);
|
{
|
||||||
|
err = mk_error (Invalid_Value);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
_gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN);
|
_gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN);
|
||||||
|
|
||||||
/* Tell the gpg object about the data */
|
/* Tell the gpg object about the data. */
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--output" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--output");
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "-" );
|
_gpgme_gpg_add_arg (ctx->gpg, "-");
|
||||||
_gpgme_gpg_add_data ( c->gpg, plain, 1 );
|
_gpgme_gpg_add_data (ctx->gpg, plain, 1);
|
||||||
_gpgme_gpg_add_data ( c->gpg, ciph, 0 );
|
_gpgme_gpg_add_data (ctx->gpg, ciph, 0);
|
||||||
|
|
||||||
/* and kick off the process */
|
/* And kick off the process. */
|
||||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
err = _gpgme_gpg_spawn (ctx->gpg, ctx);
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
if (rc) {
|
if (err)
|
||||||
c->pending = 0;
|
{
|
||||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
ctx->pending = 0;
|
||||||
|
_gpgme_gpg_release (ctx->gpg);
|
||||||
|
ctx->gpg = NULL;
|
||||||
}
|
}
|
||||||
return rc;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gpgme_op_decrypt:
|
* gpgme_op_decrypt:
|
||||||
* @c: The context
|
* @ctx: The context
|
||||||
* @in: ciphertext input
|
* @in: ciphertext input
|
||||||
* @out: plaintext output
|
* @out: plaintext output
|
||||||
*
|
*
|
||||||
* This function decrypts @in to @out.
|
* This function decrypts @in to @out.
|
||||||
* Other parameters are take from the context @c.
|
* Other parameters are take from the context @ctx.
|
||||||
* The function does wait for the result.
|
* The function does wait for the result.
|
||||||
*
|
*
|
||||||
* Return value: 0 on success or an errorcode.
|
* Return value: 0 on success or an errorcode.
|
||||||
**/
|
**/
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_decrypt (GpgmeCtx c, GpgmeData in, GpgmeData out)
|
gpgme_op_decrypt (GpgmeCtx ctx, GpgmeData in, GpgmeData out)
|
||||||
{
|
{
|
||||||
GpgmeError err = gpgme_op_decrypt_start (c, in, out);
|
GpgmeError err = gpgme_op_decrypt_start (ctx, in, out);
|
||||||
if (!err)
|
if (!err)
|
||||||
{
|
{
|
||||||
gpgme_wait (c, 1);
|
gpgme_wait (ctx, 1);
|
||||||
if (!c->result.decrypt)
|
if (!ctx->result.decrypt)
|
||||||
err = mk_error (General_Error);
|
err = mk_error (General_Error);
|
||||||
else if (c->out_of_core)
|
else if (ctx->out_of_core)
|
||||||
err = mk_error (Out_Of_Core);
|
err = mk_error (Out_Of_Core);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (c->result.decrypt->no_passphrase)
|
err = _gpgme_passphrase_result (ctx);
|
||||||
err = mk_error (No_Passphrase);
|
if (! err)
|
||||||
else if (c->result.decrypt->failed)
|
{
|
||||||
|
if (ctx->result.decrypt->failed)
|
||||||
err = mk_error (Decryption_Failed);
|
err = mk_error (Decryption_Failed);
|
||||||
else if (!c->result.decrypt->okay)
|
else if (!ctx->result.decrypt->okay)
|
||||||
err = mk_error (No_Data);
|
err = mk_error (No_Data);
|
||||||
}
|
}
|
||||||
c->pending = 0;
|
}
|
||||||
|
ctx->pending = 0;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ _gpgme_release_result (GpgmeCtx c)
|
|||||||
_gpgme_release_decrypt_result (c->result.decrypt);
|
_gpgme_release_decrypt_result (c->result.decrypt);
|
||||||
_gpgme_release_sign_result (c->result.sign);
|
_gpgme_release_sign_result (c->result.sign);
|
||||||
_gpgme_release_encrypt_result (c->result.encrypt);
|
_gpgme_release_encrypt_result (c->result.encrypt);
|
||||||
|
_gpgme_release_passphrase_result (c->result.passphrase);
|
||||||
memset (&c->result, 0, sizeof (c->result));
|
memset (&c->result, 0, sizeof (c->result));
|
||||||
_gpgme_set_op_info (c, NULL);
|
_gpgme_set_op_info (c, NULL);
|
||||||
}
|
}
|
||||||
|
12
gpgme/ops.h
12
gpgme/ops.h
@ -23,6 +23,7 @@
|
|||||||
#define OPS_H
|
#define OPS_H
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "rungpg.h"
|
||||||
|
|
||||||
/*-- gpgme.c --*/
|
/*-- gpgme.c --*/
|
||||||
void _gpgme_release_result ( GpgmeCtx c );
|
void _gpgme_release_result ( GpgmeCtx c );
|
||||||
@ -79,10 +80,11 @@ void _gpgme_release_sign_result ( SignResult res );
|
|||||||
/*-- encrypt.c --*/
|
/*-- encrypt.c --*/
|
||||||
void _gpgme_release_encrypt_result ( EncryptResult res );
|
void _gpgme_release_encrypt_result ( EncryptResult res );
|
||||||
|
|
||||||
|
/*-- passphrase.c --*/
|
||||||
|
void _gpgme_release_passphrase_result (PassphraseResult result);
|
||||||
|
void _gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code,
|
||||||
|
char *args);
|
||||||
|
GpgmeError _gpgme_passphrase_start (GpgmeCtx ctx);
|
||||||
|
GpgmeError _gpgme_passphrase_result (GpgmeCtx ctx);
|
||||||
|
|
||||||
#endif /* OPS_H */
|
#endif /* OPS_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
187
gpgme/passphrase.c
Normal file
187
gpgme/passphrase.c
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
/* passphrase.c - passphrase functions
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "context.h"
|
||||||
|
#include "ops.h"
|
||||||
|
|
||||||
|
struct passphrase_result_s
|
||||||
|
{
|
||||||
|
int no_passphrase;
|
||||||
|
void *last_pw_handle;
|
||||||
|
char *userid_hint;
|
||||||
|
char *passphrase_info;
|
||||||
|
int bad_passphrase;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
_gpgme_release_passphrase_result (PassphraseResult result)
|
||||||
|
{
|
||||||
|
if (!result)
|
||||||
|
return;
|
||||||
|
xfree (result->passphrase_info);
|
||||||
|
xfree (result->userid_hint);
|
||||||
|
xfree (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_gpgme_passphrase_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
||||||
|
{
|
||||||
|
if (ctx->out_of_core)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ctx->result.passphrase)
|
||||||
|
{
|
||||||
|
ctx->result.passphrase = xtrycalloc (1, sizeof *ctx->result.passphrase);
|
||||||
|
if (!ctx->result.passphrase)
|
||||||
|
{
|
||||||
|
ctx->out_of_core = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (code)
|
||||||
|
{
|
||||||
|
case STATUS_USERID_HINT:
|
||||||
|
xfree (ctx->result.passphrase->userid_hint);
|
||||||
|
if (!(ctx->result.passphrase->userid_hint = xtrystrdup (args)) )
|
||||||
|
ctx->out_of_core = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_BAD_PASSPHRASE:
|
||||||
|
ctx->result.passphrase->bad_passphrase++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_GOOD_PASSPHRASE:
|
||||||
|
ctx->result.passphrase->bad_passphrase = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_NEED_PASSPHRASE:
|
||||||
|
case STATUS_NEED_PASSPHRASE_SYM:
|
||||||
|
xfree (ctx->result.passphrase->passphrase_info);
|
||||||
|
ctx->result.passphrase->passphrase_info = xtrystrdup (args);
|
||||||
|
if (!ctx->result.passphrase->passphrase_info)
|
||||||
|
ctx->out_of_core = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_MISSING_PASSPHRASE:
|
||||||
|
DEBUG0 ("missing passphrase - stop\n");;
|
||||||
|
ctx->result.passphrase->no_passphrase = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Ignore all other codes. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
command_handler (void *opaque, GpgStatusCode code, const char *key)
|
||||||
|
{
|
||||||
|
GpgmeCtx ctx = opaque;
|
||||||
|
|
||||||
|
if (!ctx->result.passphrase)
|
||||||
|
{
|
||||||
|
ctx->result.passphrase = xtrycalloc (1, sizeof *ctx->result.passphrase);
|
||||||
|
if (!ctx->result.passphrase)
|
||||||
|
{
|
||||||
|
ctx->out_of_core = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!code)
|
||||||
|
{
|
||||||
|
/* We have been called for cleanup. */
|
||||||
|
if (ctx->passphrase_cb)
|
||||||
|
{
|
||||||
|
/* Fixme: Take the key in account. */
|
||||||
|
ctx->passphrase_cb (ctx->passphrase_cb_value, NULL,
|
||||||
|
&ctx->result.passphrase->last_pw_handle);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key || !ctx->passphrase_cb)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (code == STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter"))
|
||||||
|
{
|
||||||
|
const char *userid_hint = ctx->result.passphrase->userid_hint;
|
||||||
|
const char *passphrase_info = ctx->result.passphrase->passphrase_info;
|
||||||
|
int bad_passphrase = ctx->result.passphrase->bad_passphrase;
|
||||||
|
char *buf;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
ctx->result.passphrase->bad_passphrase = 0;
|
||||||
|
if (!userid_hint)
|
||||||
|
userid_hint = "[User ID hint missing]";
|
||||||
|
if (!passphrase_info)
|
||||||
|
passphrase_info = "[passphrase info missing]";
|
||||||
|
buf = xtrymalloc (20 + strlen (userid_hint)
|
||||||
|
+ strlen (passphrase_info) + 3);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
ctx->out_of_core = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
sprintf (buf, "%s\n%s\n%s",
|
||||||
|
bad_passphrase ? "TRY_AGAIN":"ENTER",
|
||||||
|
userid_hint, passphrase_info);
|
||||||
|
|
||||||
|
s = ctx->passphrase_cb (ctx->passphrase_cb_value,
|
||||||
|
buf, &ctx->result.passphrase->last_pw_handle);
|
||||||
|
xfree (buf);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GpgmeError
|
||||||
|
_gpgme_passphrase_start (GpgmeCtx ctx)
|
||||||
|
{
|
||||||
|
GpgmeError err = 0;
|
||||||
|
|
||||||
|
if (ctx->passphrase_cb)
|
||||||
|
err = _gpgme_gpg_set_command_handler (ctx->gpg, command_handler, ctx);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
GpgmeError
|
||||||
|
_gpgme_passphrase_result (GpgmeCtx ctx)
|
||||||
|
{
|
||||||
|
GpgmeError err = 0;
|
||||||
|
|
||||||
|
if (!ctx->result.passphrase)
|
||||||
|
err = mk_error (General_Error);
|
||||||
|
else if (ctx->out_of_core)
|
||||||
|
err = mk_error (Out_Of_Core);
|
||||||
|
else if (ctx->result.passphrase->no_passphrase)
|
||||||
|
err = mk_error (No_Passphrase);
|
||||||
|
return err;
|
||||||
|
}
|
267
gpgme/sign.c
267
gpgme/sign.c
@ -38,12 +38,7 @@
|
|||||||
|
|
||||||
struct sign_result_s
|
struct sign_result_s
|
||||||
{
|
{
|
||||||
int no_passphrase;
|
|
||||||
int okay;
|
int okay;
|
||||||
void *last_pw_handle;
|
|
||||||
char *userid_hint;
|
|
||||||
char *passphrase_info;
|
|
||||||
int bad_passphrase;
|
|
||||||
GpgmeData xmlinfo;
|
GpgmeData xmlinfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -53,12 +48,10 @@ _gpgme_release_sign_result (SignResult result)
|
|||||||
if (!result)
|
if (!result)
|
||||||
return;
|
return;
|
||||||
gpgme_data_release (result->xmlinfo);
|
gpgme_data_release (result->xmlinfo);
|
||||||
xfree (result->userid_hint);
|
|
||||||
xfree (result->passphrase_info);
|
|
||||||
xfree (result);
|
xfree (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse the args and save the information
|
/* Parse the args and save the information
|
||||||
* <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
|
* <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
|
||||||
* in an XML structure. With args of NULL the xml structure is closed.
|
* in an XML structure. With args of NULL the xml structure is closed.
|
||||||
*/
|
*/
|
||||||
@ -71,19 +64,24 @@ append_xml_siginfo (GpgmeData *rdh, char *args)
|
|||||||
char *s;
|
char *s;
|
||||||
unsigned long ul;
|
unsigned long ul;
|
||||||
|
|
||||||
if ( !*rdh ) {
|
if (!*rdh)
|
||||||
if (gpgme_data_new (rdh)) {
|
{
|
||||||
|
if (gpgme_data_new (rdh))
|
||||||
|
{
|
||||||
return; /* fixme: We are ignoring out-of-core */
|
return; /* fixme: We are ignoring out-of-core */
|
||||||
}
|
}
|
||||||
dh = *rdh;
|
dh = *rdh;
|
||||||
_gpgme_data_append_string (dh, "<GnupgOperationInfo>\n");
|
_gpgme_data_append_string (dh, "<GnupgOperationInfo>\n");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
dh = *rdh;
|
dh = *rdh;
|
||||||
_gpgme_data_append_string (dh, " </signature>\n");
|
_gpgme_data_append_string (dh, " </signature>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args) { /* just close the XML containter */
|
if (!args)
|
||||||
|
{
|
||||||
|
/* Just close the XML containter. */
|
||||||
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n");
|
_gpgme_data_append_string (dh, "</GnupgOperationInfo>\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -103,7 +101,8 @@ append_xml_siginfo (GpgmeData *rdh, char *args)
|
|||||||
i = atoi (args);
|
i = atoi (args);
|
||||||
sprintf (helpbuf, " <hashalgo>%d</hashalgo>\n", atoi (args));
|
sprintf (helpbuf, " <hashalgo>%d</hashalgo>\n", atoi (args));
|
||||||
_gpgme_data_append_string (dh, helpbuf);
|
_gpgme_data_append_string (dh, helpbuf);
|
||||||
switch (i) {
|
switch (i)
|
||||||
|
{
|
||||||
case 1: s = "pgp-md5"; break;
|
case 1: s = "pgp-md5"; break;
|
||||||
case 2: s = "pgp-sha1"; break;
|
case 2: s = "pgp-sha1"; break;
|
||||||
case 3: s = "pgp-ripemd160"; break;
|
case 3: s = "pgp-ripemd160"; break;
|
||||||
@ -128,7 +127,7 @@ append_xml_siginfo (GpgmeData *rdh, char *args)
|
|||||||
_gpgme_data_append_string (dh, helpbuf);
|
_gpgme_data_append_string (dh, helpbuf);
|
||||||
SKIP_TOKEN_OR_RETURN (args);
|
SKIP_TOKEN_OR_RETURN (args);
|
||||||
|
|
||||||
/* count the length of the finperprint */
|
/* Count the length of the finperprint. */
|
||||||
for (i = 0; args[i] && args[i] != ' '; i++)
|
for (i = 0; args[i] && args[i] != ' '; i++)
|
||||||
;
|
;
|
||||||
_gpgme_data_append_string (dh, " <fpr>");
|
_gpgme_data_append_string (dh, " <fpr>");
|
||||||
@ -136,8 +135,6 @@ append_xml_siginfo (GpgmeData *rdh, char *args)
|
|||||||
_gpgme_data_append_string (dh, "</fpr>\n");
|
_gpgme_data_append_string (dh, "</fpr>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
||||||
{
|
{
|
||||||
@ -153,43 +150,19 @@ sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (code) {
|
switch (code)
|
||||||
|
{
|
||||||
case STATUS_EOF:
|
case STATUS_EOF:
|
||||||
if (ctx->result.sign->okay) {
|
if (ctx->result.sign->okay)
|
||||||
|
{
|
||||||
append_xml_siginfo (&ctx->result.sign->xmlinfo, NULL);
|
append_xml_siginfo (&ctx->result.sign->xmlinfo, NULL);
|
||||||
_gpgme_set_op_info (ctx, ctx->result.sign->xmlinfo);
|
_gpgme_set_op_info (ctx, ctx->result.sign->xmlinfo);
|
||||||
ctx->result.sign->xmlinfo = NULL;
|
ctx->result.sign->xmlinfo = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS_USERID_HINT:
|
|
||||||
xfree (ctx->result.sign->userid_hint);
|
|
||||||
if (!(ctx->result.sign->userid_hint = xtrystrdup (args)) )
|
|
||||||
ctx->out_of_core = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_BAD_PASSPHRASE:
|
|
||||||
ctx->result.sign->bad_passphrase++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_GOOD_PASSPHRASE:
|
|
||||||
ctx->result.sign->bad_passphrase = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_NEED_PASSPHRASE:
|
|
||||||
case STATUS_NEED_PASSPHRASE_SYM:
|
|
||||||
xfree (ctx->result.sign->passphrase_info);
|
|
||||||
if (!(ctx->result.sign->passphrase_info = xtrystrdup (args)) )
|
|
||||||
ctx->out_of_core = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_MISSING_PASSPHRASE:
|
|
||||||
DEBUG0 ("missing passphrase - stop\n");
|
|
||||||
ctx->result.sign->no_passphrase = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATUS_SIG_CREATED:
|
case STATUS_SIG_CREATED:
|
||||||
/* fixme: we have no error return for multiple signatures */
|
/* FIXME: We have no error return for multiple signatures. */
|
||||||
append_xml_siginfo (&ctx->result.sign->xmlinfo, args);
|
append_xml_siginfo (&ctx->result.sign->xmlinfo, args);
|
||||||
ctx->result.sign->okay =1;
|
ctx->result.sign->okay =1;
|
||||||
break;
|
break;
|
||||||
@ -199,165 +172,106 @@ sign_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
|
||||||
command_handler ( void *opaque, GpgStatusCode code, const char *key )
|
|
||||||
{
|
|
||||||
GpgmeCtx c = opaque;
|
|
||||||
|
|
||||||
if (!c->result.sign)
|
|
||||||
{
|
|
||||||
c->result.sign = xtrycalloc (1, sizeof *c->result.sign);
|
|
||||||
if (!c->result.sign)
|
|
||||||
{
|
|
||||||
c->out_of_core = 1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !code ) {
|
|
||||||
/* We have been called for cleanup */
|
|
||||||
if ( c->passphrase_cb ) {
|
|
||||||
/* Fixme: take the key in account */
|
|
||||||
c->passphrase_cb (c->passphrase_cb_value, 0,
|
|
||||||
&c->result.sign->last_pw_handle );
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !key || !c->passphrase_cb )
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if ( code == STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter") ) {
|
|
||||||
const char *userid_hint = c->result.sign->userid_hint;
|
|
||||||
const char *passphrase_info = c->result.sign->passphrase_info;
|
|
||||||
int bad_passphrase = c->result.sign->bad_passphrase;
|
|
||||||
char *buf;
|
|
||||||
const char *s;
|
|
||||||
|
|
||||||
c->result.sign->bad_passphrase = 0;
|
|
||||||
if (!userid_hint)
|
|
||||||
userid_hint = "[User ID hint missing]";
|
|
||||||
if (!passphrase_info)
|
|
||||||
passphrase_info = "[passphrase info missing]";
|
|
||||||
buf = xtrymalloc ( 20 + strlen (userid_hint)
|
|
||||||
+ strlen (passphrase_info) + 3);
|
|
||||||
if (!buf) {
|
|
||||||
c->out_of_core = 1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
sprintf (buf, "%s\n%s\n%s",
|
|
||||||
bad_passphrase? "TRY_AGAIN":"ENTER",
|
|
||||||
userid_hint, passphrase_info );
|
|
||||||
|
|
||||||
s = c->passphrase_cb (c->passphrase_cb_value,
|
|
||||||
buf, &c->result.sign->last_pw_handle );
|
|
||||||
xfree (buf);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_sign_start ( GpgmeCtx c, GpgmeData in, GpgmeData out,
|
gpgme_op_sign_start (GpgmeCtx ctx, GpgmeData in, GpgmeData out,
|
||||||
GpgmeSigMode mode)
|
GpgmeSigMode mode)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
GpgmeError err = 0;
|
||||||
int i;
|
int i;
|
||||||
GpgmeKey key;
|
GpgmeKey key;
|
||||||
|
|
||||||
fail_on_pending_request( c );
|
fail_on_pending_request (ctx);
|
||||||
c->pending = 1;
|
ctx->pending = 1;
|
||||||
|
|
||||||
_gpgme_release_result (c);
|
|
||||||
c->out_of_core = 0;
|
|
||||||
|
|
||||||
|
_gpgme_release_result (ctx);
|
||||||
|
ctx->out_of_core = 0;
|
||||||
|
|
||||||
if (mode != GPGME_SIG_MODE_NORMAL
|
if (mode != GPGME_SIG_MODE_NORMAL
|
||||||
&& mode != GPGME_SIG_MODE_DETACH
|
&& mode != GPGME_SIG_MODE_DETACH
|
||||||
&& mode != GPGME_SIG_MODE_CLEAR)
|
&& mode != GPGME_SIG_MODE_CLEAR)
|
||||||
return mk_error (Invalid_Value);
|
return mk_error (Invalid_Value);
|
||||||
|
|
||||||
/* create a process object */
|
/* Create a process object. */
|
||||||
_gpgme_gpg_release (c->gpg);
|
_gpgme_gpg_release (ctx->gpg);
|
||||||
c->gpg = NULL;
|
ctx->gpg = NULL;
|
||||||
rc = _gpgme_gpg_new ( &c->gpg );
|
err = _gpgme_gpg_new (&ctx->gpg);
|
||||||
if (rc)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
_gpgme_gpg_set_status_handler ( c->gpg, sign_status_handler, c );
|
_gpgme_gpg_set_status_handler (ctx->gpg, sign_status_handler, ctx);
|
||||||
if (c->passphrase_cb) {
|
|
||||||
rc = _gpgme_gpg_set_command_handler ( c->gpg, command_handler, c );
|
|
||||||
if (rc)
|
|
||||||
goto leave;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* build the commandline */
|
err = _gpgme_passphrase_start (ctx);
|
||||||
if ( mode == GPGME_SIG_MODE_CLEAR ) {
|
if (err)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--clearsign" );
|
goto leave;
|
||||||
}
|
|
||||||
else {
|
/* Build the commandline. */
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--sign" );
|
if (mode == GPGME_SIG_MODE_CLEAR)
|
||||||
|
_gpgme_gpg_add_arg (ctx->gpg, "--clearsign");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gpgme_gpg_add_arg (ctx->gpg, "--sign");
|
||||||
if (mode == GPGME_SIG_MODE_DETACH)
|
if (mode == GPGME_SIG_MODE_DETACH)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--detach" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--detach");
|
||||||
if ( c->use_armor )
|
if (ctx->use_armor)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--armor" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--armor");
|
||||||
if ( c->use_textmode )
|
if (ctx->use_textmode)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--textmode" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--textmode");
|
||||||
}
|
}
|
||||||
for (i=0; i < c->verbosity; i++)
|
for (i = 0; i < ctx->verbosity; i++)
|
||||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
_gpgme_gpg_add_arg (ctx->gpg, "--verbose");
|
||||||
for (i=0; (key = gpgme_signers_enum (c, i)); i++ ) {
|
for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++)
|
||||||
|
{
|
||||||
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID,
|
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID,
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (s) {
|
if (s)
|
||||||
_gpgme_gpg_add_arg (c->gpg, "-u");
|
{
|
||||||
_gpgme_gpg_add_arg (c->gpg, s);
|
_gpgme_gpg_add_arg (ctx->gpg, "-u");
|
||||||
|
_gpgme_gpg_add_arg (ctx->gpg, s);
|
||||||
}
|
}
|
||||||
gpgme_key_unref (key);
|
gpgme_key_unref (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check the supplied data. */
|
||||||
/* Check the supplied data */
|
if (gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE)
|
||||||
if ( gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE ) {
|
{
|
||||||
rc = mk_error (No_Data);
|
err = mk_error (No_Data);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
_gpgme_data_set_mode (in, GPGME_DATA_MODE_OUT);
|
_gpgme_data_set_mode (in, GPGME_DATA_MODE_OUT);
|
||||||
if ( !out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE ) {
|
if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE)
|
||||||
rc = mk_error (Invalid_Value);
|
{
|
||||||
|
err = mk_error (Invalid_Value);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
_gpgme_data_set_mode (out, GPGME_DATA_MODE_IN);
|
_gpgme_data_set_mode (out, GPGME_DATA_MODE_IN);
|
||||||
|
|
||||||
/* tell the gpg object about the data */
|
/* Tell the gpg object about the data. */
|
||||||
_gpgme_gpg_add_data ( c->gpg, in, 0 );
|
_gpgme_gpg_add_data (ctx->gpg, in, 0);
|
||||||
_gpgme_gpg_add_data ( c->gpg, out, 1 );
|
_gpgme_gpg_add_data (ctx->gpg, out, 1);
|
||||||
|
|
||||||
/* and kick off the process */
|
/* And kick off the process. */
|
||||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
err = _gpgme_gpg_spawn (ctx->gpg, ctx);
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
if (rc) {
|
if (err)
|
||||||
c->pending = 0;
|
{
|
||||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
ctx->pending = 0;
|
||||||
|
_gpgme_gpg_release (ctx->gpg);
|
||||||
|
ctx->gpg = NULL;
|
||||||
}
|
}
|
||||||
return rc;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gpgme_op_sign:
|
* gpgme_op_sign:
|
||||||
* @c: The context
|
* @ctx: The context
|
||||||
* @in: Data to be signed
|
* @in: Data to be signed
|
||||||
* @out: Detached signature
|
* @out: Detached signature
|
||||||
* @mode: Signature creation mode
|
* @mode: Signature creation mode
|
||||||
*
|
*
|
||||||
* Create a detached signature for @in and write it to @out.
|
* Create a detached signature for @in and write it to @out.
|
||||||
* The data will be signed using either the default key or the ones
|
* The data will be signed using either the default key or the ones
|
||||||
* defined through @c.
|
* defined through @ctx.
|
||||||
* The defined modes for signature create are:
|
* The defined modes for signature create are:
|
||||||
* <literal>
|
* <literal>
|
||||||
* GPGME_SIG_MODE_NORMAL (or 0)
|
* GPGME_SIG_MODE_NORMAL (or 0)
|
||||||
@ -370,31 +284,26 @@ gpgme_op_sign_start ( GpgmeCtx c, GpgmeData in, GpgmeData out,
|
|||||||
* Return value: 0 on success or an error code.
|
* Return value: 0 on success or an error code.
|
||||||
**/
|
**/
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_sign (GpgmeCtx c, GpgmeData in, GpgmeData out, GpgmeSigMode mode)
|
gpgme_op_sign (GpgmeCtx ctx, GpgmeData in, GpgmeData out, GpgmeSigMode mode)
|
||||||
{
|
{
|
||||||
GpgmeError err = gpgme_op_sign_start ( c, in, out, mode );
|
GpgmeError err = gpgme_op_sign_start (ctx, in, out, mode);
|
||||||
if ( !err ) {
|
if (!err)
|
||||||
gpgme_wait (c, 1);
|
{
|
||||||
if (!c->result.sign)
|
gpgme_wait (ctx, 1);
|
||||||
|
if (!ctx->result.sign)
|
||||||
err = mk_error (General_Error);
|
err = mk_error (General_Error);
|
||||||
else if (c->out_of_core)
|
else if (ctx->out_of_core)
|
||||||
err = mk_error (Out_Of_Core);
|
err = mk_error (Out_Of_Core);
|
||||||
else {
|
else
|
||||||
if (c->result.sign->no_passphrase)
|
{
|
||||||
err = mk_error (No_Passphrase);
|
err = _gpgme_passphrase_result (ctx);
|
||||||
else if (!c->result.sign->okay)
|
if (! err)
|
||||||
|
{
|
||||||
|
if (!ctx->result.sign->okay)
|
||||||
err = mk_error (No_Data); /* Hmmm: choose a better error? */
|
err = mk_error (No_Data); /* Hmmm: choose a better error? */
|
||||||
}
|
}
|
||||||
c->pending = 0;
|
}
|
||||||
|
ctx->pending = 0;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +65,10 @@ typedef struct sign_result_s *SignResult;
|
|||||||
struct encrypt_result_s;
|
struct encrypt_result_s;
|
||||||
typedef struct encrypt_result_s *EncryptResult;
|
typedef struct encrypt_result_s *EncryptResult;
|
||||||
|
|
||||||
|
/*-- passphrase.c --*/
|
||||||
|
struct passphrase_result_s;
|
||||||
|
typedef struct passphrase_result_s *PassphraseResult;
|
||||||
|
|
||||||
/*-- key.c --*/
|
/*-- key.c --*/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user