diff options
author | Maximilian Krambach <[email protected]> | 2018-08-27 10:32:28 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-08-27 10:38:32 +0000 |
commit | 766d42c248a8c526b831685e93d54db81492f5a8 (patch) | |
tree | 3d4b0794e4b59f1a347548b0277662d3005b7365 /lang/js/src/Keyring.js | |
parent | json: Do not put FILE_NAME into the verify result. (diff) | |
download | gpgme-766d42c248a8c526b831685e93d54db81492f5a8.tar.gz gpgme-766d42c248a8c526b831685e93d54db81492f5a8.zip |
js: typecheck destructured parameters
--
* destructuring just takes the input argument and treats it as object.
In cases like in src/Keyring/generateKey, where I forgot to change
the old syntax, the fingerprint as string was destructured into an
object without "pattern", which caused all Keys to be retrieved.
So, methods with a destructuring now check if the first argument is
an object and get a default empty object if no parameter is
submitted. This allows the further use of destructured parameters,
while still ensuring nothing vastly incorrect is used.
* src/Kering.js, unittsets.js: fixed old syntax in method usage
Diffstat (limited to '')
-rw-r--r-- | lang/js/src/Keyring.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js index 2b57e63f..0c64f337 100644 --- a/lang/js/src/Keyring.js +++ b/lang/js/src/Keyring.js @@ -49,7 +49,13 @@ export class GPGME_Keyring { * @static * @async */ - getKeys ({ pattern, prepare_sync = false, search = false }){ + getKeys ({ pattern, prepare_sync = false, search = false } = {}){ + if (typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } + if (arguments.length && typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } return new Promise(function (resolve, reject) { let msg = createMessage('keylist'); if (pattern) { @@ -387,7 +393,7 @@ export class GPGME_Keyring { * @return {Promise<Key|GPGME_Error>} * @async */ - generateKey ({ userId, algo = 'default', expires= 0, subkey_algo }){ + generateKey ({ userId, algo = 'default', expires= 0, subkey_algo } = {}){ if (typeof userId !== 'string' // eslint-disable-next-line no-use-before-define || (algo && supportedKeyAlgos.indexOf(algo) < 0 ) @@ -409,13 +415,14 @@ export class GPGME_Keyring { } msg.setParameter('expires', expires); msg.post().then(function (response){ - me.getKeys(response.fingerprint, true).then( - // TODO prepare_sync? - function (result){ - resolve(result); - }, function (error){ - reject(error); - }); + me.getKeys({ + pattern: response.fingerprint, + prepare_sync: true + }).then(function (result){ + resolve(result); + }, function (error){ + reject(error); + }); }, function (error) { reject(error); }); |