diff options
author | Ingo Klöcker <[email protected]> | 2024-08-06 13:32:20 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2024-08-06 15:56:43 +0000 |
commit | d5f612e9685d18313d445799a19ff83e013f1b0a (patch) | |
tree | 3f71490833fe5fbfc7aedd375f1ff0d6201cae32 | |
parent | core: New function gpgme_op_setownertrust (diff) | |
download | gpgme-d5f612e9685d18313d445799a19ff83e013f1b0a.tar.gz gpgme-d5f612e9685d18313d445799a19ff83e013f1b0a.zip |
cpp: Add support for setting owner trust and for disabling keys
* lang/cpp/src/context.cpp, lang/cpp/src/context.h (class Context): Add
member functions setOwnerTrust, startSetOwnerTrust, setKeyEnabled,
startSetKeyEnabled.
* lang/cpp/src/context.cpp (owner_trust_to_string): New.
--
GnuPG-bug-id: 7239
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | lang/cpp/src/context.cpp | 45 | ||||
-rw-r--r-- | lang/cpp/src/context.h | 22 |
3 files changed, 74 insertions, 0 deletions
@@ -21,6 +21,9 @@ Noteworthy changes in version 1.24.0 (unrelease) * cpp: Add safer member function returning text describing an error. [T5960] + * cpp: Add support for setting the owner trust of keys and for enabling + and disabling keys. [T7239] + * qt: Build QGpgME for Qt 5 and Qt 6 simultaneously. [T7205] * qt: Install headers for Qt 5 and Qt 6 in separate folders. [T7161] @@ -45,6 +48,10 @@ Noteworthy changes in version 1.24.0 (unrelease) gpgme_op_setownertrust_start NEW. gpgme_op_setownertrust NEW. cpp: Context::EncryptFile NEW. + cpp: Context::setOwnerTrust NEW. + cpp: Context::startSetOwnerTrust NEW. + cpp: Context::setKeyEnabled NEW. + cpp: Context::startSetKeyEnabled NEW. cpp: SignatureMode::SignFile NEW. cpp: RevocationKey NEW. cpp: Key::revocationKey NEW. diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 8150d08b..7a0fb23f 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -1767,6 +1767,51 @@ Error Context::startSetExpire(const Key &k, unsigned long expires, k.impl(), expires, subfprs.c_str(), 0)); } +static const char *owner_trust_to_string(Key::OwnerTrust trust) +{ + static const char *const owner_trust_strings[] = { + "undefined", // --quick-set-ownertrust wants "undefined" for Unknown + "undefined", // Undefined is never used for key->owner_trust + "never", + "marginal", + "full", + "ultimate", + }; + + if (Key::OwnerTrust::Unknown <= trust && trust <= Key::OwnerTrust::Ultimate) { + return owner_trust_strings[trust]; + } + return nullptr; +} + +Error Context::setOwnerTrust(const Key &key, Key::OwnerTrust trust) +{ + d->lasterr = gpgme_op_setownertrust(d->ctx, key.impl(), + owner_trust_to_string(trust)); + return Error(d->lasterr); +} + +Error Context::startSetOwnerTrust(const Key &key, Key::OwnerTrust trust) +{ + d->lasterr = gpgme_op_setownertrust_start(d->ctx, key.impl(), + owner_trust_to_string(trust)); + return Error(d->lasterr); +} + +Error Context::setKeyEnabled(const Key &key, bool enabled) +{ + d->lasterr = gpgme_op_setownertrust(d->ctx, key.impl(), + enabled ? "enable" : "disable"); + return Error(d->lasterr); +} + +Error Context::startSetKeyEnabled(const Key &key, bool enabled) +{ + d->lasterr = gpgme_op_setownertrust_start(d->ctx, key.impl(), + enabled ? "enable" : "disable"); + return Error(d->lasterr); +} + static std::string getLFSeparatedListOfUserIds(const std::vector<UserID> &userIds) { if (userIds.empty()) { diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h index c4f968f4..e2c73b64 100644 --- a/lang/cpp/src/context.h +++ b/lang/cpp/src/context.h @@ -319,6 +319,28 @@ public: const std::vector<Subkey> &subkeys = std::vector<Subkey>(), const SetExpireFlags flags = SetExpireDefault); + /** + * Sets the owner trust of the key \a key to the value \a trust. + * Requires gpg 2.4.6. + */ + Error setOwnerTrust(const Key &key, Key::OwnerTrust trust); + /** + * Starts the operation to set the owner trust of the key \a key to the value \a trust. + * Requires gpg 2.4.6. + */ + Error startSetOwnerTrust(const Key &key, Key::OwnerTrust trust); + + /** + * Enables or disables the key \a key. + * Requires gpg 2.4.6. + */ + Error setKeyEnabled(const Key &key, bool enabled); + /** + * Starts the operation to enable or disable the key \a key. + * Requires gpg 2.4.6. + */ + Error startSetKeyEnabled(const Key &key, bool enabled); + Error revokeSignature(const Key &key, const Key &signingKey, const std::vector<UserID> &userIds = std::vector<UserID>()); Error startRevokeSignature(const Key &key, const Key &signingKey, |