From c22f5884c50557f54704f4becc5a8c1ee0749547 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 14 Sep 2016 12:15:35 +0200 Subject: [PATCH] core: Change a parameter for the engine's genkey function. * src/engine.h (GENKEY_EXTRAFLAG_ARMOR): New. * src/engine-backend.h (engine_ops): Rename USE_ARMOR in genkey to EXTRAFLAGS. * src/engine.c (_gpgme_engine_op_genkey): Ditto. * src/engine-gpg.c (gpg_createkey_from_param): Ditto and test the flags. (gpg_createkey_legacy): Ditto. (gpg_createkey): Ditto. (gpg_addkey): Ditto. (gpg_genkey): Ditto. Signed-off-by: Werner Koch --- src/engine-backend.h | 3 ++- src/engine-gpg.c | 24 ++++++++++++------------ src/engine-gpgsm.c | 5 +++-- src/engine.c | 6 +++--- src/engine.h | 7 ++++++- src/genkey.c | 15 +++++++++++---- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/engine-backend.h b/src/engine-backend.h index 842292dd..ec1a58c5 100644 --- a/src/engine-backend.h +++ b/src/engine-backend.h @@ -86,7 +86,8 @@ struct engine_ops const char *userid, const char *algo, unsigned long reserved, unsigned long expires, gpgme_key_t key, unsigned int flags, - gpgme_data_t help_data, int use_armor, + gpgme_data_t help_data, + unsigned int extraflags, gpgme_data_t pubkey, gpgme_data_t seckey); gpgme_error_t (*import) (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray); diff --git a/src/engine-gpg.c b/src/engine-gpg.c index d2b6dd34..db6637a2 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -2012,12 +2012,12 @@ gpg_add_algo_usage_expire (engine_gpg_t gpg, static gpgme_error_t gpg_createkey_from_param (engine_gpg_t gpg, - gpgme_data_t help_data, int use_armor) + gpgme_data_t help_data, unsigned int extraflags) { gpgme_error_t err; err = add_arg (gpg, "--gen-key"); - if (!err && use_armor) + if (!err && (extraflags & GENKEY_EXTRAFLAG_ARMOR)) err = add_arg (gpg, "--armor"); if (!err) err = add_arg (gpg, "--"); @@ -2036,7 +2036,7 @@ gpg_createkey_legacy (engine_gpg_t gpg, const char *userid, const char *algo, unsigned long expires, unsigned int flags, - int use_armor) + unsigned int extraflags) { return gpg_error (GPG_ERR_NOT_IMPLEMENTED); } @@ -2047,12 +2047,12 @@ gpg_createkey (engine_gpg_t gpg, const char *userid, const char *algo, unsigned long expires, unsigned int flags, - int use_armor) + unsigned int extraflags) { gpgme_error_t err; err = add_arg (gpg, "--quick-gen-key"); - if (!err && use_armor) + if (!err && (extraflags & GENKEY_EXTRAFLAG_ARMOR)) err = add_arg (gpg, "--armor"); if (!err && (flags & GPGME_CREATE_NOPASSWD)) { @@ -2082,7 +2082,7 @@ gpg_addkey (engine_gpg_t gpg, unsigned long expires, gpgme_key_t key, unsigned int flags, - int use_armor) + unsigned int extraflags) { gpgme_error_t err; @@ -2090,7 +2090,7 @@ gpg_addkey (engine_gpg_t gpg, return gpg_error (GPG_ERR_INV_ARG); err = add_arg (gpg, "--quick-addkey"); - if (!err && use_armor) + if (!err && (extraflags & GENKEY_EXTRAFLAG_ARMOR)) err = add_arg (gpg, "--armor"); if (!err && (flags & GPGME_CREATE_NOPASSWD)) { @@ -2141,7 +2141,7 @@ gpg_genkey (void *engine, const char *userid, const char *algo, unsigned long reserved, unsigned long expires, gpgme_key_t key, unsigned int flags, - gpgme_data_t help_data, int use_armor, + gpgme_data_t help_data, unsigned int extraflags, gpgme_data_t pubkey, gpgme_data_t seckey) { engine_gpg_t gpg = engine; @@ -2169,20 +2169,20 @@ gpg_genkey (void *engine, if (pubkey || seckey) err = gpg_error (GPG_ERR_NOT_IMPLEMENTED); else - err = gpg_createkey_from_param (gpg, help_data, use_armor); + err = gpg_createkey_from_param (gpg, help_data, extraflags); } else if (userid && !key) { if (!have_gpg_version (gpg, "2.1.13")) err = gpg_createkey_legacy (gpg, userid, algo, expires, flags, - use_armor); + extraflags); else - err = gpg_createkey (gpg, userid, algo, expires, flags, use_armor); + err = gpg_createkey (gpg, userid, algo, expires, flags, extraflags); } else if (!have_gpg_version (gpg, "2.1.13")) err = gpg_error (GPG_ERR_NOT_SUPPORTED); else if (!userid && key) - err = gpg_addkey (gpg, algo, expires, key, flags, use_armor); + err = gpg_addkey (gpg, algo, expires, key, flags, extraflags); else if (userid && key && !algo) err = gpg_adduid (gpg, key, userid); else diff --git a/src/engine-gpgsm.c b/src/engine-gpgsm.c index 0610c7a7..071626a9 100644 --- a/src/engine-gpgsm.c +++ b/src/engine-gpgsm.c @@ -1447,7 +1447,7 @@ gpgsm_genkey (void *engine, const char *userid, const char *algo, unsigned long reserved, unsigned long expires, gpgme_key_t key, unsigned int flags, - gpgme_data_t help_data, int use_armor, + gpgme_data_t help_data, unsigned int extraflags, gpgme_data_t pubkey, gpgme_data_t seckey) { engine_gpgsm_t gpgsm = engine; @@ -1468,7 +1468,8 @@ gpgsm_genkey (void *engine, if (err) return err; gpgsm->output_cb.data = pubkey; - err = gpgsm_set_fd (gpgsm, OUTPUT_FD, use_armor ? "--armor" + err = gpgsm_set_fd (gpgsm, OUTPUT_FD, + (extraflags & GENKEY_EXTRAFLAG_ARMOR)? "--armor" : map_data_enc (gpgsm->output_cb.data)); if (err) return err; diff --git a/src/engine.c b/src/engine.c index 1ff86981..b3bbcab7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -778,8 +778,8 @@ _gpgme_engine_op_genkey (engine_t engine, unsigned long reserved, unsigned long expires, gpgme_key_t key, unsigned int flags, gpgme_data_t help_data, - int use_armor, gpgme_data_t pubkey, - gpgme_data_t seckey) + unsigned int extraflags, + gpgme_data_t pubkey, gpgme_data_t seckey) { if (!engine) return gpg_error (GPG_ERR_INV_VALUE); @@ -789,7 +789,7 @@ _gpgme_engine_op_genkey (engine_t engine, return (*engine->ops->genkey) (engine->engine, userid, algo, reserved, expires, key, flags, - help_data, use_armor, + help_data, extraflags, pubkey, seckey); } diff --git a/src/engine.h b/src/engine.h index 857dff42..391caf28 100644 --- a/src/engine.h +++ b/src/engine.h @@ -24,6 +24,10 @@ #include "gpgme.h" +/* Flags used by the EXTRAFLAGS arg of _gpgme_engine_op_genkey. */ +#define GENKEY_EXTRAFLAG_ARMOR 1 + + struct engine; typedef struct engine *engine_t; @@ -113,7 +117,8 @@ gpgme_error_t _gpgme_engine_op_genkey (engine_t engine, unsigned long expires, gpgme_key_t key, unsigned int flags, gpgme_data_t help_data, - int use_armor, gpgme_data_t pubkey, + unsigned int extraflags, + gpgme_data_t pubkey, gpgme_data_t seckey); gpgme_error_t _gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata, diff --git a/src/genkey.c b/src/genkey.c index b93abb80..100e655e 100644 --- a/src/genkey.c +++ b/src/genkey.c @@ -267,7 +267,8 @@ genkey_start (gpgme_ctx_t ctx, int synchronous, const char *parms, return _gpgme_engine_op_genkey (ctx->engine, NULL, NULL, 0, 0, NULL, 0, opd->key_parameter, - ctx->use_armor, pubkey, seckey); + ctx->use_armor? GENKEY_EXTRAFLAG_ARMOR:0, + pubkey, seckey); } @@ -352,7 +353,9 @@ createkey_start (gpgme_ctx_t ctx, int synchronous, return _gpgme_engine_op_genkey (ctx->engine, userid, algo, reserved, expires, anchorkey, flags, - NULL, ctx->use_armor, NULL, NULL); + NULL, + ctx->use_armor? GENKEY_EXTRAFLAG_ARMOR:0, + NULL, NULL); } @@ -438,7 +441,9 @@ createsubkey_start (gpgme_ctx_t ctx, int synchronous, return _gpgme_engine_op_genkey (ctx->engine, NULL, algo, reserved, expires, key, flags, - NULL, ctx->use_armor, NULL, NULL); + NULL, + ctx->use_armor? GENKEY_EXTRAFLAG_ARMOR:0, + NULL, NULL); } @@ -522,7 +527,9 @@ adduid_start (gpgme_ctx_t ctx, int synchronous, return _gpgme_engine_op_genkey (ctx->engine, userid, NULL, 0, 0, key, flags, - NULL, ctx->use_armor, NULL, NULL); + NULL, + ctx->use_armor? GENKEY_EXTRAFLAG_ARMOR:0, + NULL, NULL); }