From d28ea8c6b3db008150e2bae99a33e30b55c4bc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Fri, 27 Jan 2023 09:40:05 +0100 Subject: cpp: Support new archive encryption flag * lang/cpp/src/context.h (EncryptArchive): New flag. * lang/cpp/src/context.cpp (encryptflags2encryptflags): Convert EncryptArchive to corresponding gpgme encrypt flags. (operator<<): Add new flag to debug stream. -- GnuPG-bug-id: 6342 --- lang/cpp/src/context.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lang/cpp/src/context.cpp') diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index dba958cf..f7f6f54d 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -1335,6 +1335,9 @@ static gpgme_encrypt_flags_t encryptflags2encryptflags(Context::EncryptionFlags if (flags & Context::Symmetric) { result |= GPGME_ENCRYPT_SYMMETRIC; } + if (flags & Context::EncryptArchive) { + result |= GPGME_ENCRYPT_ARCHIVE; + } return static_cast(result); } @@ -1909,6 +1912,7 @@ std::ostream &operator<<(std::ostream &os, Context::EncryptionFlags flags) CHECK(ExpectSign); CHECK(NoCompress); CHECK(Symmetric); + CHECK(EncryptArchive); #undef CHECK return os << ')'; } -- cgit v1.2.3 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: 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 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'lang/cpp/src/context.cpp') 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 << ')'; } -- cgit v1.2.3