diff options
| author | Andre Heinecke <[email protected]> | 2017-03-24 15:51:26 +0000 | 
|---|---|---|
| committer | Andre Heinecke <[email protected]> | 2017-03-24 15:51:26 +0000 | 
| commit | 8ad37ecc297f208d0a63783c1ffae33ad4c3c81a (patch) | |
| tree | 08a3b041489b7eefbac38185d885080dd93b52b3 /lang/cpp/src/context.cpp | |
| parent | core: New flags GPGME_DECRYPT_UNWRAP and GPGME_ENCRYPT_WRAP. (diff) | |
| download | gpgme-8ad37ecc297f208d0a63783c1ffae33ad4c3c81a.tar.gz gpgme-8ad37ecc297f208d0a63783c1ffae33ad4c3c81a.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | lang/cpp/src/context.cpp | 46 | 
1 files changed, 37 insertions, 9 deletions
| 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> Context::createForEngine(Engine eng, Error *error)      return std::unique_ptr<Context>(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<AssuanTransaction> 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<gpgme_decrypt_flags_t> (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<gpgme_decrypt_flags_t> (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<DecryptionResult, VerificationResult> Context::decryptAndVerify(const Data &cipherText, Data &plainText) +std::pair<DecryptionResult, VerificationResult> 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<gpgme_decrypt_flags_t> (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<DecryptionResult, VerificationResult> 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<gpgme_decrypt_flags_t> (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) | 
