[git] GPGME - branch, master, updated. gpgme-1.11.1-231-g24a0005

by Maximilian Krambach cvs at cvs.gnupg.org
Wed Aug 22 19:08:04 CEST 2018


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  24a00058652233775cbe51446cba337b70cefdf1 (commit)
      from  f0409bbdafcbd4f8b0be099a6b3ce0d5352c9bcd (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 24a00058652233775cbe51446cba337b70cefdf1
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Wed Aug 22 19:07:05 2018 +0200

    js: add decrypt result options
    
    --
    
    * As a decrypt result cannot be known beforehand, the decrypt operation
      may add an 'expect' property, taking either 'uint8' or 'base64',
      which will return the decrypted data in the appropiate formats.
      the return property 'format' will give a feedback on which option
      was taken.
      A test was added to reflect these changes.

diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
index 1efdf5c..c10c5d0 100644
--- a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
@@ -144,6 +144,30 @@ describe('Encryption and Decryption', function (){
             });
     }).timeout(3000);
 
+    it('Random data, original data is and should stay base64 encoded',
+        function (done) {
+            let data = bigBoringString(0.001);
+            let b64data = btoa(data);
+            context.encrypt(
+                { data: b64data, publicKeys: good_fpr })
+                .then(function (answer) {
+                    expect(answer).to.not.be.empty;
+                    expect(answer.data).to.be.a('string');
+                    expect(answer.data).to.include(
+                        'BEGIN PGP MESSAGE');
+                    expect(answer.data).to.include(
+                        'END PGP MESSAGE');
+                    context.decrypt({
+                        data:answer.data, expect: 'base64' })
+                        .then(function (result) {
+                            expect(result).to.not.be.empty;
+                            expect(result.data).to.be.a('string');
+                            expect(result.data).to.equal(b64data);
+                            done();
+                        });
+                });
+    }).timeout(3000);
+
     for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
         it('Roundtrip with >1MB non-ascii input meeting default chunksize (' +
             (j + 1) + '/'
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 8756cce..3fd1810 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -266,13 +266,16 @@ class Answer{
                 if (_decodedResponse.base64 === true
                     && poa.data[key] === 'string'
                 ) {
-                    if (this.expected === 'binary'){
+                    if (this.expected === 'uint8'){
                         _response[key] = atobArray(_decodedResponse[key]);
-                        _response.binary = true;
+                        _response.format = 'uint8';
+                    } else if (this.expected === 'base64'){
+                        _response[key] = _decodedResponse[key];
+                        _response.format = 'base64';
                     } else {
                         _response[key] = Utf8ArrayToStr(
                             atobArray(_decodedResponse[key]));
-                        _response.binary = false;
+                        _response.format = 'string';
                     }
                 } else {
                     _response[key] = decode(_decodedResponse[key]);
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index 48813df..fff20fb 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -64,7 +64,7 @@ export class GPGME_Message {
     }
 
     set expected (value){
-        if (value === 'binary'){
+        if (value === 'uint8' || value === 'base64'){
             this._expected = value;
         }
     }
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index e039842..ac64030 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -31,7 +31,11 @@ import { createSignature } from './Signature';
 /**
  * @typedef {Object} decrypt_result
  * @property {String|Uint8Array} data The decrypted data
- * @property {Boolean} binary indicating whether data is an Uint8Array.
+ * @property {String} format Indicating how the data was converted after being
+ * received from gpgme.
+ *      'string': Data was decoded into an utf-8 string,
+ *      'base64': Data was not processed and is a base64 string
+ *      'uint8': data was turned into a Uint8Array
  * @property {Boolean} is_mime (optional) the data claims to be a MIME
  * object.
  * @property {String} file_name (optional) the original file name
@@ -51,8 +55,8 @@ import { createSignature } from './Signature';
 /**
  * @typedef {Object} encrypt_result The result of an encrypt operation
  * @property {String} data The encrypted message
- * @property {Boolean} binary Indicating whether returning payload data is an
- * Uint8Array.
+ * @property {Boolean} base64 Indicating whether returning payload data is
+ * base64 encoded
  */
 
 /**
@@ -187,8 +191,9 @@ export class GpgME {
     * Strings and Objects with a getText method
     * @param {Boolean} options.base64 (optional) false if the data is an
     * armored block, true if it is base64 encoded binary data
-    * @param {Boolean} options.binary (optional) if true, treat the decoded
-    * data as binary, and return the data as Uint8Array
+    * @param {String} options.expect (optional) can be set to 'uint8' or
+    * 'base64'. Does no extra decoding on the data, and returns the decoded
+    * data as either Uint8Array or unprocessed(base64 encoded) string.
     * @returns {Promise<decrypt_result>} Decrypted Message and information
     * @async
     */
@@ -207,14 +212,14 @@ export class GpgME {
         if (options.base64 === true){
             msg.setParameter('base64', true);
         }
-        if (options.binary === true){
-            msg.expected = 'binary';
+        if (options.expect === 'base64' || options.expect === 'uint8'){
+            msg.expected = options.expect;
         }
         putData(msg, options.data);
         return new Promise(function (resolve, reject){
             msg.post().then(function (result){
                 let _result = { data: result.data };
-                _result.binary = result.binary ? true: false;
+                _result.format = result.format ? result.format : null;
                 if (result.hasOwnProperty('dec_info')){
                     _result.is_mime = result.dec_info.is_mime ? true: false;
                     if (result.dec_info.file_name) {

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

Summary of changes:
 .../tests/encryptDecryptTest.js                    | 24 ++++++++++++++++++++++
 lang/js/src/Connection.js                          |  9 +++++---
 lang/js/src/Message.js                             |  2 +-
 lang/js/src/gpgmejs.js                             | 21 +++++++++++--------
 4 files changed, 44 insertions(+), 12 deletions(-)


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




More information about the Gnupg-commits mailing list