From 766d42c248a8c526b831685e93d54db81492f5a8 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 27 Aug 2018 12:32:28 +0200 Subject: 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 --- lang/js/src/gpgmejs.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lang/js/src/gpgmejs.js') diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index b86b5f18..592b0a13 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -142,7 +142,10 @@ export class GpgME { * @async */ encrypt ({ data, publicKeys, secretKeys, base64 = false, armor = true, - wildcard, always_trust = true, additional = {} }){ + wildcard, always_trust = true, additional = {} } = {}){ + if (typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } if (!data || !publicKeys){ return Promise.reject(gpgme_error('MSG_INCOMPLETE')); } @@ -203,7 +206,10 @@ export class GpgME { * @returns {Promise} Decrypted Message and information * @async */ - decrypt ({ data, base64, expect }){ + decrypt ({ data, base64, expect } = {}){ + if (typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } if (!data){ return Promise.reject(gpgme_error('MSG_EMPTY')); } @@ -263,7 +269,10 @@ export class GpgME { * @returns {Promise} * @async */ - sign ({ data, keys, mode = 'clearsign', base64 }){ + sign ({ data, keys, mode = 'clearsign', base64 } = {}){ + if (typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } if (!data){ return Promise.reject(gpgme_error('MSG_EMPTY')); } @@ -310,7 +319,10 @@ export class GpgME { * @returns {Promise} *@async */ - verify ({ data, signature, base64 }){ + verify ({ data, signature, base64 } = {}){ + if (typeof arguments[0] !== 'object') { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } if (!data){ return Promise.reject(gpgme_error('PARAM_WRONG')); } -- cgit v1.2.3