aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lang/js/BrowserTestExtension/tests/encryptDecryptTest.js24
-rw-r--r--lang/js/src/Connection.js9
-rw-r--r--lang/js/src/Message.js2
-rw-r--r--lang/js/src/gpgmejs.js21
4 files changed, 44 insertions, 12 deletions
diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
index 1efdf5cf..c10c5d06 100644
--- a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
@@ -144,6 +144,30 @@ describe('Encryption and Decryption', function (){
});
}).timeout(3000);
+ it('Random data, original data is and should stay base64 encoded',
+ function (done) {
+ let data = bigBoringString(0.001);
+ let b64data = btoa(data);
+ context.encrypt(
+ { data: b64data, publicKeys: good_fpr })
+ .then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a('string');
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ context.decrypt({
+ data:answer.data, expect: 'base64' })
+ .then(function (result) {
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(b64data);
+ done();
+ });
+ });
+ }).timeout(3000);
+
for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
it('Roundtrip with >1MB non-ascii input meeting default chunksize (' +
(j + 1) + '/'
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 8756cce1..3fd1810d 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -266,13 +266,16 @@ class Answer{
if (_decodedResponse.base64 === true
&& poa.data[key] === 'string'
) {
- if (this.expected === 'binary'){
+ if (this.expected === 'uint8'){
_response[key] = atobArray(_decodedResponse[key]);
- _response.binary = true;
+ _response.format = 'uint8';
+ } else if (this.expected === 'base64'){
+ _response[key] = _decodedResponse[key];
+ _response.format = 'base64';
} else {
_response[key] = Utf8ArrayToStr(
atobArray(_decodedResponse[key]));
- _response.binary = false;
+ _response.format = 'string';
}
} else {
_response[key] = decode(_decodedResponse[key]);
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index 48813df7..fff20fbe 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -64,7 +64,7 @@ export class GPGME_Message {
}
set expected (value){
- if (value === 'binary'){
+ if (value === 'uint8' || value === 'base64'){
this._expected = value;
}
}
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index e0398423..ac640308 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -31,7 +31,11 @@ import { createSignature } from './Signature';
/**
* @typedef {Object} decrypt_result
* @property {String|Uint8Array} data The decrypted data
- * @property {Boolean} binary indicating whether data is an Uint8Array.
+ * @property {String} format Indicating how the data was converted after being
+ * received from gpgme.
+ * '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
* @property {Boolean} is_mime (optional) the data claims to be a MIME
* object.
* @property {String} file_name (optional) the original file name
@@ -51,8 +55,8 @@ import { createSignature } from './Signature';
/**
* @typedef {Object} encrypt_result The result of an encrypt operation
* @property {String} data The encrypted message
- * @property {Boolean} binary Indicating whether returning payload data is an
- * Uint8Array.
+ * @property {Boolean} base64 Indicating whether returning payload data is
+ * base64 encoded
*/
/**
@@ -187,8 +191,9 @@ export class GpgME {
* Strings and Objects with a getText method
* @param {Boolean} options.base64 (optional) false if the data is an
* armored block, true if it is base64 encoded binary data
- * @param {Boolean} options.binary (optional) if true, treat the decoded
- * data as binary, and return the data as Uint8Array
+ * @param {String} options.expect (optional) can be set to 'uint8' or
+ * 'base64'. Does no extra decoding on the data, and returns the decoded
+ * data as either Uint8Array or unprocessed(base64 encoded) string.
* @returns {Promise<decrypt_result>} Decrypted Message and information
* @async
*/
@@ -207,14 +212,14 @@ export class GpgME {
if (options.base64 === true){
msg.setParameter('base64', true);
}
- if (options.binary === true){
- msg.expected = 'binary';
+ if (options.expect === 'base64' || options.expect === 'uint8'){
+ msg.expected = options.expect;
}
putData(msg, options.data);
return new Promise(function (resolve, reject){
msg.post().then(function (result){
let _result = { data: result.data };
- _result.binary = result.binary ? true: false;
+ _result.format = result.format ? result.format : null;
if (result.hasOwnProperty('dec_info')){
_result.is_mime = result.dec_info.is_mime ? true: false;
if (result.dec_info.file_name) {