core: New function gpgme_op_revuid.
* src/engine.h (GENKEY_EXTRAFLAG_REVOKE): New. * src/genkey.c (adduid_start): Rename to addrevuid_start. Add arg REVOKE and pass it as extraflags. Remove useless ARMOR extraflag. Adjust callers. (gpgme_op_revuid_start, gpgme_op_revuid): New. * src/gpgme.def, src/libgpgme.vers: Add them. * tests/run-genkey.c: Add option --revuid. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
c22f5884c5
commit
c943380b7a
2
NEWS
2
NEWS
@ -21,6 +21,8 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_]
|
||||
gpgme_op_createsubkey_start NEW.
|
||||
gpgme_op_adduid_start NEW.
|
||||
gpgme_op_adduid NEW.
|
||||
gpgme_op_revuid_start NEW.
|
||||
gpgme_op_revuid NEW.
|
||||
gpgme_genkey_result_t EXTENDED: New fields pubkey and seckey.
|
||||
gpgme_signature_t EXTENDED: New field key.
|
||||
gpgme_key_t EXTENDED: New field fpr.
|
||||
|
@ -2115,14 +2115,19 @@ gpg_addkey (engine_gpg_t gpg,
|
||||
static gpgme_error_t
|
||||
gpg_adduid (engine_gpg_t gpg,
|
||||
gpgme_key_t key,
|
||||
const char *userid)
|
||||
const char *userid,
|
||||
unsigned int extraflags)
|
||||
{
|
||||
gpgme_error_t err;
|
||||
|
||||
if (!key || !key->fpr || !userid)
|
||||
return gpg_error (GPG_ERR_INV_ARG);
|
||||
|
||||
err = add_arg (gpg, "--quick-adduid");
|
||||
if ((extraflags & GENKEY_EXTRAFLAG_REVOKE))
|
||||
err = add_arg (gpg, "--quick-revuid");
|
||||
else
|
||||
err = add_arg (gpg, "--quick-adduid");
|
||||
|
||||
if (!err)
|
||||
err = add_arg (gpg, "--");
|
||||
if (!err)
|
||||
@ -2184,7 +2189,7 @@ gpg_genkey (void *engine,
|
||||
else if (!userid && key)
|
||||
err = gpg_addkey (gpg, algo, expires, key, flags, extraflags);
|
||||
else if (userid && key && !algo)
|
||||
err = gpg_adduid (gpg, key, userid);
|
||||
err = gpg_adduid (gpg, key, userid, extraflags);
|
||||
else
|
||||
err = gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
||||
#include "gpgme.h"
|
||||
|
||||
/* Flags used by the EXTRAFLAGS arg of _gpgme_engine_op_genkey. */
|
||||
#define GENKEY_EXTRAFLAG_ARMOR 1
|
||||
#define GENKEY_EXTRAFLAG_ARMOR 1
|
||||
#define GENKEY_EXTRAFLAG_REVOKE 2
|
||||
|
||||
|
||||
struct engine;
|
||||
|
51
src/genkey.c
51
src/genkey.c
@ -181,7 +181,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args)
|
||||
return gpg_error (GPG_ERR_GENERAL);
|
||||
else if (opd->failure_code)
|
||||
return opd->failure_code;
|
||||
else if (opd->uidmode)
|
||||
else if (opd->uidmode == 1)
|
||||
opd->result.uid = 1; /* We have no status line, thus this hack. */
|
||||
break;
|
||||
|
||||
@ -489,8 +489,8 @@ gpgme_op_createsubkey (gpgme_ctx_t ctx, gpgme_key_t key, const char *algo,
|
||||
|
||||
|
||||
static gpgme_error_t
|
||||
adduid_start (gpgme_ctx_t ctx, int synchronous,
|
||||
gpgme_key_t key, const char *userid, unsigned int flags)
|
||||
addrevuid_start (gpgme_ctx_t ctx, int synchronous, int revoke,
|
||||
gpgme_key_t key, const char *userid, unsigned int flags)
|
||||
{
|
||||
gpgme_error_t err;
|
||||
void *hook;
|
||||
@ -512,7 +512,7 @@ adduid_start (gpgme_ctx_t ctx, int synchronous,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
opd->uidmode = 1;
|
||||
opd->uidmode = revoke? 2 : 1;
|
||||
|
||||
_gpgme_engine_set_status_handler (ctx->engine, genkey_status_handler, ctx);
|
||||
|
||||
@ -528,7 +528,7 @@ adduid_start (gpgme_ctx_t ctx, int synchronous,
|
||||
userid, NULL, 0, 0,
|
||||
key, flags,
|
||||
NULL,
|
||||
ctx->use_armor? GENKEY_EXTRAFLAG_ARMOR:0,
|
||||
revoke? GENKEY_EXTRAFLAG_REVOKE : 0,
|
||||
NULL, NULL);
|
||||
|
||||
}
|
||||
@ -547,7 +547,7 @@ gpgme_op_adduid_start (gpgme_ctx_t ctx,
|
||||
if (!ctx)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_ARG));
|
||||
|
||||
err = adduid_start (ctx, 0, key, userid, flags);
|
||||
err = addrevuid_start (ctx, 0, 0, key, userid, flags);
|
||||
return TRACE_ERR (err);
|
||||
}
|
||||
|
||||
@ -564,7 +564,44 @@ gpgme_op_adduid (gpgme_ctx_t ctx,
|
||||
if (!ctx)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_ARG));
|
||||
|
||||
err = adduid_start (ctx, 1, key, userid, flags);
|
||||
err = addrevuid_start (ctx, 1, 0, key, userid, flags);
|
||||
if (!err)
|
||||
err = _gpgme_wait_one (ctx);
|
||||
return TRACE_ERR (err);
|
||||
}
|
||||
|
||||
|
||||
/* Revoke USERID from KEY. */
|
||||
gpgme_error_t
|
||||
gpgme_op_revuid_start (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid, unsigned int flags)
|
||||
{
|
||||
gpgme_error_t err;
|
||||
|
||||
TRACE_BEG2 (DEBUG_CTX, "gpgme_op_revuid_start", ctx,
|
||||
"uid='%s' flags=0x%x", userid, flags);
|
||||
|
||||
if (!ctx)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_ARG));
|
||||
|
||||
err = addrevuid_start (ctx, 0, 1, key, userid, flags);
|
||||
return TRACE_ERR (err);
|
||||
}
|
||||
|
||||
|
||||
gpgme_error_t
|
||||
gpgme_op_revuid (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid, unsigned int flags)
|
||||
{
|
||||
gpgme_error_t err;
|
||||
|
||||
TRACE_BEG2 (DEBUG_CTX, "gpgme_op_revuid", ctx,
|
||||
"uid='%s' flags=0x%x", userid, flags);
|
||||
|
||||
if (!ctx)
|
||||
return TRACE_ERR (gpg_error (GPG_ERR_INV_ARG));
|
||||
|
||||
err = addrevuid_start (ctx, 1, 1, key, userid, flags);
|
||||
if (!err)
|
||||
err = _gpgme_wait_one (ctx);
|
||||
return TRACE_ERR (err);
|
||||
|
@ -235,6 +235,8 @@ EXPORTS
|
||||
gpgme_op_createsubkey @175
|
||||
gpgme_op_adduid_start @176
|
||||
gpgme_op_adduid @177
|
||||
gpgme_op_revuid_start @178
|
||||
gpgme_op_revuid @179
|
||||
|
||||
; END
|
||||
|
||||
|
@ -1894,10 +1894,18 @@ gpgme_error_t gpgme_op_createsubkey (gpgme_ctx_t ctx,
|
||||
/* Add USERID to an existing KEY. */
|
||||
gpgme_error_t gpgme_op_adduid_start (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid,
|
||||
unsigned int flags);
|
||||
unsigned int reserved);
|
||||
gpgme_error_t gpgme_op_adduid (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid,
|
||||
unsigned int flags);
|
||||
unsigned int reserved);
|
||||
|
||||
/* Revoke a USERID from a KEY. */
|
||||
gpgme_error_t gpgme_op_revuid_start (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid,
|
||||
unsigned int reserved);
|
||||
gpgme_error_t gpgme_op_revuid (gpgme_ctx_t ctx,
|
||||
gpgme_key_t key, const char *userid,
|
||||
unsigned int reserved);
|
||||
|
||||
|
||||
|
||||
|
@ -109,6 +109,8 @@ GPGME_1.1 {
|
||||
gpgme_op_createsubkey;
|
||||
gpgme_op_adduid_start;
|
||||
gpgme_op_adduid;
|
||||
gpgme_op_revuid_start;
|
||||
gpgme_op_revuid;
|
||||
};
|
||||
|
||||
|
||||
|
@ -203,9 +203,11 @@ show_usage (int ex)
|
||||
" args: USERID [ALGO [USAGE [EXPIRESECONDS]]]\n"
|
||||
" for addkey: FPR [ALGO [USAGE [EXPIRESECONDS]]]\n"
|
||||
" for adduid: FPR USERID\n"
|
||||
" for revuid: FPR USERID\n"
|
||||
"Options:\n"
|
||||
" --addkey add a subkey to the key with FPR\n"
|
||||
" --adduid add a user id to the key with FPR\n"
|
||||
" --revuid Revoke a user id from the key with FPR\n"
|
||||
" --verbose run in verbose mode\n"
|
||||
" --status print status lines from the backend\n"
|
||||
" --progress print progress info\n"
|
||||
@ -231,6 +233,7 @@ main (int argc, char **argv)
|
||||
int use_loopback = 0;
|
||||
int addkey = 0;
|
||||
int adduid = 0;
|
||||
int revuid = 0;
|
||||
const char *userid;
|
||||
const char *algo = NULL;
|
||||
const char *newuserid = NULL;
|
||||
@ -255,12 +258,21 @@ main (int argc, char **argv)
|
||||
{
|
||||
addkey = 1;
|
||||
adduid = 0;
|
||||
revuid = 0;
|
||||
argc--; argv++;
|
||||
}
|
||||
else if (!strcmp (*argv, "--adduid"))
|
||||
{
|
||||
addkey = 0;
|
||||
adduid = 1;
|
||||
revuid = 0;
|
||||
argc--; argv++;
|
||||
}
|
||||
else if (!strcmp (*argv, "--revuid"))
|
||||
{
|
||||
addkey = 0;
|
||||
adduid = 0;
|
||||
revuid = 1;
|
||||
argc--; argv++;
|
||||
}
|
||||
else if (!strcmp (*argv, "--verbose"))
|
||||
@ -307,7 +319,7 @@ main (int argc, char **argv)
|
||||
show_usage (1);
|
||||
}
|
||||
|
||||
if (adduid)
|
||||
if (adduid || revuid)
|
||||
{
|
||||
if (argc != 2)
|
||||
show_usage (1);
|
||||
@ -346,7 +358,7 @@ main (int argc, char **argv)
|
||||
gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
|
||||
}
|
||||
|
||||
if (addkey || adduid)
|
||||
if (addkey || adduid || revuid)
|
||||
{
|
||||
gpgme_key_t akey;
|
||||
|
||||
@ -378,6 +390,16 @@ main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if (revuid)
|
||||
{
|
||||
err = gpgme_op_revuid (ctx, akey, newuserid, flags);
|
||||
if (err)
|
||||
{
|
||||
fprintf (stderr, PGM ": gpgme_op_revuid failed: %s\n",
|
||||
gpg_strerror (err));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
gpgme_key_unref (akey);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user