From 2faa031af24959d5093da430d5f10fe30d77a75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 30 Jan 2023 12:08:43 +0100 Subject: [PATCH] cpp: Support new archive signing flag * lang/cpp/src/global.h (enum SignatureMode): Add constant SignArchive. * lang/cpp/src/context.cpp (sigmode2sigmode): Rename to sigflags2sigflags (sigflags2sigflags): ... and rename argument mode to flags and treat it as flags. Adjust the callers. (operator<<): Change local CHECK macro to handle flags. Add new flag to debug stream. * lang/cpp/src/signingresult.cpp (CreatedSignature::mode): Handle new flags (even if it cannot occur currently). -- GnuPG-bug-id: 6342 --- lang/cpp/src/context.cpp | 32 ++++++++++++++++++-------------- lang/cpp/src/global.h | 7 ++++++- lang/cpp/src/signingresult.cpp | 1 + 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index f7f6f54d..68b061db 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -1278,14 +1278,22 @@ std::vector Context::signatureNotations() const return result; } -static gpgme_sig_mode_t sigmode2sigmode(SignatureMode mode) +static gpgme_sig_mode_t sigflags2sigflags(SignatureMode flags) { - switch (mode) { - default: - case NormalSignatureMode: return GPGME_SIG_MODE_NORMAL; - case Detached: return GPGME_SIG_MODE_DETACH; - case Clearsigned: return GPGME_SIG_MODE_CLEAR; + unsigned int result = 0; + if (flags & SignatureMode::NormalSignatureMode) { + result |= GPGME_SIG_MODE_NORMAL; } + if (flags & SignatureMode::Detached) { + result |= GPGME_SIG_MODE_DETACH; + } + if (flags & SignatureMode::Clearsigned) { + result |= GPGME_SIG_MODE_CLEAR; + } + if (flags & SignatureMode::SignArchive) { + result |= GPGME_SIG_MODE_ARCHIVE; + } + return static_cast(result); } SigningResult Context::sign(const Data &plainText, Data &signature, SignatureMode mode) @@ -1293,7 +1301,7 @@ SigningResult Context::sign(const Data &plainText, Data &signature, SignatureMod d->lastop = Private::Sign; const Data::Private *const pdp = plainText.impl(); Data::Private *const sdp = signature.impl(); - d->lasterr = gpgme_op_sign(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigmode2sigmode(mode)); + d->lasterr = gpgme_op_sign(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigflags2sigflags(mode)); return SigningResult(d->ctx, Error(d->lasterr)); } @@ -1302,7 +1310,7 @@ Error Context::startSigning(const Data &plainText, Data &signature, SignatureMod d->lastop = Private::Sign; const Data::Private *const pdp = plainText.impl(); Data::Private *const sdp = signature.impl(); - return Error(d->lasterr = gpgme_op_sign_start(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigmode2sigmode(mode))); + return Error(d->lasterr = gpgme_op_sign_start(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigflags2sigflags(mode))); } SigningResult Context::signingResult() const @@ -1889,16 +1897,12 @@ std::ostream &operator<<(std::ostream &os, KeyListMode mode) std::ostream &operator<<(std::ostream &os, SignatureMode mode) { os << "GpgME::SignatureMode("; - switch (mode) { -#define CHECK( x ) case x: os << #x; break +#define CHECK( x ) if ( !(mode & (x)) ) {} else do { os << #x " "; } while (0) CHECK(NormalSignatureMode); CHECK(Detached); CHECK(Clearsigned); + CHECK(SignArchive); #undef CHECK - default: - os << "???" "(" << static_cast(mode) << ')'; - break; - } return os << ')'; } diff --git a/lang/cpp/src/global.h b/lang/cpp/src/global.h index 84c8d462..c9c65cdb 100644 --- a/lang/cpp/src/global.h +++ b/lang/cpp/src/global.h @@ -74,7 +74,12 @@ enum KeyListMode { KeyListModeMask = 0x3ff }; -enum SignatureMode { NormalSignatureMode, Detached, Clearsigned }; +enum SignatureMode { + NormalSignatureMode = 0, + Detached = 1, + Clearsigned = 2, + SignArchive = 4, +}; enum class RevocationReason { Unspecified = 0, diff --git a/lang/cpp/src/signingresult.cpp b/lang/cpp/src/signingresult.cpp index 6e0dd90a..06169cbc 100644 --- a/lang/cpp/src/signingresult.cpp +++ b/lang/cpp/src/signingresult.cpp @@ -199,6 +199,7 @@ GpgME::SignatureMode GpgME::CreatedSignature::mode() const case GPGME_SIG_MODE_NORMAL: return NormalSignatureMode; case GPGME_SIG_MODE_DETACH: return Detached; case GPGME_SIG_MODE_CLEAR: return Clearsigned; + case GPGME_SIG_MODE_ARCHIVE: return SignArchive; // cannot happen } }