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
This commit is contained in:
parent
48b11f5762
commit
2faa031af2
@ -1278,14 +1278,22 @@ std::vector<Notation> Context::signatureNotations() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpgme_sig_mode_t sigmode2sigmode(SignatureMode mode)
|
static gpgme_sig_mode_t sigflags2sigflags(SignatureMode flags)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
unsigned int result = 0;
|
||||||
default:
|
if (flags & SignatureMode::NormalSignatureMode) {
|
||||||
case NormalSignatureMode: return GPGME_SIG_MODE_NORMAL;
|
result |= GPGME_SIG_MODE_NORMAL;
|
||||||
case Detached: return GPGME_SIG_MODE_DETACH;
|
|
||||||
case Clearsigned: return GPGME_SIG_MODE_CLEAR;
|
|
||||||
}
|
}
|
||||||
|
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<gpgme_sig_mode_t>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SigningResult Context::sign(const Data &plainText, Data &signature, SignatureMode mode)
|
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;
|
d->lastop = Private::Sign;
|
||||||
const Data::Private *const pdp = plainText.impl();
|
const Data::Private *const pdp = plainText.impl();
|
||||||
Data::Private *const sdp = signature.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));
|
return SigningResult(d->ctx, Error(d->lasterr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1310,7 @@ Error Context::startSigning(const Data &plainText, Data &signature, SignatureMod
|
|||||||
d->lastop = Private::Sign;
|
d->lastop = Private::Sign;
|
||||||
const Data::Private *const pdp = plainText.impl();
|
const Data::Private *const pdp = plainText.impl();
|
||||||
Data::Private *const sdp = signature.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
|
SigningResult Context::signingResult() const
|
||||||
@ -1889,16 +1897,12 @@ std::ostream &operator<<(std::ostream &os, KeyListMode mode)
|
|||||||
std::ostream &operator<<(std::ostream &os, SignatureMode mode)
|
std::ostream &operator<<(std::ostream &os, SignatureMode mode)
|
||||||
{
|
{
|
||||||
os << "GpgME::SignatureMode(";
|
os << "GpgME::SignatureMode(";
|
||||||
switch (mode) {
|
#define CHECK( x ) if ( !(mode & (x)) ) {} else do { os << #x " "; } while (0)
|
||||||
#define CHECK( x ) case x: os << #x; break
|
|
||||||
CHECK(NormalSignatureMode);
|
CHECK(NormalSignatureMode);
|
||||||
CHECK(Detached);
|
CHECK(Detached);
|
||||||
CHECK(Clearsigned);
|
CHECK(Clearsigned);
|
||||||
|
CHECK(SignArchive);
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
default:
|
|
||||||
os << "???" "(" << static_cast<int>(mode) << ')';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return os << ')';
|
return os << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,12 @@ enum KeyListMode {
|
|||||||
KeyListModeMask = 0x3ff
|
KeyListModeMask = 0x3ff
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SignatureMode { NormalSignatureMode, Detached, Clearsigned };
|
enum SignatureMode {
|
||||||
|
NormalSignatureMode = 0,
|
||||||
|
Detached = 1,
|
||||||
|
Clearsigned = 2,
|
||||||
|
SignArchive = 4,
|
||||||
|
};
|
||||||
|
|
||||||
enum class RevocationReason {
|
enum class RevocationReason {
|
||||||
Unspecified = 0,
|
Unspecified = 0,
|
||||||
|
@ -199,6 +199,7 @@ GpgME::SignatureMode GpgME::CreatedSignature::mode() const
|
|||||||
case GPGME_SIG_MODE_NORMAL: return NormalSignatureMode;
|
case GPGME_SIG_MODE_NORMAL: return NormalSignatureMode;
|
||||||
case GPGME_SIG_MODE_DETACH: return Detached;
|
case GPGME_SIG_MODE_DETACH: return Detached;
|
||||||
case GPGME_SIG_MODE_CLEAR: return Clearsigned;
|
case GPGME_SIG_MODE_CLEAR: return Clearsigned;
|
||||||
|
case GPGME_SIG_MODE_ARCHIVE: return SignArchive; // cannot happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user