aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Connection.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-05-22 12:24:16 +0000
committerMaximilian Krambach <[email protected]>2018-05-22 12:24:16 +0000
commitecad77263585cd5954758f797327d98232d880dc (patch)
treec7654c406f4e838a06f646be8cbb6798e38b1bd9 /lang/js/src/Connection.js
parentjs: Testing lare messages (diff)
downloadgpgme-ecad77263585cd5954758f797327d98232d880dc.tar.gz
gpgme-ecad77263585cd5954758f797327d98232d880dc.zip
js: transfer encoding changes
-- * Uint8Arrays are not supported for now there are unsolved issues in conversion, and they are lower priority * encrypt gains a new option to indicate that input values are base64 encoded * as decrypted values are always base64 encoded, the option base64 will not try to decode the result into utf, but leave it as it is
Diffstat (limited to '')
-rw-r--r--lang/js/src/Connection.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 1931a55b..9c2a6428 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -93,7 +93,7 @@ export class Connection{
}
let me = this;
return new Promise(function(resolve, reject){
- let answer = new Answer(message.operation);
+ let answer = new Answer(message);
let listener = function(msg) {
if (!msg){
me._connection.onMessage.removeListener(listener)
@@ -147,8 +147,9 @@ export class Connection{
*/
class Answer{
- constructor(operation){
- this.operation = operation;
+ constructor(message){
+ this.operation = message.operation;
+ this.expected = message.expected;
}
/**
@@ -210,26 +211,31 @@ class Answer{
}
/**
- * @returns {Object} the assembled message.
- * TODO: does not care yet if completed.
+ * @returns {Object} the assembled message, original data assumed to be
+ * (javascript-) strings
*/
get message(){
let keys = Object.keys(this._response);
+ let msg = {};
let poa = permittedOperations[this.operation].answer;
for (let i=0; i < keys.length; i++) {
- if (poa.data.indexOf(keys[i]) >= 0){
- if (this._response.base64 == true){
- let respatob = atob(this._response[keys[i]]);
-
- let result = decodeURIComponent(
- respatob.split('').map(function(c) {
+ if (poa.data.indexOf(keys[i]) >= 0
+ && this._response.base64 === true
+ ) {
+ msg[keys[i]] = atob(this._response[keys[i]]);
+ if (this.expected === 'base64'){
+ msg[keys[i]] = this._response[keys[i]];
+ } else {
+ msg[keys[i]] = decodeURIComponent(
+ atob(this._response[keys[i]]).split('').map(function(c) {
return '%' +
- ('00' + c.charCodeAt(0).toString(16)).slice(-2);
+ ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
- this._response[keys[i]] = result;
}
+ } else {
+ msg[keys[i]] = this._response[keys[i]];
}
}
- return this._response;
+ return msg;
}
}