diff options
author | Maximilian Krambach <[email protected]> | 2018-06-08 15:54:58 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-06-08 15:54:58 +0000 |
commit | c072675f3f2d734297a348c6de810148fb1424a2 (patch) | |
tree | 9e0ddfd642f26b6adfd793a7db9241c404bb891d /lang/js/src/Message.js | |
parent | js: change Keyinfo timestamps into javascript date (diff) | |
download | gpgme-c072675f3f2d734297a348c6de810148fb1424a2.tar.gz gpgme-c072675f3f2d734297a348c6de810148fb1424a2.zip |
js: change chunksize handling and decoding
--
* the nativeApp now sends all data in one base64-encoded string, which
needs reassembly, but in a much easier way now.
* there are some new performance problems now, especially with
decrypting data
Diffstat (limited to '')
-rw-r--r-- | lang/js/src/Message.js | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js index 0ddda6c4..7ccf7efc 100644 --- a/lang/js/src/Message.js +++ b/lang/js/src/Message.js @@ -46,7 +46,6 @@ export class GPGME_Message { constructor(operation){ this.operation = operation; - this._expected = 'string'; } set operation (op){ @@ -59,24 +58,50 @@ export class GPGME_Message { } } } - get operation(){ return this._msg.op; } - set expected(string){ - if (string === 'base64'){ - this._expected = 'base64'; + /** + * Set the maximum size of responses from gpgme in bytes. Values allowed + * range from 10kB to 1MB. The lower limit is arbitrary, the upper limit + * fixed by browsers' nativeMessaging specifications + */ + set chunksize(value){ + if ( + Number.isInteger(value) && + value > 10 * 1024 && + value <= 1024 * 1024 + ){ + this._chunksize = value; + } + } + get chunksize(){ + if (this._chunksize === undefined){ + return 1024 * 1023; + } else { + return this._chunksize; } } - get expected() { - if (this._expected === 'base64'){ - return this._expected; + /** + * If expect is set to 'base64', the response is expected to be base64 + * encoded binary + */ + set expect(value){ + if (value ==='base64'){ + this._expect = value; + } + } + + get expect(){ + if ( this._expect === 'base64'){ + return this._expect; } - return 'string'; + return undefined; } + /** * Sets a parameter for the message. Note that the operation has to be set * first, to be able to check if the parameter is permittted @@ -188,6 +213,7 @@ export class GPGME_Message { */ get message(){ if (this.isComplete === true){ + this._msg.chunksize = this.chunksize; return this._msg; } else { @@ -201,10 +227,13 @@ export class GPGME_Message { return new Promise(function(resolve, reject) { if (me.isComplete === true) { let conn = new Connection; + if (me._msg.chunksize === undefined){ + me._msg.chunksize = 1023*1024; + } conn.post(me).then(function(response) { resolve(response); }, function(reason) { - reject(gpgme_error('GNUPG_ERROR', reason)); + reject(reason); }); } else { |