[git] GPGME - branch, master, updated. gpgme-1.6.0-274-g09667a6

by Andre Heinecke cvs at cvs.gnupg.org
Wed Aug 10 14:15:29 CEST 2016


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  09667a6006986a782af98ca1de4d6521e1b8f353 (commit)
       via  b602d8bc7bd726afb52dc60cc07e4609e88d4511 (commit)
      from  d467018ce36f5be36751267c3b6079e8c1ee5d8a (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 09667a6006986a782af98ca1de4d6521e1b8f353
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Aug 10 14:12:33 2016 +0200

    Cpp: Handle empty recipients consistently
    
    * lang/cpp/src/context.cpp (Context::getKeysFromRecipients):
    New helper.
    (Context::encrypt, Context::startEncryption, Context::signAndEncrypt)
    (Context::startCombinedSigningAndEncryption): Use new helper.
    * lang/cpp/src/context.h (Context::getKeysFromRecipients): Add
    as private helper.
    
    --
    bf776ce was incomplete as the code to handle recpients
    was duplicated four times. This is now unified and constently
    uses a nullptr instead of an empty array.

diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp
index d63573f..1a2741e 100644
--- a/lang/cpp/src/context.cpp
+++ b/lang/cpp/src/context.cpp
@@ -1109,26 +1109,36 @@ static gpgme_encrypt_flags_t encryptflags2encryptflags(Context::EncryptionFlags
     return static_cast<gpgme_encrypt_flags_t>(result);
 }
 
-EncryptionResult Context::encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
+gpgme_key_t *const Context::getKeysFromRecipients(const std::vector<Key> &recipients)
 {
-    d->lastop = Private::Encrypt;
-    if (flags & NoEncryptTo) {
-        return EncryptionResult(Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED)));
+    if (recipients.empty()) {
+        return nullptr;
     }
-    const Data::Private *const pdp = plainText.impl();
-    Data::Private *const cdp = cipherText.impl();
-    gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ];
-    gpgme_key_t *keys_it = keys;
+    gpgme_key_t *ret = new gpgme_key_t[ recipients.size() + 1 ];
+    gpgme_key_t *keys_it = ret;
     for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
         if (it->impl()) {
             *keys_it++ = it->impl();
         }
     }
     *keys_it++ = 0;
-    d->lasterr = gpgme_op_encrypt(d->ctx, recipients.empty() ? nullptr : keys,
-                                  encryptflags2encryptflags(flags),
+    return ret;
+}
+
+EncryptionResult Context::encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
+{
+    d->lastop = Private::Encrypt;
+    if (flags & NoEncryptTo) {
+        return EncryptionResult(Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED)));
+    }
+    const Data::Private *const pdp = plainText.impl();
+    Data::Private *const cdp = cipherText.impl();
+    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
+    d->lasterr = gpgme_op_encrypt(d->ctx, keys, encryptflags2encryptflags(flags),
                                   pdp ? pdp->data : 0, cdp ? cdp->data : 0);
-    delete[] keys;
+    if (keys) {
+        delete[] keys;
+    }
     return EncryptionResult(d->ctx, Error(d->lasterr));
 }
 
@@ -1149,17 +1159,12 @@ Error Context::startEncryption(const std::vector<Key> &recipients, const Data &p
     }
     const Data::Private *const pdp = plainText.impl();
     Data::Private *const cdp = cipherText.impl();
-    gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ];
-    gpgme_key_t *keys_it = keys;
-    for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
-        if (it->impl()) {
-            *keys_it++ = it->impl();
-        }
-    }
-    *keys_it++ = 0;
+    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
     d->lasterr = gpgme_op_encrypt_start(d->ctx, keys, encryptflags2encryptflags(flags),
                                         pdp ? pdp->data : 0, cdp ? cdp->data : 0);
-    delete[] keys;
+    if (keys) {
+        delete[] keys;
+    }
     return Error(d->lasterr);
 }
 
