aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Connection.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-08-22 14:32:31 +0000
committerMaximilian Krambach <[email protected]>2018-08-22 14:32:31 +0000
commit129fa919b935d97d995bc6b457c7f6984c06e825 (patch)
treed25245b9ae7634acd99d713e12832fd97c988af0 /lang/js/src/Connection.js
parentjs: Return error if signature has no fingerprint (diff)
downloadgpgme-129fa919b935d97d995bc6b457c7f6984c06e825.tar.gz
gpgme-129fa919b935d97d995bc6b457c7f6984c06e825.zip
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 [email protected] 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.
Diffstat (limited to 'lang/js/src/Connection.js')
-rw-r--r--lang/js/src/Connection.js24
1 files changed, 13 insertions, 11 deletions
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]);
}