From 8ad37ecc297f208d0a63783c1ffae33ad4c3c81a Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Fri, 24 Mar 2017 16:51:26 +0100 Subject: cpp: Use gpgme_op_decrypt_ex and add new flags. * lang/cpp/src/context.cpp: New decrypt and decryptVerify functions that take flags as arguments. Use new variants in old functions. (Context::setDecryptionFlags): New helper. (Context::Private::Private): Initialize new member. * lang/cpp/src/context_p.h (Context::Private::decryptFlags): New. * lang/cpp/src/context.h (Context::DecryptFlags): New enum. (Context::EncryptionFlags): Extend for EncryptWrap. -- The setDecryptionFlags provides a generic way to set decryption flags for the whole context. This allows existing code to just keep using the old functions and modify the decryption behavior in a central place. --- lang/cpp/src/context.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'lang/cpp/src/context.cpp') diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index 040e8f32..c20e5a9d 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -280,6 +280,11 @@ std::unique_ptr Context::createForEngine(Engine eng, Error *error) return std::unique_ptr(new Context(ctx)); } +void Context::setDecryptionFlags(DecryptionFlags flags) +{ + d->decryptFlags = flags; +} + // // // Context::Private @@ -294,7 +299,8 @@ Context::Private::Private(gpgme_ctx_t c) lastAssuanInquireData(Data::null), lastAssuanTransaction(), lastEditInteractor(), - lastCardEditInteractor() + lastCardEditInteractor(), + decryptFlags(DecryptNone) { } @@ -904,21 +910,32 @@ std::unique_ptr Context::takeLastAssuanTransaction() return std::move(d->lastAssuanTransaction); } -DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText) +DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText, const DecryptionFlags flags) { d->lastop = Private::Decrypt; const Data::Private *const cdp = cipherText.impl(); Data::Private *const pdp = plainText.impl(); - d->lasterr = gpgme_op_decrypt(d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0); + d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast (d->decryptFlags), cdp ? cdp->data : 0, pdp ? pdp->data : 0); return DecryptionResult(d->ctx, Error(d->lasterr)); } -Error Context::startDecryption(const Data &cipherText, Data &plainText) +DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText) +{ + return decrypt(cipherText, plainText, DecryptNone); +} + +Error Context::startDecryption(const Data &cipherText, Data &plainText, const DecryptionFlags flags) { d->lastop = Private::Decrypt; const Data::Private *const cdp = cipherText.impl(); Data::Private *const pdp = plainText.impl(); - return Error(d->lasterr = gpgme_op_decrypt_start(d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0)); + return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast (d->decryptFlags), + cdp ? cdp->data : 0, pdp ? pdp->data : 0)); +} + +Error Context::startDecryption(const Data &cipherText, Data &plainText) +{ + return startDecryption(cipherText, plainText, DecryptNone); } DecryptionResult Context::decryptionResult() const @@ -973,22 +990,33 @@ VerificationResult Context::verificationResult() const } } -std::pair Context::decryptAndVerify(const Data &cipherText, Data &plainText) +std::pair Context::decryptAndVerify(const Data &cipherText, Data &plainText, DecryptionFlags flags) { d->lastop = Private::DecryptAndVerify; const Data::Private *const cdp = cipherText.impl(); Data::Private *const pdp = plainText.impl(); - d->lasterr = gpgme_op_decrypt_verify(d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0); + d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast (d->decryptFlags | DecryptVerify), + cdp ? cdp->data : 0, pdp ? pdp->data : 0); return std::make_pair(DecryptionResult(d->ctx, Error(d->lasterr)), VerificationResult(d->ctx, Error(d->lasterr))); } -Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText) +std::pair Context::decryptAndVerify(const Data &cipherText, Data &plainText) +{ + return decryptAndVerify(cipherText, plainText, DecryptNone); +} + +Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText, DecryptionFlags flags) { d->lastop = Private::DecryptAndVerify; const Data::Private *const cdp = cipherText.impl(); Data::Private *const pdp = plainText.impl(); - return Error(d->lasterr = gpgme_op_decrypt_verify_start(d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0)); + return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast (d->decryptFlags | DecryptVerify), cdp ? cdp->data : 0, pdp ? pdp->data : 0)); +} + +Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText) +{ + return startCombinedDecryptionAndVerification(cipherText, plainText, DecryptNone); } unsigned int to_auditlog_flags(unsigned int flags) -- cgit v1.2.3