From 4f28fbddd3d70eb7e3ce874b1673630142110b72 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 27 Aug 2018 11:50:09 +0200 Subject: [PATCH] js: extend information on decoding in decrypt -- * src/Connection.js: resulting data, if not pure ascii, is base64 encoded in the result message. A further decoding attempt into javascript 'string' will be attempted by default, unless specified at the decrypt() method. The return value 'format' now shows which of the possibilities has been applied. The old boolean 'base64' now turns into format:'base64' if the returned payload is a base64 string after decryption. --- lang/js/src/Connection.js | 4 +++- lang/js/src/gpgmejs.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js index 3fd1810d..c4921d53 100644 --- a/lang/js/src/Connection.js +++ b/lang/js/src/Connection.js @@ -232,7 +232,9 @@ class Answer{ return gpgme_error('CONN_UNEXPECTED_ANSWER'); } let _decodedResponse = JSON.parse(atob(this._response_b64)); - let _response = {}; + let _response = { + format: 'ascii' + }; let messageKeys = Object.keys(_decodedResponse); let poa = permittedOperations[this.operation].answer; if (messageKeys.length === 0){ diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index 5bdffeb5..b86b5f18 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -55,8 +55,12 @@ import { createSignature } from './Signature'; /** * @typedef {Object} encrypt_result The result of an encrypt operation * @property {String} data The encrypted message - * @property {Boolean} base64 Indicating whether returning payload data is - * base64 encoded + * @property {String} format Indicating how the data was converted after being + * received from gpgme. + * 'ascii': Data was ascii-encoded and no further processed + * 'string': Data was decoded into an utf-8 string, + * 'base64': Data was not processed and is a base64 string + * 'uint8': Data was turned into a Uint8Array */ /**