From e416f9961837039f259558edf41fccbc181ad128 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Wed, 11 Jan 2017 16:14:45 +0100 Subject: [PATCH] cpp: Add revuid and adduid support * lang/cpp/src/context.cpp (Context::revUid, Context::startRevUid), (Context::addUid, Context::startAddUid): New. * lang/cpp/src/context.h: Declare new functions. * lang/cpp/src/key.cpp (Key::UserID::revoke) (Key::addUid): Idomatic helpers. lang/cpp/src/key.h: Declare new functions. * NEWS: Update accordingly. --- NEWS | 11 +++++++++++ lang/cpp/src/context.cpp | 24 ++++++++++++++++++++++++ lang/cpp/src/context.h | 6 ++++++ lang/cpp/src/key.cpp | 28 ++++++++++++++++++++++++++++ lang/cpp/src/key.h | 18 ++++++++++++++++++ 5 files changed, 87 insertions(+) diff --git a/NEWS b/NEWS index 39b41f6f..c0ae27fa 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,17 @@ Noteworthy changes in version 1.8.1 (unreleased) ------------------------------------------------ + * cpp: Support for adduid and revuid operations. + + * Interface changes relative to the 1.8.0 release: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + cpp: Context::revUid(const Key&, const char*) NEW. + cpp: Context::startRevUid(const Key&, const char*) NEW. + cpp: Context::addUid(const Key&, const char*) NEW. + cpp: Context::startAddUid(const Key&, const char*) NEW. + cpp: Key::UserID::revoke() NEW. + cpp: Key::addUid() NEW. + Noteworthy changes in version 1.8.0 (2016-11-16) ------------------------------------------------ diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index ada7bead..040e8f32 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -1376,6 +1376,30 @@ Error Context::setTofuPolicyStart(const Key &k, unsigned int policy) k.impl(), to_tofu_policy_t(policy))); } +Error Context::addUid(const Key &k, const char *userid) +{ + return Error(d->lasterr = gpgme_op_adduid(d->ctx, + k.impl(), userid, 0)); +} + +Error Context::startAddUid(const Key &k, const char *userid) +{ + return Error(d->lasterr = gpgme_op_adduid_start(d->ctx, + k.impl(), userid, 0)); +} + +Error Context::revUid(const Key &k, const char *userid) +{ + return Error(d->lasterr = gpgme_op_revuid(d->ctx, + k.impl(), userid, 0)); +} + +Error Context::startRevUid(const Key &k, const char *userid) +{ + return Error(d->lasterr = gpgme_op_revuid_start(d->ctx, + k.impl(), userid, 0)); +} + // Engine Spawn stuff Error Context::spawn(const char *file, const char *argv[], Data &input, Data &output, Data &err, diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h index 2c205b02..b075bf1b 100644 --- a/lang/cpp/src/context.h +++ b/lang/cpp/src/context.h @@ -214,6 +214,12 @@ public: GpgME::Error edit(const Key &key, std::unique_ptr function, Data &out); GpgME::Error startEditing(const Key &key, std::unique_ptr function, Data &out); + Error addUid(const Key &key, const char *userid); + Error startAddUid(const Key &key, const char *userid); + + Error revUid(const Key &key, const char *userid); + Error startRevUid(const Key &key, const char *userid); + // using TofuInfo::Policy Error setTofuPolicy(const Key &k, unsigned int policy); Error setTofuPolicyStart(const Key &k, unsigned int policy); diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 4f7ec54b..3cc26a77 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -906,6 +906,34 @@ std::string UserID::addrSpec() const return uid->address; } +Error UserID::revoke() +{ + if (isNull()) { + return Error::fromCode(GPG_ERR_GENERAL); + } + auto ctx = Context::createForProtocol(parent().protocol()); + if (!ctx) { + return Error::fromCode(GPG_ERR_INV_ENGINE); + } + Error ret = ctx->revUid(key, id()); + delete ctx; + return ret; +} + +Error Key::addUid(const char *uid) +{ + if (isNull()) { + return Error::fromCode(GPG_ERR_GENERAL); + } + auto ctx = Context::createForProtocol(protocol()); + if (!ctx) { + return Error::fromCode(GPG_ERR_INV_ENGINE); + } + Error ret = ctx->addUid(key, uid); + delete ctx; + return ret; +} + std::ostream &operator<<(std::ostream &os, const UserID &uid) { os << "GpgME::UserID("; diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 3f596a82..b0599c7f 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -152,6 +152,17 @@ public: * how long the keylisting takes.*/ void update(); + /** + * @brief Add a user id to this key. + * + * Needs gnupg 2.1.13 and the key needs to be updated + * afterwards to see the new uid. + * + * @param uid should be fully formated and UTF-8 encoded. + * + * @returns a possible error. + **/ + Error addUid(const char *uid); private: gpgme_key_t impl() const { @@ -335,6 +346,13 @@ public: * @returns a normalized mail address for this userid * or an empty string. */ std::string addrSpec() const; + + /*! Revoke the user id. + * + * Key needs update afterwards. + * + * @returns an error on error.*/ + Error revoke(); private: shared_gpgme_key_t key; gpgme_user_id_t uid;