From f0a45d0c20abe8bda33e275277da6d3cea434f49 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 8 Feb 2002 22:43:44 +0000 Subject: [PATCH] 2002-02-08 Marcus Brinkmann * genkey.c (gpgme_op_genkey_start): Allow PUBKEY and SECKEY to be set, and pass them down to the crypto engine. * engine-gpgsm.h (_gpgme_gpgsm_start): New arguments PUBKEY and SECKEY. * engine.h: Likewise. * rungpg.h (_gpgme_gpg_spawn): Likewise. * engine.c (_gpgme_engine_op_genkey): Likewise. Use those arguments. * rungpg.c (_gpgme_gpg_op_genkey): Likewise. Complain if those arguments are set. * engine-gpgsm.c (_gpgme_gpgsm_op_genkey): Likewise. Implement function. * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Beautify comment. --- gpgme/ChangeLog | 16 ++++++++++++++++ gpgme/engine-gpgsm.c | 32 +++++++++++++++++++++++++++----- gpgme/engine-gpgsm.h | 5 +++-- gpgme/engine.c | 9 ++++++--- gpgme/engine.h | 5 +++-- gpgme/genkey.c | 24 ++++++++---------------- gpgme/rungpg.c | 13 ++++++++++++- gpgme/rungpg.h | 3 ++- 8 files changed, 77 insertions(+), 30 deletions(-) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index df4f8403..9912cb41 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,19 @@ +2002-02-08 Marcus Brinkmann + + * genkey.c (gpgme_op_genkey_start): Allow PUBKEY and SECKEY to be + set, and pass them down to the crypto engine. + * engine-gpgsm.h (_gpgme_gpgsm_start): New arguments PUBKEY and SECKEY. + * engine.h: Likewise. + * rungpg.h (_gpgme_gpg_spawn): Likewise. + * engine.c (_gpgme_engine_op_genkey): Likewise. Use those + arguments. + * rungpg.c (_gpgme_gpg_op_genkey): Likewise. Complain if those + arguments are set. + * engine-gpgsm.c (_gpgme_gpgsm_op_genkey): Likewise. Implement + function. + + * engine-gpgsm.c (_gpgme_gpgsm_op_keylist): Beautify comment. + 2002-02-06 Marcus Brinkmann * rungpg.c (_gpgme_gpg_op_keylist): Remove handling of keylist diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index 44816d04..0be5215c 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -504,10 +504,30 @@ _gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, GpgmeError -_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor) +_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) { - /* FIXME */ - return mk_error (Not_Implemented); + GpgmeError err; + + if (!gpgsm || !pubkey || seckey) + return mk_error (Invalid_Value); + + gpgsm->command = xtrystrdup ("GENKEY"); + if (!gpgsm->command) + return mk_error (Out_Of_Core); + + gpgsm->input_data = help_data; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, 0); + if (err) + return err; + gpgsm->output_data = pubkey; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_fd); + + return 0; } @@ -543,7 +563,8 @@ _gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, if (!pattern) pattern = ""; - line = xtrymalloc (15 + strlen (pattern) + 1); /* "LISTSECRETKEYS "+p+'\0'.*/ + /* Length is "LISTSECRETKEYS " + p + '\0'. */ + line = xtrymalloc (15 + strlen (pattern) + 1); if (!line) return mk_error (Out_Of_Core); if (secret_only) @@ -932,7 +953,8 @@ _gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, GpgmeError -_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor) +_gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) { return mk_error (Invalid_Engine); } diff --git a/gpgme/engine-gpgsm.h b/gpgme/engine-gpgsm.h index 995be66e..c302625e 100644 --- a/gpgme/engine-gpgsm.h +++ b/gpgme/engine-gpgsm.h @@ -1,6 +1,6 @@ /* engine-gpgsm.h - GPGME GpgSM engine calling functions * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001 g10 Code GmbH + * Copyright (C) 2001, 2002 g10 Code GmbH * * This file is part of GPGME. * @@ -45,7 +45,8 @@ GpgmeError _gpgme_gpgsm_op_encrypt (GpgsmObject gpgsm, GpgmeRecipients recp, GpgmeError _gpgme_gpgsm_op_export (GpgsmObject gpgsm, GpgmeRecipients recp, GpgmeData keydata, int use_armor); GpgmeError _gpgme_gpgsm_op_genkey (GpgsmObject gpgsm, GpgmeData help_data, - int use_armor); + int use_armor, GpgmeData pubkey, + GpgmeData seckey); GpgmeError _gpgme_gpgsm_op_import (GpgsmObject gpgsm, GpgmeData keydata); GpgmeError _gpgme_gpgsm_op_keylist (GpgsmObject gpgsm, const char *pattern, int secret_only, int keylist_mode); diff --git a/gpgme/engine.c b/gpgme/engine.c index 1d993217..608340e8 100644 --- a/gpgme/engine.c +++ b/gpgme/engine.c @@ -376,7 +376,8 @@ _gpgme_engine_op_export (EngineObject engine, GpgmeRecipients recp, } GpgmeError -_gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, int use_armor) +_gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, + int use_armor, GpgmeData pubkey, GpgmeData seckey) { if (!engine) return mk_error (Invalid_Value); @@ -384,9 +385,11 @@ _gpgme_engine_op_genkey (EngineObject engine, GpgmeData help_data, int use_armor switch (engine->protocol) { case GPGME_PROTOCOL_OpenPGP: - return _gpgme_gpg_op_genkey (engine->engine.gpg, help_data, use_armor); + return _gpgme_gpg_op_genkey (engine->engine.gpg, help_data, use_armor, + pubkey, seckey); case GPGME_PROTOCOL_CMS: - return _gpgme_gpgsm_op_genkey (engine->engine.gpgsm, help_data, use_armor); + return _gpgme_gpgsm_op_genkey (engine->engine.gpgsm, help_data, use_armor, + pubkey, seckey); default: break; } diff --git a/gpgme/engine.h b/gpgme/engine.h index c7a83425..a9d373e6 100644 --- a/gpgme/engine.h +++ b/gpgme/engine.h @@ -1,6 +1,6 @@ /* engine.h - GPGME engine calling functions * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001 g10 Code GmbH + * Copyright (C) 2001, 2002 g10 Code GmbH * * This file is part of GPGME. * @@ -49,7 +49,8 @@ GpgmeError _gpgme_engine_op_encrypt (EngineObject engine, GpgmeRecipients recp, 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); + int use_armor, GpgmeData pubkey, + GpgmeData seckey); GpgmeError _gpgme_engine_op_import (EngineObject engine, GpgmeData keydata); GpgmeError _gpgme_engine_op_keylist (EngineObject engine, const char *pattern, int secret_only, diff --git a/gpgme/genkey.c b/gpgme/genkey.c index 2537c8ce..9c654006 100644 --- a/gpgme/genkey.c +++ b/gpgme/genkey.c @@ -138,16 +138,6 @@ gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms, 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) - { - err = mk_error (Not_Implemented); - goto leave; - } - if (!pubkey && !seckey) ; /* okay: Add key to the keyrings */ else if (!pubkey || gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE) @@ -162,11 +152,12 @@ gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms, } if (pubkey) - { - _gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN); - _gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN); - /* FIXME: Need some more things here. */ - } + /* FIXME: Need some more things here. */ + _gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN); + + if (seckey) + /* FIXME: Need some more things here. */ + _gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN); if ((parms = strstr (parms, "')) @@ -188,7 +179,8 @@ gpgme_op_genkey_start (GpgmeCtx ctx, const char *parms, _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); + err = _gpgme_engine_op_genkey (ctx->engine, ctx->help_data_1, ctx->use_armor, + pubkey, seckey); if (!err) err = _gpgme_engine_start (ctx->engine, ctx); diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 92b7cbaf..b30bb04c 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -1338,10 +1338,21 @@ _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp, } GpgmeError -_gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor) +_gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) { GpgmeError err; + if (!gpg) + return mk_error (Invalid_Value); + + /* 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) + return err = mk_error (Not_Implemented); + err = _gpgme_gpg_add_arg (gpg, "--gen-key"); if (!err && use_armor) err = _gpgme_gpg_add_arg (gpg, "--armor"); diff --git a/gpgme/rungpg.h b/gpgme/rungpg.h index 9120a4d0..36bd5c4f 100644 --- a/gpgme/rungpg.h +++ b/gpgme/rungpg.h @@ -129,7 +129,8 @@ GpgmeError _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp, 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); + int use_armor, GpgmeData pubkey, + GpgmeData seckey); 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);