[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-63-g780f788

[email protected] (by Maximilian Krambach)
Newsgroups gmane.comp.encryption.gpg.cvs
Message-ID <[email protected]>
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  780f7880c6598d4532354b348d7bd74026d162f4 (commit)
      from  3cd428ba442f43e470b977e27e18ff52567baba5 (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 780f7880c6598d4532354b348d7bd74026d162f4
Author: Maximilian Krambach <[email protected]>
Date:   Tue Jun 19 09:26:01 2018 +0200

    js: getDefaultKey and GenerateKey improvements
    
    --
    
    * src/Keyring.js: added more options for key generation.
    
    * src/Key.js: GetDefaultKey now relies on the info associated with the
      key, as the approach of relying on a secret subkey did not work as
      intended
    * DemoExtension: Added a button for retrieval of the subkey, to test
      this functionality.

diff --git a/lang/js/DemoExtension/maindemo.js b/lang/js/DemoExtension/maindemo.js
index 67b811f..6230c3f 100644
--- a/lang/js/DemoExtension/maindemo.js
+++ b/lang/js/DemoExtension/maindemo.js
@@ -57,7 +57,7 @@ document.addEventListener('DOMContentLoaded', function() {
         document.getElementById('getdefaultkey').addEventListener('click',
             function(){
                 gpgmejs.Keyring.getDefaultKey().then(function(answer){
-                    document.getElementById('defaultkey').innerHtml =
+                    document.getElementById('defaultkey').textContent =
                         answer.fingerprint;
                 }, function(errormsg){
                     alert(errormsg.message);
diff --git a/lang/js/src/Key.js b/lang/js/src/Key.js
index 3e4f1c7..88c2b92 100644
--- a/lang/js/src/Key.js
+++ b/lang/js/src/Key.js
@@ -218,7 +218,6 @@ export class GPGME_Key {
      *
      * @async
      */
-    // TODO: Does not work yet, result is always false
     getHasSecret(){
         let me = this;
         return new Promise(function(resolve, reject) {
@@ -230,31 +229,17 @@ export class GPGME_Key {
             msg.setParameter('secret', true);
             msg.post().then(function(result){
                 me._data.hasSecret = null;
-                if (result.keys === undefined || result.keys.length < 1) {
+                if (
+                    result.keys &&
+                    result.keys.length === 1 &&
+                    result.keys[0].secret === true
+                ) {
+                    me._data.hasSecret = true;
+                    resolve(true);
+                } else {
                     me._data.hasSecret = false;
                     resolve(false);
                 }
-                else if (result.keys.length === 1){
-                    let key = result.keys[0];
-                    if (!key.subkeys){
-                        me._data.hasSecret = false;
-                        resolve(false);
-                    } else {
-                        for (let i=0; i < key.subkeys.length; i++) {
-                            if (key.subkeys[i].secret === true) {
-                                me._data.hasSecret = true;
-                                resolve(true);
-                                break;
-                            }
-                            if (i === (key.subkeys.length -1)) {
-                                me._data.hasSecret = false;
-                                resolve(false);
-                            }
-                        }
-                    }
-                } else {
-                    reject(gpgme_error('CONN_UNEXPECTED_ANSWER'));
-                }
             }, function(error){
                 reject(error);
             });
diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js
index 43d257d..8bec1ce 100644
--- a/lang/js/src/Keyring.js
+++ b/lang/js/src/Keyring.js
@@ -273,21 +273,18 @@ export class GPGME_Keyring {
      * Keys can not be _deleted_ from inside gpgmejs.
      *
      * @param {String} userId The user Id, e.g. "Foo Bar <[email protected]>"
-     * @param {*} algo (optional) algorithm to be used. See
-     *      {@link supportedKeyAlgos } below for supported values.
-     * @param {Number} keyLength (optional) TODO
+     * @param {*} algo (optional) algorithm (and optionally key size to be
+     *  used. See {@link supportedKeyAlgos } below for supported values.
      * @param {Date} expires (optional) Expiration date. If not set, expiration
      * will be set to 'never'
      *
      * @returns{Promise<Key>}
      */
-    generateKey(userId, algo = 'default', keyLength, expires){
+    generateKey(userId, algo = 'default', expires){
         if (
             typeof(userId) !== 'string' ||
             supportedKeyAlgos.indexOf(algo) < 0 ||
             (expires && !(expires instanceof Date))
-            // TODO keylength
-            // TODO check for completeness of algos
         ){
             return Promise.reject(gpgme_error('PARAM_WRONG'));
         }
@@ -295,12 +292,11 @@ export class GPGME_Keyring {
         return new Promise(function(resolve, reject){
             let msg = createMessage('createkey');
             msg.setParameter('userid', userId);
-            msg.setParameter('algo', algo);
+            msg.setParameter('algo', algo );
             if (expires){
                 msg.setParameter('expires',
                     Math.floor(expires.valueOf()/1000));
             }
-            // TODO append keylength to algo
             msg.post().then(function(response){
                 me.getKeys(response.fingerprint, true).then(
                     // TODO make prepare_sync (second parameter) optional here.
@@ -321,9 +317,11 @@ export class GPGME_Keyring {
  */
 const supportedKeyAlgos = [
     'default',
-    'rsa',
-    'dsa',
-    'elg',
+    'rsa', 'rsa2048', 'rsa3072', 'rsa4096',
+    'dsa', 'dsa2048', 'dsa3072', 'dsa4096',
+    'elg', 'elg2048', 'elg3072', 'elg4096',
     'ed25519',
-    'cv25519'
+    'cv25519',
+    'brainpoolP256r1', 'brainpoolP384r1', 'brainpoolP512r1',
+    'NIST P-256', 'NIST P-384', 'NIST P-521'
 ];
\ No newline at end of file

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

Summary of changes:
 lang/js/DemoExtension/maindemo.js |  2 +-
 lang/js/src/Key.js                | 31 ++++++++-----------------------
 lang/js/src/Keyring.js            | 22 ++++++++++------------
 3 files changed, 19 insertions(+), 36 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.