js: Fix Key.hasSecret answer
authorMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 31 Jul 2018 14:54:43 +0000 (16:54 +0200)
committerMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 31 Jul 2018 14:54:43 +0000 (16:54 +0200)
--

* The comparision result between Keyring and Keyring with secrets was
  set to the wrong Object which was not returned at all.

lang/js/src/Key.js
lang/js/src/Keyring.js

index f431a28..88c49d3 100644 (file)
@@ -74,7 +74,7 @@ export class GPGME_Key {
          * @returns {Boolean} If the Key has a secret subkey.
          */
         this.hasSecret= function (){
-            return this.get('hasSecret', true);
+            return this.get('hasSecret');
         };
 
         /**
index 31c4f92..8715a47 100644 (file)
@@ -46,7 +46,7 @@ export class GPGME_Keyring {
          * resort to a refresh() first.
          * @param {Boolean} search (optional) retrieve Keys from external
          * servers with the method(s) defined in gnupg (e.g. WKD/HKP lookup)
-         * @returns {Promise.<Array<GPGME_Key>|GPGME_Error>}
+         * @returns {Promise<Array<GPGME_Key>>}
          * @static
          * @async
          */
@@ -79,9 +79,9 @@ export class GPGME_Keyring {
                             };
                         }
                         secondrequest().then(function(answer) {
-                            for (let i=0; i < result.keys.length; i++){
+                            for (let i=0; i < answer.keys.length; i++){
                                 if (prepare_sync === true){
-                                    result.keys[i].hasSecret = false;
+                                    result.keys[i].hasSecret = undefined;
                                     if (answer && answer.keys) {
                                         for (let j=0;
                                             j < answer.keys.length; j++ ){
@@ -91,7 +91,9 @@ export class GPGME_Keyring {
                                                 a.fingerprint === b.fingerprint
                                             ) {
                                                 if (a.secret === true){
-                                                    a.hasSecret = true;
+                                                    b.hasSecret = true;
+                                                } else {
+                                                    b.hasSecret = false;
                                                 }
                                                 break;
                                             }