diff options
author | Maximilian Krambach <[email protected]> | 2018-08-30 12:46:54 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-08-30 12:46:54 +0000 |
commit | 44691995b72c483ee8a91f11767b2bd317072d5a (patch) | |
tree | 549838b0f04b875fab1c632ac106eb160396a5ad /lang/js | |
parent | js: separate gpgme answer by type of data (diff) | |
download | gpgme-44691995b72c483ee8a91f11767b2bd317072d5a.tar.gz gpgme-44691995b72c483ee8a91f11767b2bd317072d5a.zip |
js: add encoding parameter for encrypt return
--
* src/gpgme.js: In case the encryption was done unarmored, the result
is binary data. Added an option to either return the binary data as
base64-encoded string or as Uint8Array, similar to return values of
decrypt
Diffstat (limited to 'lang/js')
-rw-r--r-- | lang/js/src/gpgmejs.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index 295cc043..7b835ac2 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -136,6 +136,8 @@ export class GpgME { * @param {Boolean} always_trust (optional, default true) This assumes that * used keys are fully trusted. If set to false, encryption to a key not * fully trusted in gnupg will fail + * @param {String} expect in case of armored:false, request how to return + * the binary result. Accepts 'base64' or 'uint8', defaults to 'base64'. * @param {Object} additional use additional valid gpg options as * defined in {@link permittedOperations} * @returns {Promise<encrypt_result>} Object containing the encrypted @@ -143,7 +145,8 @@ export class GpgME { * @async */ encrypt ({ data, publicKeys, secretKeys, base64 = false, armor = true, - wildcard, always_trust = true, additional = {} } = {}){ + wildcard, always_trust = true, expect = 'base64', + additional = {} } = {}){ if (typeof arguments[0] !== 'object') { return Promise.reject(gpgme_error('PARAM_WRONG')); } @@ -156,7 +159,11 @@ export class GpgME { } if (armor === false){ msg.setParameter('armor', false); - msg.expected = 'base64'; + if (expect === 'uint8' || expect === 'base64') { + msg.expected = expect; + } else { + return Promise.reject(gpgme_error('PARAM_WRONG')); + } } else if (armor === true) { msg.setParameter('armor', true); } |