cpp: Add support for gpgme_op_setexpire
* lang/cpp/src/context.cpp (Context::setExpire, Context::startSetExpire): New. (Context::getLFSeparatedListOfFingerprintsFromSubkeys): New helper. * lang/cpp/src/context.h (Context::SetExpireFlags): New enum. (Context::setExpire, Context::startSetExpire): Add prototypes. (Context::getLFSeparatedListOfFingerprintsFromSubkeys): Add as private helper. -- GnuPG-bug-id: 5003
This commit is contained in:
parent
197ba151e7
commit
aa03205fe5
4
NEWS
4
NEWS
@ -4,10 +4,14 @@ Noteworthy changes in version 1.14.1 (unreleased)
|
|||||||
* New function gpgme_op_setexpire to make changing the expiration
|
* New function gpgme_op_setexpire to make changing the expiration
|
||||||
easier (requires GnuPG 2.1.22). [#4999]
|
easier (requires GnuPG 2.1.22). [#4999]
|
||||||
|
|
||||||
|
* cpp: Support for set expire operations in the C++ bindings. [#5003]
|
||||||
|
|
||||||
* Interface changes relative to the 1.14.0 release:
|
* Interface changes relative to the 1.14.0 release:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
gpgme_op_setexpire_start NEW.
|
gpgme_op_setexpire_start NEW.
|
||||||
gpgme_op_setexpire NEW.
|
gpgme_op_setexpire NEW.
|
||||||
|
cpp: Context::setExpire NEW.
|
||||||
|
cpp: Context::startSetExpire NEW.
|
||||||
|
|
||||||
|
|
||||||
Noteworthy changes in version 1.14.0 (2020-07-16)
|
Noteworthy changes in version 1.14.0 (2020-07-16)
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include <gpgme.h>
|
#include <gpgme.h>
|
||||||
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
#include <numeric>
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
@ -1526,6 +1527,62 @@ Error Context::startCreateSubkey(const Key &k, const char *algo,
|
|||||||
k.impl(), algo, reserved, expires, flags));
|
k.impl(), algo, reserved, expires, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Context::getLFSeparatedListOfFingerprintsFromSubkeys(const std::vector<Subkey> &subkeys)
|
||||||
|
{
|
||||||
|
if (subkeys.empty()) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> fprs;
|
||||||
|
fprs.reserve(subkeys.size());
|
||||||
|
for (auto &it : subkeys) {
|
||||||
|
if (it.fingerprint()) {
|
||||||
|
fprs.push_back(std::string(it.fingerprint()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fprs.empty()) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::accumulate(
|
||||||
|
std::next(fprs.begin()),
|
||||||
|
fprs.end(),
|
||||||
|
fprs[0],
|
||||||
|
[](const std::string &a, const std::string &b) {
|
||||||
|
return a + '\n' + b;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Error Context::setExpire(const Key &k, unsigned long expires,
|
||||||
|
const std::vector<Subkey> &subkeys,
|
||||||
|
const Context::SetExpireFlags flags)
|
||||||
|
{
|
||||||
|
std::string subfprs;
|
||||||
|
if (flags & Context::SetExpireAllSubkeys) {
|
||||||
|
subfprs = "*";
|
||||||
|
} else {
|
||||||
|
subfprs = getLFSeparatedListOfFingerprintsFromSubkeys(subkeys);
|
||||||
|
}
|
||||||
|
return Error(d->lasterr = gpgme_op_setexpire(d->ctx,
|
||||||
|
k.impl(), expires, subfprs.c_str(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Error Context::startSetExpire(const Key &k, unsigned long expires,
|
||||||
|
const std::vector<Subkey> &subkeys,
|
||||||
|
const Context::SetExpireFlags flags)
|
||||||
|
{
|
||||||
|
std::string subfprs;
|
||||||
|
if (flags & Context::SetExpireAllSubkeys) {
|
||||||
|
subfprs = "*";
|
||||||
|
} else {
|
||||||
|
subfprs = getLFSeparatedListOfFingerprintsFromSubkeys(subkeys);
|
||||||
|
}
|
||||||
|
return Error(d->lasterr = gpgme_op_setexpire_start(d->ctx,
|
||||||
|
k.impl(), expires, subfprs.c_str(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
Error Context::setFlag(const char *name, const char *value)
|
Error Context::setFlag(const char *name, const char *value)
|
||||||
{
|
{
|
||||||
return Error(d->lasterr = gpgme_set_ctx_flag(d->ctx, name, value));
|
return Error(d->lasterr = gpgme_set_ctx_flag(d->ctx, name, value));
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "key.h"
|
||||||
#include "verificationresult.h" // for Signature::Notation
|
#include "verificationresult.h" // for Signature::Notation
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -37,7 +38,6 @@
|
|||||||
namespace GpgME
|
namespace GpgME
|
||||||
{
|
{
|
||||||
|
|
||||||
class Key;
|
|
||||||
class Data;
|
class Data;
|
||||||
class TrustItem;
|
class TrustItem;
|
||||||
class ProgressProvider;
|
class ProgressProvider;
|
||||||
@ -273,6 +273,18 @@ public:
|
|||||||
unsigned long expires = 0,
|
unsigned long expires = 0,
|
||||||
unsigned int flags = 0);
|
unsigned int flags = 0);
|
||||||
|
|
||||||
|
enum SetExpireFlags {
|
||||||
|
SetExpireDefault = 0,
|
||||||
|
SetExpireAllSubkeys = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
Error setExpire(const Key &k, unsigned long expires,
|
||||||
|
const std::vector<Subkey> &subkeys = std::vector<Subkey>(),
|
||||||
|
const SetExpireFlags flags = SetExpireDefault);
|
||||||
|
Error startSetExpire(const Key &k, unsigned long expires,
|
||||||
|
const std::vector<Subkey> &subkeys = std::vector<Subkey>(),
|
||||||
|
const SetExpireFlags flags = SetExpireDefault);
|
||||||
|
|
||||||
// using TofuInfo::Policy
|
// using TofuInfo::Policy
|
||||||
Error setTofuPolicy(const Key &k, unsigned int policy);
|
Error setTofuPolicy(const Key &k, unsigned int policy);
|
||||||
Error setTofuPolicyStart(const Key &k, unsigned int policy);
|
Error setTofuPolicyStart(const Key &k, unsigned int policy);
|
||||||
@ -488,6 +500,8 @@ private:
|
|||||||
// on the "Friendlyness" of context to access the gpgme types.
|
// on the "Friendlyness" of context to access the gpgme types.
|
||||||
gpgme_key_t *getKeysFromRecipients(const std::vector<Key> &recipients);
|
gpgme_key_t *getKeysFromRecipients(const std::vector<Key> &recipients);
|
||||||
|
|
||||||
|
std::string getLFSeparatedListOfFingerprintsFromSubkeys(const std::vector<Subkey> &subkeys);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Private *const d;
|
Private *const d;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user