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
This commit is contained in:
parent
a9863717b1
commit
44691995b7
@ -136,6 +136,8 @@ export class GpgME {
|
|||||||
* @param {Boolean} always_trust (optional, default true) This assumes that
|
* @param {Boolean} always_trust (optional, default true) This assumes that
|
||||||
* used keys are fully trusted. If set to false, encryption to a key not
|
* used keys are fully trusted. If set to false, encryption to a key not
|
||||||
* fully trusted in gnupg will fail
|
* 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
|
* @param {Object} additional use additional valid gpg options as
|
||||||
* defined in {@link permittedOperations}
|
* defined in {@link permittedOperations}
|
||||||
* @returns {Promise<encrypt_result>} Object containing the encrypted
|
* @returns {Promise<encrypt_result>} Object containing the encrypted
|
||||||
@ -143,7 +145,8 @@ export class GpgME {
|
|||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
encrypt ({ data, publicKeys, secretKeys, base64 = false, armor = true,
|
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') {
|
if (typeof arguments[0] !== 'object') {
|
||||||
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
||||||
}
|
}
|
||||||
@ -156,7 +159,11 @@ export class GpgME {
|
|||||||
}
|
}
|
||||||
if (armor === false){
|
if (armor === false){
|
||||||
msg.setParameter('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) {
|
} else if (armor === true) {
|
||||||
msg.setParameter('armor', true);
|
msg.setParameter('armor', true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user