diff options
author | Maximilian Krambach <[email protected]> | 2018-06-13 13:22:03 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-06-13 13:22:03 +0000 |
commit | aed402c5d572b60246f1f8e57ae269f8c91b0b7c (patch) | |
tree | db92714ef1e5f2b9aafa819db5f9fd3c7dd45187 /lang/js/src/Keyring.js | |
parent | js: less confusing icons for test/Demo extension (diff) | |
download | gpgme-aed402c5d572b60246f1f8e57ae269f8c91b0b7c.tar.gz gpgme-aed402c5d572b60246f1f8e57ae269f8c91b0b7c.zip |
js: getDefaultKey and verify fix
--
* DemoExtension/maindemo.js - added a Demo for retrieving the default
signing key
* src/Errors.js - add a new Error if no default key can be determined
* src/Key.js added documentation and a TODO marker for hasSecret.
* src/Keyring.js implemented getDefaultKey
* src/permittedOperations.js: Added missing entry for verify,
added config_opt
Diffstat (limited to 'lang/js/src/Keyring.js')
-rw-r--r-- | lang/js/src/Keyring.js | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js index 0d4e3c52..e07a5934 100644 --- a/lang/js/src/Keyring.js +++ b/lang/js/src/Keyring.js @@ -99,7 +99,61 @@ export class GPGME_Keyring { }); } - // getDefaultKey() Big TODO + /** + * Returns the Key to be used by default for signing operations, + * looking up the gpg configuration, or returning the first key that + * contains a secret key. + * @returns {Promise<GPGME_Key>} + * + * @async + * TODO: getHasSecret always returns false at this moment, so this fucntion + * still does not fully work as intended. + * + */ + getDefaultKey() { + let me = this; + return new Promise(function(resolve, reject){ + 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(function(keys){ + if(keys.length === 1){ + resolve(keys[0]); + } else { + reject(gpgme_error('KEY_NO_DEFAULT')); + } + }, function(error){ + reject(error); + }); + } else { + // TODO: this is overly 'expensive' in communication + // and probably performance, too + me.getKeys(null,true).then(function(keys){ + for (let i=0; i < keys.length; i++){ + console.log(keys[i]); + console.log(keys[i].get('hasSecret')); + if (keys[i].get('hasSecret') === true){ + resolve(keys[i]); + break; + } + if (i === keys.length -1){ + reject(gpgme_error('KEY_NO_DEFAULT')); + } + } + }, function(error){ + reject(error); + }); + } + }, function(error){ + reject(error); + }); + }); + } /** * |