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 } }