[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-12-g5befa1c

by Maximilian Krambach cvs at cvs.gnupg.org
Wed Apr 25 11:32:55 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, javascript-binding has been updated
       via  5befa1c9751fe54b5ae87906d7f09772ce9de6ea (commit)
      from  c72adc00965fe4fcedd9d18609211021a091b28b (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 5befa1c9751fe54b5ae87906d7f09772ce9de6ea
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Wed Apr 25 11:32:21 2018 +0200

    js: reactivate timeout on connection
    
    --
    * A timeout of 5 seconds is activated for functions that do not require
      a pinentry. This definition is written to src/permittedOperations.js
    * testapplication.js now alerts the proper error codes and messages.
    * src/Errors.js fixed two typos in error handling

diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 8bc3d42..4270be5 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -118,14 +118,18 @@ export class Connection{
             };
 
             me._connection.onMessage.addListener(listener);
-            me._connection.postMessage(message.message);
-
-            //TBD: needs to be aware if there is a pinentry pending
-            // setTimeout(
-            //     function(){
-            //         me.disconnect();
-            //         reject(GPGMEJS_Error('CONN_TIMEOUT'));
-            //     }, timeout);
+            let timeout = new Promise(function(resolve, reject){
+                setTimeout(function(){
+                    reject(GPGMEJS_Error('CONN_TIMEOUT'));
+                }, 5000);
+            });
+            if (permittedOperations[message.operation].pinentry){
+                return me._connection.postMessage(message.message);
+            } else {
+                return Promise.race([timeout,
+                    me._connection.postMessage(message.message)
+                ]);
+            }
         });
      }
 };
diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js
index c49bfe2..04b13e1 100644
--- a/lang/js/src/Errors.js
+++ b/lang/js/src/Errors.js
@@ -104,12 +104,12 @@ export function GPGMEJS_Error(code = 'GENERIC_ERROR'){
         if (errors.hasOwnProperty(code)){
             code = 'GENERIC_ERROR';
         }
-        if (error.type === 'error'){
+        if (errors.type === 'error'){
             return {code: 'code',
                     msg: errors[code].msg
                 };
         }
-        if (error.type === 'warning'){
+        if (errors.type === 'warning'){
             console.log(code + ': ' + error[code].msg);
         }
         return undefined;
diff --git a/lang/js/src/permittedOperations.js b/lang/js/src/permittedOperations.js
index 3c11b8e..892f4f2 100644
--- a/lang/js/src/permittedOperations.js
+++ b/lang/js/src/permittedOperations.js
@@ -23,6 +23,8 @@
   * operation: <Object>
       required: Array<String>
       optional: Array<String>
+      pinentry: Boolean If a pinentry dialog is expected, and a timeout of
+                5000 ms would be too short
       answer: <Object>
           type: <String< The content type of answer expected
           data: Array<String> The payload property of the answer. May be
@@ -59,6 +61,7 @@ export const permittedOperations = {
     },
 
     decrypt: {
+        pinentry: true,
         required: ['data'],
         optional: [
             'protocol',
diff --git a/lang/js/testapplication.js b/lang/js/testapplication.js
index f47299e..b2cb4c2 100644
--- a/lang/js/testapplication.js
+++ b/lang/js/testapplication.js
@@ -33,7 +33,7 @@ document.addEventListener('DOMContentLoaded', function() {
                         document.getElementById('answer').value = answer.data;
                         }
                     }, function(errormsg){
-                        alert('Error: '+ errormsg);
+                        alert( errormsg.code + ' ' + errormsg.msg);
                 });
             });
 
@@ -47,7 +47,7 @@ document.addEventListener('DOMContentLoaded', function() {
                         document.getElementById('answer').value = answer.data;
                     }
                 }, function(errormsg){
-                    alert('Error: '+ errormsg);
+                    alert( errormsg.code + ' ' + errormsg.msg);
             });
         });
     },

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

Summary of changes:
 lang/js/src/Connection.js          | 20 ++++++++++++--------
 lang/js/src/Errors.js              |  4 ++--
 lang/js/src/permittedOperations.js |  3 +++
 lang/js/testapplication.js         |  4 ++--
 4 files changed, 19 insertions(+), 12 deletions(-)


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




More information about the Gnupg-commits mailing list