[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-89-g715cdc0

[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  715cdc0d7d5bc8d39ff3cc49774c59e5db01c1b6 (commit)
      from  aeb065acc91a22b6548ebf0a558951ed26398214 (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 715cdc0d7d5bc8d39ff3cc49774c59e5db01c1b6
Author: Maximilian Krambach <[email protected]>
Date:   Thu Aug 16 12:03:30 2018 +0200

    js: get default key fixes
    
    --
    
    * src/Keyring.js: The answer was not parsed correctly, so a config was
      being ignored.
    
    * If no config is set, we return the first non-invalid key with a
      secret, instead of the first key (which may be e.g. an expired one)

diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js
index c4b89b2..9fdd53b 100644
--- a/lang/js/src/Keyring.js
+++ b/lang/js/src/Keyring.js
@@ -176,12 +176,13 @@ export class GPGME_Keyring {
                 let msg = createMessage('config_opt');
                 msg.setParameter('component', 'gpg');
                 msg.setParameter('option', 'default-key');
-                msg.post().then(function(response){
-                    if (response.value !== undefined
-                        && response.value.hasOwnProperty('string')
-                        && typeof(response.value.string) === 'string'
-                    ){
-                        me.getKeys(response.value.string,true).then(
+                msg.post().then(function(resp){
+                    if (resp.option !== undefined
+                        && resp.option.hasOwnProperty('value')
+                        && resp.option.value.length === 1
+                        && resp.option.value[0].hasOwnProperty('string')
+                        && typeof(resp.option.value[0].string) === 'string'){
+                        me.getKeys(resp.option.value[0].string, true).then(
                             function(keys){
                                 if(keys.length === 1){
                                     resolve(keys[0]);
@@ -198,7 +199,14 @@ export class GPGME_Keyring {
                             if (result.keys.length === 0){
                                 reject(gpgme_error('KEY_NO_DEFAULT'));
                             } else {
-                                resolve(result.keys[0]);
+                                for (let i=0; i< result.keys.length; i++ ) {
+                                    if (result.keys[i].get('invalid') === false) {
+                                        resolve(result.keys[i]);
+                                        break;
+                                    } else if (i === result.keys.length - 1){
+                                        reject(gpgme_error('KEY_NO_DEFAULT'));
+                                    }
+                                }
                             }
                         }, function(error){
                             reject(error);

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

Summary of changes:
 lang/js/src/Keyring.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 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.