@@ -1177,17 +1182,12 @@ std::pair<SigningResult, EncryptionResult> Context::signAndEncrypt(const std::ve
     d->lastop = Private::SignAndEncrypt;
     const Data::Private *const pdp = plainText.impl();
     Data::Private *const cdp = cipherText.impl();
-    gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ];
-    gpgme_key_t *keys_it = keys;
-    for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
-        if (it->impl()) {
-            *keys_it++ = it->impl();
-        }
-    }
-    *keys_it++ = 0;
+    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
     d->lasterr = gpgme_op_encrypt_sign(d->ctx, keys, encryptflags2encryptflags(flags),
                                        pdp ? pdp->data : 0, cdp ? cdp->data : 0);
-    delete[] keys;
+    if (keys) {
+        delete[] keys;
+    }
     return std::make_pair(SigningResult(d->ctx, Error(d->lasterr)),
                           EncryptionResult(d->ctx, Error(d->lasterr)));
 }
@@ -1197,17 +1197,12 @@ Error Context::startCombinedSigningAndEncryption(const std::vector<Key> &recipie
     d->lastop = Private::SignAndEncrypt;
     const Data::Private *const pdp = plainText.impl();
     Data::Private *const cdp = cipherText.impl();
-    gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ];
-    gpgme_key_t *keys_it = keys;
-    for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
-        if (it->impl()) {
-            *keys_it++ = it->impl();
-        }
-    }
-    *keys_it++ = 0;
+    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
     d->lasterr = gpgme_op_encrypt_sign_start(d->ctx, keys, encryptflags2encryptflags(flags),
                  pdp ? pdp->data : 0, cdp ? cdp->data : 0);
-    delete[] keys;
+    if (keys) {
+        delete[] keys;
+    }
     return Error(d->lasterr);
 }
 
diff --git a/lang/cpp/src/context.h b/lang/cpp/src/context.h
index 70ab079..7d7f53a 100644
--- a/lang/cpp/src/context.h
+++ b/lang/cpp/src/context.h
@@ -369,6 +369,11 @@ public:
         return d;
     }
 private:
+    // Helper functions that need to be context because they rely
+    // on the "Friendlyness" of context to access the gpgme types.
+    gpgme_key_t *const getKeysFromRecipients(const std::vector<Key> &recipients);
+
+private:
     Private *const d;
 
 private: // disable...

commit b602d8bc7bd726afb52dc60cc07e4609e88d4511
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Aug 10 14:01:38 2016 +0200

    core: Handle ENCRYPT_SYMMETRIC also for sig & enc
    
    * src/engine-gpg.c (gpg_encrypt_sign): Handle ENCRYPT_SYMMETRIC
    flag.

diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 4fad977..efab80a 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -1782,10 +1782,13 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[],
 		  gpgme_ctx_t ctx /* FIXME */)
 {
   engine_gpg_t gpg = engine;
-  gpgme_error_t err;
-  int symmetric = !recp;
+  gpgme_error_t err = 0;
+
+  if (recp)
+    err = add_arg (gpg, "--encrypt");
 
-  err = add_arg (gpg, symmetric ? "--symmetric" : "--encrypt");
+  if (!err && ((flags & GPGME_ENCRYPT_SYMMETRIC) || !recp))
+    err = add_arg (gpg, "--symmetric");
 
   if (!err)
     err = add_arg (gpg, "--sign");
@@ -1799,7 +1802,7 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[],
       && have_gpg_version (gpg, "2.1.14"))
     err = add_arg (gpg, "--mimemode");
 
-  if (!symmetric)
+  if (recp)
     {
       /* If we know that all recipients are valid (full or ultimate trust)
 	 we can suppress further checks.  */

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

Summary of changes:
 lang/cpp/src/context.cpp | 71 ++++++++++++++++++++++--------------------------
 lang/cpp/src/context.h   |  5 ++++
 src/engine-gpg.c         | 11 +++++---
 3 files changed, 45 insertions(+), 42 deletions(-)


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




More information about the Gnupg-commits mailing list