[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-7-g727340b

by Maximilian Krambach cvs at cvs.gnupg.org
Mon Apr 23 19:20:01 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  727340b295f25e04cb595022ba143cda48364697 (commit)
      from  d62f66b1fb47f2075770d896f672748a4136e70b (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 727340b295f25e04cb595022ba143cda48364697
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Mon Apr 23 19:15:40 2018 +0200

    js: don't allow message operation changes
    
    --
    
    Once an operation is changed, their set of allowed/required parameters
    will change. So we shouldn't set/change the operation later.

diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js
index 52fa7f7..d8cb84b 100644
--- a/lang/js/src/Keyring.js
+++ b/lang/js/src/Keyring.js
@@ -49,8 +49,7 @@ export class GPGME_Keyring {
      *
      */
     getKeys(pattern, include_secret){
-        let msg = new GPGME_Message;
-        msg.operation = 'listkeys';
+        let msg = new GPGME_Message('listkeys');
         if (pattern && typeof(pattern) === 'string'){
             msg.setParameter('pattern', pattern);
         }
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index 6a93b6f..f5e21e0 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -23,28 +23,7 @@ export class GPGME_Message {
     //TODO getter
 
     constructor(operation){
-        if (operation){
-            this.operation(operation);
-        }
-    }
-
-    /**
-     * Defines the operation this message will have
-     * @param {String} operation Must be defined in permittedOperations
-     *  TODO: move to constructor?
-     */
-    set operation (operation){
-        if (!operation || typeof(operation) !== 'string'){
-            return new GPGMEJS_Error('WRONGPARAM');
-        }
-        if (operation in permittedOperations){
-            if (!this._msg){
-                this._msg = {};
-            }
-            this._msg.op = operation;
-        } else {
-            return new GPGMEJS_Error('WRONG_OP');
-        }
+        setOperation(this, operation);
     }
 
     get operation(){
@@ -110,4 +89,23 @@ export class GPGME_Message {
         }
 
     }
+}
+
+/**
+ * Defines the operation this message will have
+ * @param {String} operation Must be defined in permittedOperations
+ *  TODO: move to constructor?
+ */
+function setOperation (scope, operation){
+    if (!operation || typeof(operation) !== 'string'){
+        return new GPGMEJS_Error('WRONGTYPE');
+    }
+    if (permittedOperations.hasOwnProperty(operation)){
+        if (!scope._msg){
+            scope._msg = {};
+        }
+        scope._msg.op = operation;
+    } else {
+        return new GPGMEJS_Error('WRONG_OP');
+    }
 }
\ No newline at end of file
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index c23a356..b15477f 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -76,8 +76,7 @@ export class GpgME {
      */
     encrypt (data, publicKeys, wildcard=false){
 
-        let msg = new GPGME_Message;
-        msg.operation = 'encrypt';
+        let msg = new GPGME_Message('encrypt');
 
         // TODO temporary
         msg.setParameter('armor', true);
@@ -108,8 +107,7 @@ export class GpgME {
         if (data === undefined){
             return Promise.reject(new GPGMEJS_Error ('EMPTY_MSG'));
         }
-        let msg = new GPGME_Message;
-        msg.operation = 'decrypt';
+        let msg = new GPGME_Message('decrypt');
         putData(msg, data);
         return this._connection.post(msg);
 
@@ -117,8 +115,7 @@ export class GpgME {
 
     deleteKey(key, delete_secret = false, no_confirm = false){
         return Promise.reject(new GPGMEJS_Error ('NOT_YET_IMPLEMENTED'));
-        let msg = new GPGME_Message;
-        msg.operation = 'deletekey';
+        let msg = new GPGME_Message('deletekey');
         let key_arr = toKeyIdArray(key);
         if (key_arr.length !== 1){
             throw('TODO');

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

Summary of changes:
 lang/js/src/Keyring.js |  3 +--
 lang/js/src/Message.js | 42 ++++++++++++++++++++----------------------
 lang/js/src/gpgmejs.js |  9 +++------
 3 files changed, 24 insertions(+), 30 deletions(-)


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




More information about the Gnupg-commits mailing list