[git] GPGME - branch, master, updated. gpgme-1.11.1-260-ga986371

by Maximilian Krambach cvs at cvs.gnupg.org
Thu Aug 30 12:07:10 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  a9863717b1b82b3077edd0db85454ba801eac9bd (commit)
      from  1d00fb987b903e245d484bddfe3c0a0aba670ac1 (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 a9863717b1b82b3077edd0db85454ba801eac9bd
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Thu Aug 30 12:04:50 2018 +0200

    js: separate gpgme answer by type of data
    
    --
    
    * src/Connection.js; src/permittedOperations.js: To avoid further
      encoding problems, data sent by gpgme is now sorted  as either
      'payload' or 'info'. Payload data may come in any encoding, and here
      the 'expected' and 'format' options are used, 'info' data may
      contain text created by gnupg which may need re-encoding, but this
      should not be affected by 'expected' and 'format'

diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index c4921d5..a421985 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -243,7 +243,7 @@ class Answer{
         for (let i= 0; i < messageKeys.length; i++){
             let key = messageKeys[i];
             switch (key) {
-            case 'type':
+            case 'type': {
                 if (_decodedResponse.type === 'error'){
                     return (gpgme_error('GNUPG_ERROR',
                         decode(_decodedResponse.msg)));
@@ -251,39 +251,60 @@ class Answer{
                     return gpgme_error('CONN_UNEXPECTED_ANSWER');
                 }
                 break;
-            case 'base64':
+            }
+            case 'base64': {
                 break;
-            case 'msg':
+            }
+            case 'msg': {
                 if (_decodedResponse.type === 'error'){
                     return (gpgme_error('GNUPG_ERROR', _decodedResponse.msg));
                 }
                 break;
-            default:
-                if (!poa.data.hasOwnProperty(key)){
-                    return gpgme_error('CONN_UNEXPECTED_ANSWER');
+            }
+            default: {
+                let answerType = null;
+                if (poa.payload && poa.payload.hasOwnProperty(key)){
+                    answerType = 'p';
+                } else if (poa.info && poa.info.hasOwnProperty(key)){
+                    answerType = 'i';
                 }
-                if ( typeof (_decodedResponse[key]) !== poa.data[key] ){
+                if (answerType !== 'p' && answerType !== 'i'){
                     return gpgme_error('CONN_UNEXPECTED_ANSWER');
                 }
-                if (_decodedResponse.base64 === true
-                    && poa.data[key] === 'string'
-                ) {
-                    if (this.expected === 'uint8'){
-                        _response[key] = atobArray(_decodedResponse[key]);
-                        _response.format = 'uint8';
-                    } else if (this.expected === 'base64'){
+
+                if (answerType === 'i') {
+                    if ( typeof (_decodedResponse[key]) !== poa.info[key] ){
+                        return gpgme_error('CONN_UNEXPECTED_ANSWER');
+                    }
+                    _response[key] = decode(_decodedResponse[key]);
+
+                } else if (answerType === 'p') {
+                    if (_decodedResponse.base64 === true
+                        && poa.payload[key] === 'string'
+                    ) {
+                        if (this.expected === 'uint8'){
+                            _response[key] = atobArray(_decodedResponse[key]);
+                            _response.format = 'uint8';
+
+                        } else if (this.expected === 'base64'){
+                            _response[key] = _decodedResponse[key];
+                            _response.format = 'base64';
+
+                        } else { // no 'expected'
+                            _response[key] = Utf8ArrayToStr(
+                                atobArray(_decodedResponse[key]));
+                            _response.format = 'string';
+                        }
+                    } else if (poa.payload[key] === 'string') {
                         _response[key] = _decodedResponse[key];
-                        _response.format = 'base64';
                     } else {
-                        _response[key] = Utf8ArrayToStr(
-                            atobArray(_decodedResponse[key]));
-                        _response.format = 'string';
+                        // fallthrough, should not be reached
+                        // (payload is always string)
+                        return gpgme_error('CONN_UNEXPECTED_ANSWER');
                     }
-                } else {
-                    _response[key] = decode(_decodedResponse[key]);
                 }
                 break;
-            }
+            } }
         }
         return _response;
     }
diff --git a/lang/js/src/permittedOperations.js b/lang/js/src/permittedOperations.js
index efb34f9..c3c72ca 100644
--- a/lang/js/src/permittedOperations.js
+++ b/lang/js/src/permittedOperations.js
@@ -42,8 +42,12 @@
  * @property {Object} answer The definition on what to expect as answer, if the
  *      answer is not an error
  * @property {Array<String>} answer.type the type(s) as reported by gpgme-json.
- * @property {Object} answer.data key-value combinations of expected properties
- * of an answer and their type ('boolean', 'string', object)
+ * @property {Object} answer.payload key-value combinations of expected
+ * properties of an answer and their type ('boolean', 'string', object), which
+ * may need further decoding from base64
+ * @property {Object} answer.info key-value combinations of expected
+ * properties of an answer and their type ('boolean', 'string', object), which
+ * are meant to be data directly sent by gpgme (i.e. user ids)
   @const
 */
 export const permittedOperations = {
@@ -104,8 +108,10 @@ export const permittedOperations = {
         },
         answer: {
             type: ['ciphertext'],
-            data: {
-                'data': 'string',
+            payload: {
+                'data': 'string'
+            },
+            info: {
                 'base64':'boolean'
             }
         }
@@ -129,8 +135,10 @@ export const permittedOperations = {
         },
         answer: {
             type: ['plaintext'],
-            data: {
+            payload: {
                 'data': 'string',
+            },
+            info: {
                 'base64': 'boolean',
                 'mime': 'boolean',
                 'info': 'object',
@@ -171,11 +179,12 @@ export const permittedOperations = {
         },
         answer: {
             type: ['signature', 'ciphertext'],
-            data: {
+            payload: {
                 'data': 'string',
+            },
+            info: {
                 'base64':'boolean'
             }
-
         }
     },
 
@@ -223,9 +232,9 @@ export const permittedOperations = {
         },
         answer: {
             type: ['keys'],
-            data: {
+            info: {
+                'keys': 'object',
                 'base64': 'boolean',
-                'keys': 'object'
             }
         }
     },
@@ -263,8 +272,10 @@ export const permittedOperations = {
         },
         answer: {
             type: ['keys'],
-            data: {
+            payload: {
                 'data': 'string',
+            },
+            info: {
                 'base64': 'boolean',
                 'sec-fprs': 'object'
             }
@@ -288,7 +299,7 @@ export const permittedOperations = {
         },
         answer: {
             type: [],
-            data: {
+            info: {
                 'result': 'object'
             }
         }
@@ -308,7 +319,7 @@ export const permittedOperations = {
             },
         },
         answer: {
-            data: {
+            info: {
                 'success': 'boolean'
             }
         }
@@ -319,7 +330,7 @@ export const permittedOperations = {
         optional: {},
         answer: {
             type:  [''],
-            data: {
+            info: {
                 'gpgme': 'string',
                 'info': 'object'
             }
@@ -346,7 +357,7 @@ export const permittedOperations = {
         },
         answer: {
             type: [''],
-            data: { 'fingerprint': 'string' }
+            info: { 'fingerprint': 'string' }
         }
     },
 
@@ -370,10 +381,12 @@ export const permittedOperations = {
         },
         answer: {
             type: ['plaintext'],
-            data:{
-                data: 'string',
-                base64:'boolean',
-                info: 'object'
+            payload:{
+                'data': 'string'
+            },
+            info: {
+                'base64':'boolean',
+                'info': 'object'
                 // info.file_name: Optional string of the plaintext file name.
                 // info.is_mime: Boolean if the messages claims it is MIME.
                 // info.signatures: Array of signatures
@@ -395,15 +408,9 @@ export const permittedOperations = {
         optional: {},
         answer: {
             type: [],
-            data: {
-                option: 'object'
+            info: {
+                'option': 'object'
             }
         }
     }
-
-    /**
-     * TBD handling of secrets
-     * TBD key modification?
-     */
-
 };

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

Summary of changes:
 lang/js/src/Connection.js          | 63 +++++++++++++++++++++++++-------------
 lang/js/src/permittedOperations.js | 59 +++++++++++++++++++----------------
 2 files changed, 75 insertions(+), 47 deletions(-)


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




More information about the Gnupg-commits mailing list