[git] GPGME - branch, master, updated. gpgme-1.8.0-119-g5493164

by Andre Heinecke cvs at cvs.gnupg.org
Fri Mar 24 17:10:47 CET 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  5493164f8665fabf795f3b34a7084770a38ae940 (commit)
       via  8ad37ecc297f208d0a63783c1ffae33ad4c3c81a (commit)
      from  6ac1f2cdedb085b4ac9372c1e591497e2e618de4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5493164f8665fabf795f3b34a7084770a38ae940
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Mar 24 16:58:58 2017 +0100

    qt: Add unittest for decrypt unwrap
    
    * lang/qt/tests/t-encrypt.cpp
    (EncryptTest::testEncryptDecryptNowrap): New.

diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index ba4a1c5..199517f 100644
--- a/lang/qt/tests/t-encrypt.cpp
+++ b/lang/qt/tests/t-encrypt.cpp
@@ -39,6 +39,8 @@
 #include <QBuffer>
 #include "keylistjob.h"
 #include "encryptjob.h"
+#include "signencryptjob.h"
+#include "signingresult.h"
 #include "qgpgmeencryptjob.h"
 #include "encryptionresult.h"
 #include "decryptionresult.h"
@@ -46,6 +48,7 @@
 #include "qgpgmebackend.h"
 #include "keylistresult.h"
 #include "engineinfo.h"
+#include "verifyopaquejob.h"
 #include "t-support.h"
 
 #define PROGRESS_TEST_SIZE 1 * 1024 * 1024
@@ -109,7 +112,7 @@ private Q_SLOTS:
         auto decJob = new QGpgMEDecryptJob(ctx);
         QByteArray plainText;
         auto decResult = decJob->exec(cipherText, plainText);
-        QVERIFY(!result.error());
+        QVERIFY(!decResult.error());
         QVERIFY(QString::fromUtf8(plainText) == QStringLiteral("Hello World"));
         delete decJob;
     }
@@ -200,6 +203,68 @@ private Q_SLOTS:
         delete decJob;
     }
 
+    void testEncryptDecryptNowrap()
+    {
+        /* Now decrypt */
+        if (!decryptSupported()) {
+            return;
+        }
+        auto listjob = openpgp()->keyListJob(false, false, false);
+        std::vector<Key> keys;
+        auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa at example.net"),
+                                          false, keys);
+        QVERIFY(!keylistresult.error());
+        QVERIFY(keys.size() == 1);
+        delete listjob;
+
+        auto job = openpgp()->signEncryptJob(/*ASCII Armor */true, /* Textmode */ true);
+
+        auto encSignCtx = Job::context(job);
+        TestPassphraseProvider provider1;
+        encSignCtx->setPassphraseProvider(&provider1);
+        encSignCtx->setPinentryMode(Context::PinentryLoopback);
+
+        QVERIFY(job);
+        QByteArray cipherText;
+        auto result = job->exec(keys, keys, QStringLiteral("Hello World").toUtf8(), Context::AlwaysTrust, cipherText);
+        delete job;
+        QVERIFY(!result.first.error());
+        QVERIFY(!result.second.error());
+        const auto cipherString = QString::fromUtf8(cipherText);
+        QVERIFY(cipherString.startsWith("-----BEGIN PGP MESSAGE-----"));
+
+        /* Now decrypt */
+        if (!decryptSupported()) {
+            return;
+        }
+        auto ctx = Context::createForProtocol(OpenPGP);
+        TestPassphraseProvider provider;
+        ctx->setPassphraseProvider(&provider);
+        ctx->setPinentryMode(Context::PinentryLoopback);
+        ctx->setDecryptionFlags(Context::DecryptUnwrap);
+
+        auto decJob = new QGpgMEDecryptJob(ctx);
+        QByteArray plainText;
+        auto decResult = decJob->exec(cipherText, plainText);
+
+        QVERIFY(!decResult.error());
+
+        delete decJob;
+
+        // Now verify the unwrapeped data.
+        auto verifyJob = openpgp()->verifyOpaqueJob(true);
+        QByteArray verified;
+
+        auto verResult = verifyJob->exec(plainText, verified);
+        QVERIFY(!verResult.error());
+        delete verifyJob;
+
+        QVERIFY(verResult.numSignatures() == 1);
+        auto sig = verResult.signatures()[0];
+
+        QVERIFY(verified == QStringLiteral("Hello World"));
+    }
+
 private:
     /* Loopback and passphrase provider don't work for mixed encryption.
      * So this test is disabled until gnupg(?) is fixed for this. */

commit 8ad37ecc297f208d0a63783c1ffae33ad4c3c81a
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Mar 24 16:51:26 2017 +0100

    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.

diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp
index 040e8f3..c20e5a9 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)
diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h
index b075bf1..bec4e39 100644
--- a/lang/cpp/src/context.h
+++ b/lang/cpp/src/context.h
@@ -261,14 +261,28 @@ public:
     //
     // Crypto Operations
     //
-    //
+
+    enum DecryptionFlags {
+        // Keep in line with core's flags
+        DecryptNone = 0,
+        DecryptVerify = 1,
+        DecryptUnwrap = 128,
+        DecryptMaxValue = 0x80000000
+    };
 
     //
     // Decryption
     //
 
+    // Alternative way to set decryption flags as they were added only in
+    // 1.9.0 and so other API can still be used but with 1.9.0 additionally
+    // flags can be set.
+    void setDecryptionFlags (const DecryptionFlags flags);
+
     DecryptionResult decrypt(const Data &cipherText, Data &plainText);
     GpgME::Error startDecryption(const Data &cipherText, Data &plainText);
+    DecryptionResult decrypt(const Data &cipherText, Data &plainText, const DecryptionFlags flags);
+    GpgME::Error startDecryption(const Data &cipherText, Data &plainText, const DecryptionFlags flags);
     DecryptionResult decryptionResult() const;
 
     //
@@ -286,7 +300,9 @@ public:
     //
 
     std::pair<DecryptionResult, VerificationResult> decryptAndVerify(const Data &cipherText, Data &plainText);
+    std::pair<DecryptionResult, VerificationResult> decryptAndVerify(const Data &cipherText, Data &plainText, const DecryptionFlags flags);
     GpgME::Error startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText);
+    GpgME::Error startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText, const DecryptionFlags flags);
     // use verificationResult() and decryptionResult() to retrieve the result objects...
 
     //
@@ -325,7 +341,9 @@ public:
         Prepare = 4,
         ExpectSign = 8,
         NoCompress = 16,
-        Symmetric = 32
+        Symmetric = 32,
+        ThrowKeyIds = 64,
+        EncryptWrap = 128
     };
     EncryptionResult encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags);
     GpgME::Error encryptSymmetrically(const Data &plainText, Data &cipherText);
diff --git a/lang/cpp/src/context_p.h b/lang/cpp/src/context_p.h
index be34783..d53da0a 100644
--- a/lang/cpp/src/context_p.h
+++ b/lang/cpp/src/context_p.h
@@ -77,6 +77,7 @@ public:
     Data lastAssuanInquireData;
     std::unique_ptr<AssuanTransaction> lastAssuanTransaction;
     std::unique_ptr<EditInteractor> lastEditInteractor, lastCardEditInteractor;
+    DecryptionFlags decryptFlags;
 };
 
 } // namespace GpgME

-----------------------------------------------------------------------

Summary of changes:
 lang/cpp/src/context.cpp    | 46 +++++++++++++++++++++++++------
 lang/cpp/src/context.h      | 22 +++++++++++++--
 lang/cpp/src/context_p.h    |  1 +
 lang/qt/tests/t-encrypt.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 124 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list