From 129fa919b935d97d995bc6b457c7f6984c06e825 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 22 Aug 2018 16:32:31 +0200 Subject: js: improve decryption performance -- * src/Connection.js, src/Helpers.js: performance of decoding incoming base64 data was improved to about 4 times the speed by introducing two more efficient functions (thanks to rrenkert@intevation.de for finding and testing them) * src/gpgmejs.js: Decrypted data will now return as Uint8Array, if the caller does not wish for a decoding. Decoding binary data will return invalid data, and a Uint8Array may be desired. This can be indicated by using the (new) 'binary' option in decrypt. * src/Errors.js A new error in case this decoding fails * src/Message.js, src/Connection.js: expected is change from base64 to binary, to avoid confusion later on. --- lang/js/src/Connection.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'lang/js/src/Connection.js') diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js index 928ac681..8756cce1 100644 --- a/lang/js/src/Connection.js +++ b/lang/js/src/Connection.js @@ -26,7 +26,7 @@ import { permittedOperations } from './permittedOperations'; import { gpgme_error } from './Errors'; import { GPGME_Message, createMessage } from './Message'; -import { decode } from './Helpers'; +import { decode, atobArray, Utf8ArrayToStr } from './Helpers'; /** * A Connection handles the nativeMessaging interaction via a port. As the @@ -223,8 +223,9 @@ class Answer{ } } /** - * Returns the base64 encoded answer data with the content verified - * against {@link permittedOperations}. + * Decodes and verifies the base64 encoded answer data. Verified against + * {@link permittedOperations}. + * @returns {Object} The readable gpnupg answer */ getMessage (){ if (this._response_b64 === null){ @@ -264,14 +265,15 @@ class Answer{ } if (_decodedResponse.base64 === true && poa.data[key] === 'string' - && this.expected !== 'base64' - ){ - _response[key] = decodeURIComponent( - atob(_decodedResponse[key]).split('').map( - function (c) { - return '%' + - ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); + ) { + if (this.expected === 'binary'){ + _response[key] = atobArray(_decodedResponse[key]); + _response.binary = true; + } else { + _response[key] = Utf8ArrayToStr( + atobArray(_decodedResponse[key])); + _response.binary = false; + } } else { _response[key] = decode(_decodedResponse[key]); } -- cgit v1.2.3