2001-11-21 Marcus Brinkmann <marcus@g10code.de>
* context.h: Do not include rungpg.h, but engine.h. (struct gpgme_context_s): Replace member gpg with engine. * gpgme.c (gpgme_release): Release engine, not gpg. * recipient.c (_gpgme_append_gpg_args_from_recifgpients): Function moved ... * rungpg.c (_gpgme_append_gpg_args_from_recipients): ... here. Make static, change order of arguments, and return an error value. * ops.h (_gpgme_append_gpg_args_from_recipients): Removed prototype. * rungpg.h (_gpgme_gpg_op_verify): Add prototype. (_gpgme_gpg_op_encrypt): Likewise. (_gpgme_gpg_op_decrypt): Likewise. (_gpgme_gpg_op_delete): Likewise. (_gpgme_gpg_op_export): Likewise. (_gpgme_gpg_op_genkey): Likewise. (_gpgme_gpg_op_import): Likewise. (_gpgme_gpg_op_keylist): Likewise. (_gpgme_gpg_op_sign): Likewise. (_gpgme_gpg_op_trustlist): Likewise. * rungpg.c (_gpgme_gpg_op_verify): New function. (_gpgme_gpg_op_encrypt): Likewise. (_gpgme_gpg_op_decrypt): Likewise. (_gpgme_gpg_op_delete): Likewise. (_gpgme_gpg_op_export): Likewise. (_gpgme_gpg_op_genkey): Likewise. (_gpgme_gpg_op_import): Likewise. (_gpgme_gpg_op_keylist): Likewise. (_gpgme_gpg_op_sign): Likewise. (_gpgme_gpg_op_trustlist): Likewise. * engine.h (_gpgme_engine_set_status_handler): Add prototype. (_gpgme_engine_set_command_handler): Likewise. (_gpgme_engine_set_colon_line_handler): Likewise. (_gpgme_engine_op_decrypt): Likewise. (_gpgme_engine_op_delete): Likewise. (_gpgme_engine_op_encrypt): Likewise. (_gpgme_engine_op_export): Likewise. (_gpgme_engine_op_genkey): Likewise. (_gpgme_engine_op_import): Likewise. (_gpgme_engine_op_keylist): Likewise. (_gpgme_engine_op_sign): Likewise. (_gpgme_engine_op_trustlist): Likewise. (_gpgme_engine_op_verify): Likewise. (_gpgme_engine_start): Likewise. * engine.c (_gpgme_engine_set_status_handler): New function. (_gpgme_engine_set_command_handler): Likewise. (_gpgme_engine_set_colon_line_handler): Likewise. (_gpgme_engine_op_decrypt): Likewise. (_gpgme_engine_op_delete): Likewise. (_gpgme_engine_op_encrypt): Likewise. (_gpgme_engine_op_export): Likewise. (_gpgme_engine_op_genkey): Likewise. (_gpgme_engine_op_import): Likewise. (_gpgme_engine_op_keylist): Likewise. (_gpgme_engine_op_sign): Likewise. (_gpgme_engine_op_trustlist): Likewise. (_gpgme_engine_op_verify): Likewise. (_gpgme_engine_start): Likewise. * verify.c (gpgme_op_verify_start): Reimplement in terms of above functions. * encrypt.c (gpgme_op_encrypt_start): Likewise. * decrypt.c (_gpgme_decrypt_start): Likewise. * passphrase.c (_gpgme_passphrase_start): Likewise. * keylist.c (gpgme_op_keylist_start): Likewise.
This commit is contained in:
parent
38c00b4b32
commit
da95ecfc2c
@ -1,3 +1,72 @@
|
||||
2001-11-21 Marcus Brinkmann <marcus@g10code.de>
|
||||
|
||||
* context.h: Do not include rungpg.h, but engine.h.
|
||||
(struct gpgme_context_s): Replace member gpg with engine.
|
||||
* gpgme.c (gpgme_release): Release engine, not gpg.
|
||||
|
||||
* recipient.c (_gpgme_append_gpg_args_from_recifgpients): Function
|
||||
moved ...
|
||||
* rungpg.c (_gpgme_append_gpg_args_from_recipients): ... here.
|
||||
Make static, change order of arguments, and return an error value.
|
||||
* ops.h (_gpgme_append_gpg_args_from_recipients): Removed prototype.
|
||||
|
||||
* rungpg.h (_gpgme_gpg_op_verify): Add prototype.
|
||||
(_gpgme_gpg_op_encrypt): Likewise.
|
||||
(_gpgme_gpg_op_decrypt): Likewise.
|
||||
(_gpgme_gpg_op_delete): Likewise.
|
||||
(_gpgme_gpg_op_export): Likewise.
|
||||
(_gpgme_gpg_op_genkey): Likewise.
|
||||
(_gpgme_gpg_op_import): Likewise.
|
||||
(_gpgme_gpg_op_keylist): Likewise.
|
||||
(_gpgme_gpg_op_sign): Likewise.
|
||||
(_gpgme_gpg_op_trustlist): Likewise.
|
||||
* rungpg.c (_gpgme_gpg_op_verify): New function.
|
||||
(_gpgme_gpg_op_encrypt): Likewise.
|
||||
(_gpgme_gpg_op_decrypt): Likewise.
|
||||
(_gpgme_gpg_op_delete): Likewise.
|
||||
(_gpgme_gpg_op_export): Likewise.
|
||||
(_gpgme_gpg_op_genkey): Likewise.
|
||||
(_gpgme_gpg_op_import): Likewise.
|
||||
(_gpgme_gpg_op_keylist): Likewise.
|
||||
(_gpgme_gpg_op_sign): Likewise.
|
||||
(_gpgme_gpg_op_trustlist): Likewise.
|
||||
|
||||
* engine.h (_gpgme_engine_set_status_handler): Add prototype.
|
||||
(_gpgme_engine_set_command_handler): Likewise.
|
||||
(_gpgme_engine_set_colon_line_handler): Likewise.
|
||||
(_gpgme_engine_op_decrypt): Likewise.
|
||||
(_gpgme_engine_op_delete): Likewise.
|
||||
(_gpgme_engine_op_encrypt): Likewise.
|
||||
(_gpgme_engine_op_export): Likewise.
|
||||
(_gpgme_engine_op_genkey): Likewise.
|
||||
(_gpgme_engine_op_import): Likewise.
|
||||
(_gpgme_engine_op_keylist): Likewise.
|
||||
(_gpgme_engine_op_sign): Likewise.
|
||||
(_gpgme_engine_op_trustlist): Likewise.
|
||||
(_gpgme_engine_op_verify): Likewise.
|
||||
(_gpgme_engine_start): Likewise.
|
||||
* engine.c (_gpgme_engine_set_status_handler): New function.
|
||||
(_gpgme_engine_set_command_handler): Likewise.
|
||||
(_gpgme_engine_set_colon_line_handler): Likewise.
|
||||
(_gpgme_engine_op_decrypt): Likewise.
|
||||
(_gpgme_engine_op_delete): Likewise.
|
||||
(_gpgme_engine_op_encrypt): Likewise.
|
||||
(_gpgme_engine_op_export): Likewise.
|
||||
(_gpgme_engine_op_genkey): Likewise.
|
||||
(_gpgme_engine_op_import): Likewise.
|
||||
(_gpgme_engine_op_keylist): Likewise.
|
||||
(_gpgme_engine_op_sign): Likewise.
|
||||
(_gpgme_engine_op_trustlist): Likewise.
|
||||
(_gpgme_engine_op_verify): Likewise.
|
||||
(_gpgme_engine_start): Likewise.
|
||||
|
||||
* verify.c (gpgme_op_verify_start): Reimplement in terms of above
|
||||
functions.
|
||||
* encrypt.c (gpgme_op_encrypt_start): Likewise.
|
||||
* decrypt.c (_gpgme_decrypt_start): Likewise.
|
||||
* passphrase.c (_gpgme_passphrase_start): Likewise.
|
||||
* keylist.c (gpgme_op_keylist_start): Likewise.
|
||||
|
||||
2001-11-20 Marcus Brinkmann <marcus@g10code.de>
|
||||
|
||||
* types.h: Add types EngineObject and GpgsmObject.
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include "gpgme.h"
|
||||
#include "types.h"
|
||||
#include "rungpg.h" /* for GpgObject */
|
||||
#include "engine.h"
|
||||
|
||||
struct key_queue_item_s {
|
||||
struct key_queue_item_s *next;
|
||||
@ -51,7 +51,7 @@ struct gpgme_context_s {
|
||||
int cancel; /* cancel operation request */
|
||||
|
||||
|
||||
GpgObject gpg; /* the running gpg process */
|
||||
EngineObject engine; /* The running engine process. */
|
||||
|
||||
int verbosity; /* level of verbosity to use */
|
||||
int use_armor;
|
||||
|
@ -94,7 +94,6 @@ _gpgme_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain,
|
||||
void *status_handler)
|
||||
{
|
||||
GpgmeError err = 0;
|
||||
int i;
|
||||
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
@ -102,25 +101,13 @@ _gpgme_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain,
|
||||
_gpgme_release_result (ctx);
|
||||
ctx->out_of_core = 0;
|
||||
|
||||
/* Do some checks. */
|
||||
|
||||
/* Create a process object. */
|
||||
_gpgme_gpg_release (ctx->gpg);
|
||||
err = _gpgme_gpg_new (&ctx->gpg);
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler (ctx->gpg, status_handler, ctx);
|
||||
|
||||
err = _gpgme_passphrase_start (ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* Build the commandline. */
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--decrypt");
|
||||
for (i = 0; i < ctx->verbosity; i++)
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--verbose");
|
||||
|
||||
/* Check the supplied data. */
|
||||
if (!ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
@ -136,21 +123,24 @@ _gpgme_decrypt_start (GpgmeCtx ctx, GpgmeData ciph, GpgmeData plain,
|
||||
}
|
||||
_gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN);
|
||||
|
||||
/* Tell the gpg object about the data. */
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--output");
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "-");
|
||||
_gpgme_gpg_add_data (ctx->gpg, plain, 1);
|
||||
_gpgme_gpg_add_data (ctx->gpg, ciph, 0);
|
||||
err = _gpgme_passphrase_start (ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* And kick off the process. */
|
||||
err = _gpgme_gpg_spawn (ctx->gpg, ctx);
|
||||
_gpgme_engine_set_status_handler (ctx->engine, status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
err = _gpgme_engine_op_decrypt (ctx->engine, ciph, plain);
|
||||
|
||||
if (!err) /* And kick off the process. */
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_gpg_release (ctx->gpg);
|
||||
ctx->gpg = NULL;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -48,54 +48,45 @@ delete_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_delete_start ( GpgmeCtx c, const GpgmeKey key, int allow_secret )
|
||||
gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key, int allow_secret)
|
||||
{
|
||||
GpgmeError rc = 0;
|
||||
int i;
|
||||
const char *s;
|
||||
GpgmeError err = 0;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
if (!key) {
|
||||
rc = mk_error (Invalid_Value);
|
||||
if (!key)
|
||||
{
|
||||
err = mk_error (Invalid_Value);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if ( c->gpg ) {
|
||||
_gpgme_gpg_release ( c->gpg );
|
||||
c->gpg = NULL;
|
||||
if (ctx->engine)
|
||||
{
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, delete_status_handler, c );
|
||||
_gpgme_engine_set_status_handler (ctx->engine, delete_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
/* build the commandline */
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, allow_secret?
|
||||
"--delete-secret-and-public-key":"--delete-key" );
|
||||
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
s = gpgme_key_get_string_attr ( key, GPGME_ATTR_FPR, NULL, 0 );
|
||||
if (!s) {
|
||||
rc = mk_error (Invalid_Key);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_gpg_add_arg ( c->gpg, s );
|
||||
|
||||
/* do it */
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
err = _gpgme_engine_op_delete (ctx->engine, key, allow_secret);
|
||||
if (!err)
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,73 +138,64 @@ encrypt_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_encrypt_start ( GpgmeCtx c, GpgmeRecipients recp,
|
||||
GpgmeData plain, GpgmeData ciph )
|
||||
gpgme_op_encrypt_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain,
|
||||
GpgmeData ciph)
|
||||
{
|
||||
int rc = 0;
|
||||
int i;
|
||||
int err = 0;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
_gpgme_release_result (c);
|
||||
c->out_of_core = 0;
|
||||
_gpgme_release_result (ctx);
|
||||
ctx->out_of_core = 0;
|
||||
|
||||
/* do some checks */
|
||||
if ( !gpgme_recipients_count ( recp ) ) {
|
||||
/* Fixme: In this case we should do symmentric encryption */
|
||||
rc = mk_error (No_Recipients);
|
||||
/* Do some checks. */
|
||||
if (!gpgme_recipients_count (recp))
|
||||
{
|
||||
/* Fixme: In this case we should do symmentric encryption. */
|
||||
err = mk_error (No_Recipients);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* create a process object */
|
||||
_gpgme_gpg_release (c->gpg); c->gpg = NULL;
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
/* Create an engine object. */
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, encrypt_status_handler, c );
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--encrypt" );
|
||||
if ( c->use_armor )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--armor" );
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
/* If we know that all recipients are valid (full or ultimate trust)
|
||||
* we can suppress further checks */
|
||||
if ( _gpgme_recipients_all_valid (recp) )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--always-trust" );
|
||||
|
||||
_gpgme_append_gpg_args_from_recipients ( recp, c->gpg );
|
||||
_gpgme_engine_set_status_handler (ctx->engine, encrypt_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
/* Check the supplied data */
|
||||
if ( gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (No_Data);
|
||||
if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (No_Data);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT);
|
||||
if ( !ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (Invalid_Value);
|
||||
if (!ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (Invalid_Value);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_data_set_mode (ciph, GPGME_DATA_MODE_IN);
|
||||
/* Tell the gpg object about the data */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--output" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "-" );
|
||||
_gpgme_gpg_add_data ( c->gpg, ciph, 1 );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
_gpgme_gpg_add_data ( c->gpg, plain, 0 );
|
||||
|
||||
/* and kick off the process */
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor);
|
||||
|
||||
|
||||
if (!err) /* And kick off the process. */
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
298
gpgme/engine.c
298
gpgme/engine.c
@ -155,3 +155,301 @@ _gpgme_engine_release (EngineObject engine)
|
||||
}
|
||||
xfree (engine);
|
||||
}
|
||||
|
||||
void
|
||||
_gpgme_engine_set_verbosity (EngineObject engine, int verbosity)
|
||||
{
|
||||
if (!engine)
|
||||
return;
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
while (verbosity-- > 0)
|
||||
_gpgme_gpg_add_arg (engine->engine.gpg, "--verbose");
|
||||
break;
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_gpgme_engine_set_status_handler (EngineObject engine,
|
||||
GpgStatusHandler fnc, void *fnc_value)
|
||||
{
|
||||
if (!engine)
|
||||
return;
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
_gpgme_gpg_set_status_handler (engine->engine.gpg, fnc, fnc_value);
|
||||
break;
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_set_command_handler (EngineObject engine,
|
||||
GpgCommandHandler fnc, void *fnc_value)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_set_command_handler (engine->engine.gpg, fnc, fnc_value);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError _gpgme_engine_set_colon_line_handler (EngineObject engine,
|
||||
GpgColonLineHandler fnc,
|
||||
void *fnc_value)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_set_colon_line_handler (engine->engine.gpg, fnc,
|
||||
fnc_value);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_decrypt (EngineObject engine, GpgmeData ciph, GpgmeData plain)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_decrypt (engine->engine.gpg, ciph, plain);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_delete (EngineObject engine, GpgmeKey key, int allow_secret)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_delete (engine->engine.gpg, key, allow_secret);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp,
|
||||
GpgmeData plain, GpgmeData ciph, int use_armor)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_encrypt (engine->engine.gpg, recp, plain, ciph,
|
||||
use_armor);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp,
|
||||
GpgmeData keydata, int use_armor)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_export (engine->engine.gpg, recp, keydata,
|
||||
use_armor);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, int use_armor)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_genkey (engine->engine.gpg, help_data, use_armor);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_import (EngineObject engine, GpgmeData keydata)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_import (engine->engine.gpg, keydata);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_keylist (EngineObject engine, const char *pattern, int secret_only,
|
||||
int keylist_mode)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_keylist (engine->engine.gpg, pattern, secret_only,
|
||||
keylist_mode);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_sign (EngineObject engine, GpgmeData in, GpgmeData out,
|
||||
GpgmeSigMode mode, int use_armor,
|
||||
int use_textmode, GpgmeCtx ctx /* FIXME */)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_sign (engine->engine.gpg, in, out, mode, use_armor,
|
||||
use_textmode, ctx);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_trustlist (EngineObject engine, const char *pattern)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_trustlist (engine->engine.gpg, pattern);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_op_verify (engine->engine.gpg, sig, text);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque)
|
||||
{
|
||||
if (!engine)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
switch (engine->protocol)
|
||||
{
|
||||
case GPGME_PROTOCOL_OpenPGP:
|
||||
return _gpgme_gpg_spawn (engine->engine.gpg, opaque);
|
||||
case GPGME_PROTOCOL_CMS:
|
||||
/* FIXME */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,10 +23,44 @@
|
||||
#define ENGINE_H
|
||||
|
||||
#include "types.h"
|
||||
#include "rungpg.h"
|
||||
|
||||
const char *_gpgme_engine_get_path (GpgmeProtocol proto);
|
||||
const char *_gpgme_engine_get_version (GpgmeProtocol proto);
|
||||
GpgmeError _gpgme_engine_new (GpgmeProtocol proto, EngineObject *r_engine);
|
||||
void _gpgme_engine_release (EngineObject engine);
|
||||
void _gpgme_engine_set_status_handler (EngineObject engine,
|
||||
GpgStatusHandler fnc, void *fnc_value);
|
||||
GpgmeError _gpgme_engine_set_command_handler (EngineObject engine,
|
||||
GpgCommandHandler fnc,
|
||||
void *fnc_value);
|
||||
GpgmeError _gpgme_engine_set_colon_line_handler (EngineObject gpg,
|
||||
GpgColonLineHandler fnc,
|
||||
void *fnc_value);
|
||||
void _gpgme_engine_set_verbosity (EngineObject engine, int verbosity);
|
||||
GpgmeError _gpgme_engine_op_decrypt (EngineObject engine, GpgmeData ciph,
|
||||
GpgmeData plain);
|
||||
GpgmeError _gpgme_engine_op_delete (EngineObject engine, GpgmeKey key,
|
||||
int allow_secret);
|
||||
GpgmeError _gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp,
|
||||
GpgmeData plain, GpgmeData ciph,
|
||||
int use_armor);
|
||||
GpgmeError _gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp,
|
||||
GpgmeData keydata, int use_armor);
|
||||
GpgmeError _gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data,
|
||||
int use_armor);
|
||||
GpgmeError _gpgme_engine_op_import (EngineObject engine, GpgmeData keydata);
|
||||
GpgmeError _gpgme_engine_op_keylist (EngineObject engine, const char *pattern,
|
||||
int secret_only,
|
||||
int keylist_mode);
|
||||
GpgmeError _gpgme_engine_op_sign (EngineObject engine, GpgmeData in,
|
||||
GpgmeData out, GpgmeSigMode mode,
|
||||
int use_armor, int use_textmode,
|
||||
GpgmeCtx ctx /* FIXME */);
|
||||
GpgmeError _gpgme_engine_op_trustlist (EngineObject engine,
|
||||
const char *pattern);
|
||||
GpgmeError _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig,
|
||||
GpgmeData text);
|
||||
GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque);
|
||||
|
||||
#endif /* ENGINE_H */
|
||||
|
@ -36,66 +36,46 @@ export_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
|
||||
/* FIXME: Need to do more */
|
||||
}
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_export_start ( GpgmeCtx c, GpgmeRecipients recp,
|
||||
GpgmeData keydata )
|
||||
gpgme_op_export_start (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData keydata)
|
||||
{
|
||||
int rc = 0;
|
||||
int i;
|
||||
GpgmeError err = 0;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
/* create a process object */
|
||||
_gpgme_gpg_release (c->gpg); c->gpg = NULL;
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, export_status_handler, c );
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--export" );
|
||||
if ( c->use_armor )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--armor" );
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
|
||||
if ( !keydata || gpgme_data_get_type (keydata) != GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (Invalid_Value);
|
||||
if (!keydata || gpgme_data_get_type (keydata) != GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (Invalid_Value);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_data_set_mode (keydata, GPGME_DATA_MODE_IN);
|
||||
_gpgme_gpg_add_data ( c->gpg, keydata, 1 );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
|
||||
{
|
||||
void *ec;
|
||||
const char *s;
|
||||
_gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
rc = gpgme_recipients_enum_open ( recp, &ec );
|
||||
if ( rc )
|
||||
goto leave;
|
||||
while ( (s = gpgme_recipients_enum_read ( recp, &ec )) )
|
||||
_gpgme_gpg_add_arg (c->gpg, s);
|
||||
rc = gpgme_recipients_enum_close ( recp, &ec );
|
||||
if ( rc )
|
||||
goto leave;
|
||||
}
|
||||
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
err = _gpgme_engine_op_export (ctx->engine, recp, keydata, ctx->use_armor);
|
||||
if (!err)
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* gpgme_op_export:
|
||||
* @c: the context
|
||||
|
@ -104,93 +104,92 @@ genkey_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
|
||||
*
|
||||
* Return value: 0 for success or an error code
|
||||
**/
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_genkey_start ( GpgmeCtx c, const char *parms,
|
||||
gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms,
|
||||
GpgmeData pubkey, GpgmeData seckey)
|
||||
{
|
||||
int rc = 0;
|
||||
int err = 0;
|
||||
int i;
|
||||
const char *s, *s2, *sx;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
gpgme_data_release (c->help_data_1); c->help_data_1 = NULL;
|
||||
gpgme_data_release (ctx->help_data_1);
|
||||
ctx->help_data_1 = NULL;
|
||||
|
||||
/* create a process object */
|
||||
_gpgme_gpg_release (c->gpg); c->gpg = NULL;
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* We need a special mechanism to get the fd of a pipe here, so
|
||||
* that we can use this for the %pubring and %secring parameters.
|
||||
* We don't have this yet, so we implement only the adding to the
|
||||
* standard keyrings */
|
||||
if ( pubkey || seckey ) {
|
||||
rc = mk_error (Not_Implemented);
|
||||
if (pubkey || seckey)
|
||||
{
|
||||
err = mk_error (Not_Implemented);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, genkey_status_handler, c );
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--gen-key" );
|
||||
if ( c->use_armor )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--armor" );
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
|
||||
if (!pubkey && !seckey)
|
||||
; /* okay: Add key to the keyrings */
|
||||
else if ( !pubkey
|
||||
|| gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (Invalid_Value);
|
||||
else if (!pubkey || gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (Invalid_Value);
|
||||
goto leave;
|
||||
}
|
||||
else if ( !seckey
|
||||
|| gpgme_data_get_type (seckey) != GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (Invalid_Value);
|
||||
else if (!seckey || gpgme_data_get_type (seckey) != GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (Invalid_Value);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if ( pubkey ) {
|
||||
if (pubkey)
|
||||
{
|
||||
_gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN);
|
||||
_gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN);
|
||||
/* need some more things here */
|
||||
/* FIXME: Need some more things here. */
|
||||
}
|
||||
|
||||
|
||||
if ((parms = strstr (parms, "<GnupgKeyParms "))
|
||||
&& (s = strchr (parms, '>'))
|
||||
&& (sx = strstr (parms, "format=\"internal\""))
|
||||
&& sx < s
|
||||
&& (s2 = strstr (s+1, "</GnupgKeyParms>")) ) {
|
||||
/* fixme: check that there are no control statements inside */
|
||||
rc = gpgme_data_new_from_mem ( &c->help_data_1, s+1, s2-s-1, 1 );
|
||||
&& (s2 = strstr (s+1, "</GnupgKeyParms>")))
|
||||
{
|
||||
/* FIXME: Check that there are no control statements inside. */
|
||||
err = gpgme_data_new_from_mem (&ctx->help_data_1, s+1, s2-s-1, 1);
|
||||
}
|
||||
else
|
||||
rc = mk_error (Invalid_Value);
|
||||
err = mk_error (Invalid_Value);
|
||||
|
||||
if (rc )
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_data_set_mode (c->help_data_1, GPGME_DATA_MODE_OUT );
|
||||
_gpgme_gpg_add_data (c->gpg, c->help_data_1, 0);
|
||||
_gpgme_data_set_mode (ctx->help_data_1, GPGME_DATA_MODE_OUT);
|
||||
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
_gpgme_engine_set_status_handler (ctx->engine, genkey_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
err = _gpgme_engine_op_genkey (ctx->engine, ctx->help_data_1, ctx->use_armor);
|
||||
|
||||
if (!err)
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* gpgme_op_genkey:
|
||||
* @c: the context
|
||||
|
@ -68,7 +68,7 @@ gpgme_release ( GpgmeCtx c )
|
||||
{
|
||||
if (!c)
|
||||
return;
|
||||
_gpgme_gpg_release ( c->gpg );
|
||||
_gpgme_engine_release (c->engine);
|
||||
_gpgme_release_result (c);
|
||||
gpgme_key_release (c->tmp_key);
|
||||
gpgme_data_release (c->help_data_1);
|
||||
@ -76,11 +76,10 @@ gpgme_release ( GpgmeCtx c )
|
||||
gpgme_signers_clear (c);
|
||||
if (c->signers)
|
||||
xfree (c->signers);
|
||||
/* fixme: release the key_queue */
|
||||
/* FIXME: Release the key_queue. */
|
||||
xfree (c);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_gpgme_release_result (GpgmeCtx c)
|
||||
{
|
||||
|
@ -38,50 +38,47 @@ import_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
|
||||
* a progress callback */
|
||||
}
|
||||
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_import_start ( GpgmeCtx c, GpgmeData keydata )
|
||||
gpgme_op_import_start (GpgmeCtx ctx, GpgmeData keydata)
|
||||
{
|
||||
int rc = 0;
|
||||
int i;
|
||||
int err = 0;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
/* create a process object */
|
||||
_gpgme_gpg_release (c->gpg); c->gpg = NULL;
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, import_status_handler, c );
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--import" );
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
|
||||
/* Check the supplied data */
|
||||
if ( gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (No_Data);
|
||||
if (gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (No_Data);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_data_set_mode (keydata, GPGME_DATA_MODE_OUT);
|
||||
|
||||
_gpgme_gpg_add_data ( c->gpg, keydata, 0 );
|
||||
_gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
_gpgme_engine_op_import (ctx->engine, keydata);
|
||||
|
||||
if (!err)
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gpgme_op_import:
|
||||
* @c: Context
|
||||
|
@ -383,62 +383,51 @@ finish_key ( GpgmeCtx ctx )
|
||||
* Return value: 0 on success or an errorcode.
|
||||
**/
|
||||
GpgmeError
|
||||
gpgme_op_keylist_start ( GpgmeCtx c, const char *pattern, int secret_only )
|
||||
gpgme_op_keylist_start (GpgmeCtx ctx, const char *pattern, int secret_only)
|
||||
{
|
||||
GpgmeError rc = 0;
|
||||
int i;
|
||||
GpgmeError err = 0;
|
||||
|
||||
if ( !c )
|
||||
if (!ctx)
|
||||
return mk_error (Invalid_Value);
|
||||
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 ( c->gpg ) {
|
||||
_gpgme_gpg_release ( c->gpg );
|
||||
c->gpg = NULL;
|
||||
if (ctx->engine)
|
||||
{
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
gpgme_key_release (c->tmp_key);
|
||||
c->tmp_key = NULL;
|
||||
/* Fixme: release key_queue */
|
||||
gpgme_key_release (ctx->tmp_key);
|
||||
ctx->tmp_key = NULL;
|
||||
/* Fixme: Release key_queue. */
|
||||
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, keylist_status_handler, c );
|
||||
|
||||
rc = _gpgme_gpg_set_colon_line_handler ( c->gpg,
|
||||
keylist_colon_handler, c );
|
||||
if (rc)
|
||||
_gpgme_engine_set_status_handler (ctx->engine, keylist_status_handler, ctx);
|
||||
err = _gpgme_engine_set_colon_line_handler (ctx->engine,
|
||||
keylist_colon_handler, ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
/* build the commandline */
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--with-colons" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--fixed-list-mode" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--with-fingerprint" );
|
||||
if (c->keylist_mode == 1)
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--no-expensive-trust-checks" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, secret_only?
|
||||
"--list-secret-keys":"--list-keys" );
|
||||
err = _gpgme_engine_op_keylist (ctx->engine, pattern, secret_only, ctx->keylist_mode);
|
||||
|
||||
/* Tell the gpg object about the data */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
if (pattern && *pattern)
|
||||
_gpgme_gpg_add_arg ( c->gpg, pattern );
|
||||
|
||||
/* and kick off the process */
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
if (!err) /* And kick off the process. */
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,9 +37,6 @@ void _gpgme_thaw_fd ( int fd );
|
||||
|
||||
|
||||
/*-- recipient.c --*/
|
||||
void _gpgme_append_gpg_args_from_recipients (
|
||||
const GpgmeRecipients rset,
|
||||
GpgObject gpg );
|
||||
int _gpgme_recipients_all_valid ( const GpgmeRecipients rset );
|
||||
|
||||
|
||||
|
@ -168,7 +168,7 @@ _gpgme_passphrase_start (GpgmeCtx ctx)
|
||||
GpgmeError err = 0;
|
||||
|
||||
if (ctx->passphrase_cb)
|
||||
err = _gpgme_gpg_set_command_handler (ctx->gpg, command_handler, ctx);
|
||||
err = _gpgme_engine_set_command_handler (ctx->engine, command_handler, ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -222,21 +222,6 @@ gpgme_recipients_enum_close ( const GpgmeRecipients rset, void **ctx )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_gpgme_append_gpg_args_from_recipients (
|
||||
const GpgmeRecipients rset,
|
||||
GpgObject gpg )
|
||||
{
|
||||
struct user_id_s *r;
|
||||
|
||||
assert (rset);
|
||||
for (r=rset->list ; r; r = r->next ) {
|
||||
_gpgme_gpg_add_arg ( gpg, "-r" );
|
||||
_gpgme_gpg_add_arg ( gpg, r->name );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
_gpgme_recipients_all_valid ( const GpgmeRecipients rset )
|
||||
{
|
||||
|
267
gpgme/rungpg.c
267
gpgme/rungpg.c
@ -1434,6 +1434,273 @@ command_cb ( void *opaque, char *buffer, size_t length, size_t *nread )
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph, GpgmeData plain)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--decrypt");
|
||||
|
||||
/* Tell the gpg object about the data. */
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--output");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "-");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, plain, 1);
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, ciph, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_delete (GpgObject gpg, GpgmeKey key, int allow_secret)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, allow_secret
|
||||
? "--delete-secret-and-public-key"
|
||||
: "--delete-key");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err)
|
||||
{
|
||||
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0);
|
||||
if (!s)
|
||||
err = mk_error (Invalid_Key);
|
||||
else
|
||||
err = _gpgme_gpg_add_arg (gpg, s);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static GpgmeError
|
||||
_gpgme_append_gpg_args_from_recipients (GpgObject gpg,
|
||||
const GpgmeRecipients rset)
|
||||
{
|
||||
GpgmeError err = 0;
|
||||
struct user_id_s *r;
|
||||
|
||||
assert (rset);
|
||||
for (r = rset->list; r; r = r->next)
|
||||
{
|
||||
err = _gpgme_gpg_add_arg (gpg, "-r");
|
||||
if (!err)
|
||||
_gpgme_gpg_add_arg (gpg, r->name);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp,
|
||||
GpgmeData plain, GpgmeData ciph, int use_armor)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--encrypt");
|
||||
if (!err && use_armor)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--armor");
|
||||
|
||||
/* If we know that all recipients are valid (full or ultimate trust)
|
||||
* we can suppress further checks */
|
||||
if (!err && _gpgme_recipients_all_valid (recp))
|
||||
err = _gpgme_gpg_add_arg (gpg, "--always-trust");
|
||||
|
||||
if (!err)
|
||||
err = _gpgme_append_gpg_args_from_recipients (gpg, recp);
|
||||
|
||||
/* Tell the gpg object about the data. */
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--output");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "-");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, ciph, 1);
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, plain, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp,
|
||||
GpgmeData keydata, int use_armor)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--export");
|
||||
if (!err && use_armor)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--armor");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, keydata, 1);
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
|
||||
if (!err)
|
||||
{
|
||||
void *ec;
|
||||
const char *s;
|
||||
|
||||
err = gpgme_recipients_enum_open (recp, &ec);
|
||||
while (!err && (s = gpgme_recipients_enum_read (recp, &ec)))
|
||||
err = _gpgme_gpg_add_arg (gpg, s);
|
||||
if (!err)
|
||||
err = gpgme_recipients_enum_close (recp, &ec);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--gen-key");
|
||||
if (!err && use_armor)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--armor");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, help_data, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--import");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, keydata, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_keylist (GpgObject gpg, const char *pattern, int secret_only,
|
||||
int keylist_mode)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--with-colons");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--fixed-list-mode");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--with-fingerprint");
|
||||
if (!err && keylist_mode == 1)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--no-expensive-trust-checks");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, secret_only ? "--list-secret-keys"
|
||||
: "--list-keys");
|
||||
|
||||
/* Tell the gpg object about the data */
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err && pattern && *pattern)
|
||||
err = _gpgme_gpg_add_arg (gpg, pattern);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out,
|
||||
GpgmeSigMode mode, int use_armor,
|
||||
int use_textmode, GpgmeCtx ctx /* FIXME */)
|
||||
{
|
||||
GpgmeError err;
|
||||
GpgmeKey key;
|
||||
int i;
|
||||
|
||||
if (mode == GPGME_SIG_MODE_CLEAR)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--clearsign");
|
||||
else
|
||||
{
|
||||
err = _gpgme_gpg_add_arg (gpg, "--sign");
|
||||
if (!err && mode == GPGME_SIG_MODE_DETACH)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--detach");
|
||||
if (!err && use_armor)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--armor");
|
||||
if (!err && use_textmode)
|
||||
_gpgme_gpg_add_arg (gpg, "--textmode");
|
||||
}
|
||||
for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++)
|
||||
{
|
||||
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID,
|
||||
NULL, 0);
|
||||
if (s)
|
||||
{
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "-u");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, s);
|
||||
}
|
||||
gpgme_key_unref (key);
|
||||
if (err) break;
|
||||
}
|
||||
|
||||
/* Tell the gpg object about the data. */
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, in, 0);
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, out, 1);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern)
|
||||
{
|
||||
GpgmeError err;
|
||||
|
||||
err = _gpgme_gpg_add_arg (gpg, "--with-colons");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--list-trust-path");
|
||||
|
||||
/* Tell the gpg object about the data */
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, pattern);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
GpgmeError
|
||||
_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text)
|
||||
{
|
||||
GpgmeError err = 0;
|
||||
|
||||
if (gpg->pm.used)
|
||||
{
|
||||
err = _gpgme_gpg_add_arg (gpg, gpg->pm.used ? "--pipemode" : "--verify");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_pm_data (gpg, sig, 0);
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_pm_data (gpg, text, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = _gpgme_gpg_add_arg (gpg, "--verify");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "--");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, sig, -1);
|
||||
if (text)
|
||||
{
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_arg (gpg, "-");
|
||||
if (!err)
|
||||
err = _gpgme_gpg_add_data (gpg, text, 0);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -119,14 +119,24 @@ GpgmeError _gpgme_gpg_set_command_handler ( GpgObject gpg,
|
||||
GpgCommandHandler fnc,
|
||||
void *fnc_value );
|
||||
|
||||
GpgmeError _gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph,
|
||||
GpgmeData plain);
|
||||
GpgmeError _gpgme_gpg_op_delete (GpgObject gpg, GpgmeKey key, int allow_secret);
|
||||
GpgmeError _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp,
|
||||
GpgmeData plain, GpgmeData ciph,
|
||||
int use_armor);
|
||||
GpgmeError _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp,
|
||||
GpgmeData keydata, int use_armor);
|
||||
GpgmeError _gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data,
|
||||
int use_armor);
|
||||
GpgmeError _gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata);
|
||||
GpgmeError _gpgme_gpg_op_keylist (GpgObject gpg, const char *pattern,
|
||||
int secret_only, int keylist_mode);
|
||||
GpgmeError _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out,
|
||||
GpgmeSigMode mode, int use_armor,
|
||||
int use_textmode, GpgmeCtx ctx /* FIXME */);
|
||||
GpgmeError _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern);
|
||||
GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text);
|
||||
GpgmeError _gpgme_gpg_spawn (GpgObject gpg, void *opaque);
|
||||
|
||||
|
||||
|
||||
#endif /* RUNGPG_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
60
gpgme/sign.c
60
gpgme/sign.c
@ -177,8 +177,6 @@ gpgme_op_sign_start (GpgmeCtx ctx, GpgmeData in, GpgmeData out,
|
||||
GpgmeSigMode mode)
|
||||
{
|
||||
GpgmeError err = 0;
|
||||
int i;
|
||||
GpgmeKey key;
|
||||
|
||||
fail_on_pending_request (ctx);
|
||||
ctx->pending = 1;
|
||||
@ -192,45 +190,13 @@ gpgme_op_sign_start (GpgmeCtx ctx, GpgmeData in, GpgmeData out,
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
/* Create a process object. */
|
||||
_gpgme_gpg_release (ctx->gpg);
|
||||
ctx->gpg = NULL;
|
||||
err = _gpgme_gpg_new (&ctx->gpg);
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler (ctx->gpg, sign_status_handler, ctx);
|
||||
|
||||
err = _gpgme_passphrase_start (ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* Build the commandline. */
|
||||
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)
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--detach");
|
||||
if (ctx->use_armor)
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--armor");
|
||||
if (ctx->use_textmode)
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--textmode");
|
||||
}
|
||||
for (i = 0; i < ctx->verbosity; i++)
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "--verbose");
|
||||
for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++)
|
||||
{
|
||||
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID,
|
||||
NULL, 0);
|
||||
if (s)
|
||||
{
|
||||
_gpgme_gpg_add_arg (ctx->gpg, "-u");
|
||||
_gpgme_gpg_add_arg (ctx->gpg, s);
|
||||
}
|
||||
gpgme_key_unref (key);
|
||||
}
|
||||
|
||||
/* Check the supplied data. */
|
||||
if (gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
@ -245,19 +211,25 @@ gpgme_op_sign_start (GpgmeCtx ctx, GpgmeData in, GpgmeData out,
|
||||
}
|
||||
_gpgme_data_set_mode (out, GPGME_DATA_MODE_IN);
|
||||
|
||||
/* Tell the gpg object about the data. */
|
||||
_gpgme_gpg_add_data (ctx->gpg, in, 0);
|
||||
_gpgme_gpg_add_data (ctx->gpg, out, 1);
|
||||
err = _gpgme_passphrase_start (ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_engine_set_status_handler (ctx->engine, sign_status_handler, ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
_gpgme_engine_op_sign (ctx->engine, in, out, mode, ctx->use_armor,
|
||||
ctx->use_textmode, ctx /* FIXME */);
|
||||
|
||||
/* And kick off the process. */
|
||||
err = _gpgme_gpg_spawn (ctx->gpg, ctx);
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_gpg_release (ctx->gpg);
|
||||
ctx->gpg = NULL;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -154,55 +154,49 @@ trustlist_colon_handler ( GpgmeCtx ctx, char *line )
|
||||
ctx->key_cond = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_trustlist_start ( GpgmeCtx c, const char *pattern, int max_level )
|
||||
gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
|
||||
{
|
||||
GpgmeError rc = 0;
|
||||
GpgmeError err = 0;
|
||||
|
||||
fail_on_pending_request( c );
|
||||
if ( !pattern || !*pattern ) {
|
||||
fail_on_pending_request (ctx);
|
||||
if (!pattern || !*pattern)
|
||||
return mk_error (Invalid_Value);
|
||||
|
||||
ctx->pending = 1;
|
||||
|
||||
_gpgme_release_result (ctx);
|
||||
ctx->out_of_core = 0;
|
||||
|
||||
if (ctx->engine)
|
||||
{
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
|
||||
c->pending = 1;
|
||||
|
||||
_gpgme_release_result (c);
|
||||
c->out_of_core = 0;
|
||||
|
||||
if ( c->gpg ) {
|
||||
_gpgme_gpg_release ( c->gpg );
|
||||
c->gpg = NULL;
|
||||
}
|
||||
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
_gpgme_gpg_set_status_handler ( c->gpg, trustlist_status_handler, c );
|
||||
rc = _gpgme_gpg_set_colon_line_handler ( c->gpg,
|
||||
trustlist_colon_handler, c );
|
||||
if (rc)
|
||||
_gpgme_engine_set_status_handler (ctx->engine, trustlist_status_handler, ctx);
|
||||
err = _gpgme_engine_set_colon_line_handler (ctx->engine,
|
||||
trustlist_colon_handler, ctx);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--with-colons" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--list-trust-path" );
|
||||
err =_gpgme_engine_op_trustlist (ctx->engine, pattern);
|
||||
|
||||
/* Tell the gpg object about the data */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
_gpgme_gpg_add_arg ( c->gpg, pattern );
|
||||
|
||||
/* and kick off the process */
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
if (!err) /* And kick off the process. */
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err) {
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,78 +218,68 @@ _gpgme_verify_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GpgmeError
|
||||
gpgme_op_verify_start ( GpgmeCtx c, GpgmeData sig, GpgmeData text )
|
||||
gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData text)
|
||||
{
|
||||
int rc = 0;
|
||||
int i;
|
||||
int pipemode = 0; /*!!text; use pipemode for detached sigs */
|
||||
int err = 0;
|
||||
int pipemode = 0; /* !!text; use pipemode for detached sigs. */
|
||||
|
||||
fail_on_pending_request( c );
|
||||
c->pending = 1;
|
||||
fail_on_pending_request(ctx);
|
||||
ctx->pending = 1;
|
||||
|
||||
_gpgme_release_result (c);
|
||||
c->out_of_core = 0;
|
||||
_gpgme_release_result (ctx);
|
||||
ctx->out_of_core = 0;
|
||||
|
||||
if ( !pipemode ) {
|
||||
_gpgme_gpg_release ( c->gpg );
|
||||
c->gpg = NULL;
|
||||
if (!pipemode)
|
||||
{
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
|
||||
if ( !c->gpg )
|
||||
rc = _gpgme_gpg_new ( &c->gpg );
|
||||
if (rc)
|
||||
if (!ctx->engine)
|
||||
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
|
||||
: GPGME_PROTOCOL_OpenPGP, &ctx->engine);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
#if 0 /* FIXME */
|
||||
if (pipemode)
|
||||
_gpgme_gpg_enable_pipemode ( c->gpg );
|
||||
_gpgme_gpg_set_status_handler (c->gpg, _gpgme_verify_status_handler, c);
|
||||
_gpgme_gpg_enable_pipemode (c->engine->engine.gpg);
|
||||
#endif
|
||||
|
||||
/* build the commandline */
|
||||
_gpgme_gpg_add_arg ( c->gpg, pipemode?"--pipemode" : "--verify" );
|
||||
for ( i=0; i < c->verbosity; i++ )
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--verbose" );
|
||||
_gpgme_engine_set_status_handler (ctx->engine, _gpgme_verify_status_handler,
|
||||
ctx);
|
||||
_gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity);
|
||||
|
||||
/* Check the supplied data */
|
||||
if ( gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (No_Data);
|
||||
/* Check the supplied data. */
|
||||
if (gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (No_Data);
|
||||
goto leave;
|
||||
}
|
||||
if ( text && gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE ) {
|
||||
rc = mk_error (No_Data);
|
||||
if (text && gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE)
|
||||
{
|
||||
err = mk_error (No_Data);
|
||||
goto leave;
|
||||
}
|
||||
_gpgme_data_set_mode (sig, GPGME_DATA_MODE_OUT);
|
||||
if (text) /* detached signature */
|
||||
if (text) /* Detached signature. */
|
||||
_gpgme_data_set_mode (text, GPGME_DATA_MODE_OUT);
|
||||
/* Tell the gpg object about the data */
|
||||
_gpgme_gpg_add_arg ( c->gpg, "--" );
|
||||
if (pipemode) {
|
||||
_gpgme_gpg_add_pm_data ( c->gpg, sig, 0 );
|
||||
_gpgme_gpg_add_pm_data ( c->gpg, text, 1 );
|
||||
}
|
||||
else {
|
||||
_gpgme_gpg_add_data ( c->gpg, sig, -1 );
|
||||
if (text) {
|
||||
_gpgme_gpg_add_arg ( c->gpg, "-" );
|
||||
_gpgme_gpg_add_data ( c->gpg, text, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/* and kick off the process */
|
||||
rc = _gpgme_gpg_spawn ( c->gpg, c );
|
||||
err = _gpgme_engine_op_verify (ctx->engine, sig, text);
|
||||
if (!err) /* And kick off the process. */
|
||||
err = _gpgme_engine_start (ctx->engine, ctx);
|
||||
|
||||
leave:
|
||||
if (rc) {
|
||||
c->pending = 0;
|
||||
_gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
|
||||
if (err)
|
||||
{
|
||||
ctx->pending = 0;
|
||||
_gpgme_engine_release (ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Figure out a common status value for all signatures
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user