initial modifications
This commit is contained in:
parent
2e4e9387a0
commit
91d35ff99c
|
@ -74,22 +74,43 @@ function getWorker() {
|
||||||
/**
|
/**
|
||||||
* Encrypts message text/data with keys or passwords
|
* Encrypts message text/data with keys or passwords
|
||||||
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
||||||
* @param {String} text text message as native JavaScript string
|
* @param {String} data text/data message as native JavaScript string/binary string
|
||||||
* @param {(Array<String>|String)} passwords passwords for the message
|
* @param {(Array<String>|String)} passwords passwords for the message
|
||||||
* @return {Promise<String>} encrypted ASCII armored message
|
* @param {Object} params parameter object with optional properties binary {Boolean},
|
||||||
|
* filename {String}, and packets {Boolean}
|
||||||
|
* @return {Promise<String> or Promise<Packetlist>} encrypted ASCII armored message, or Packetlist if params.packets is true
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function encryptMessage(keys, text, passwords) {
|
function encryptMessage(keys, data, passwords, params) {
|
||||||
|
|
||||||
if (asyncProxy) {
|
if (asyncProxy) {
|
||||||
return asyncProxy.encryptMessage(keys, text, passwords);
|
return asyncProxy.encryptMessage(keys, data, passwords, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
var filename, binary, packets;
|
||||||
|
if(params) {
|
||||||
|
filename = params.filename;
|
||||||
|
binary = params.binary;
|
||||||
|
packets = params.packets;
|
||||||
}
|
}
|
||||||
|
|
||||||
return execute(function() {
|
return execute(function() {
|
||||||
var msg, armored;
|
var msg, armored;
|
||||||
msg = message.fromText(text);
|
if(binary) {
|
||||||
|
msg = message.fromBinary(data, filename);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = message.fromText(data, filename);
|
||||||
|
}
|
||||||
msg = msg.encrypt(keys, passwords);
|
msg = msg.encrypt(keys, passwords);
|
||||||
return armor.encode(enums.armor.message, msg.packets.write());
|
|
||||||
|
if(packets) {
|
||||||
|
return msg.packets;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return armor.encode(enums.armor.message, msg.packets.write());
|
||||||
|
}
|
||||||
|
|
||||||
}, 'Error encrypting message!');
|
}, 'Error encrypting message!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,18 +146,25 @@ function signAndEncryptMessage(publicKeys, privateKey, text) {
|
||||||
* Decrypts message
|
* Decrypts message
|
||||||
* @param {module:key~Key|String} privateKey private key with decrypted secret key data or string password
|
* @param {module:key~Key|String} privateKey private key with decrypted secret key data or string password
|
||||||
* @param {module:message~Message} msg the message object with the encrypted data
|
* @param {module:message~Message} msg the message object with the encrypted data
|
||||||
|
* @param {Boolean} binary if true, return literal data binaryString instead of converting from UTF-8
|
||||||
* @return {Promise<(String|null)>} decrypted message as as native JavaScript string
|
* @return {Promise<(String|null)>} decrypted message as as native JavaScript string
|
||||||
* or null if no literal data found
|
* or null if no literal data found
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function decryptMessage(privateKey, msg) {
|
function decryptMessage(privateKey, msg, binary) {
|
||||||
if (asyncProxy) {
|
if (asyncProxy) {
|
||||||
return asyncProxy.decryptMessage(privateKey, msg);
|
return asyncProxy.decryptMessage(privateKey, msg, binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
return execute(function() {
|
return execute(function() {
|
||||||
msg = msg.decrypt(privateKey);
|
msg = msg.decrypt(privateKey);
|
||||||
return msg.getText();
|
if(binary) {
|
||||||
|
return msg.getLiteralData();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return msg.getText();
|
||||||
|
}
|
||||||
|
|
||||||
}, 'Error decrypting message!');
|
}, 'Error decrypting message!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,10 +132,12 @@ AsyncProxy.prototype.terminate = function() {
|
||||||
/**
|
/**
|
||||||
* Encrypts message text/data with keys or passwords
|
* Encrypts message text/data with keys or passwords
|
||||||
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
||||||
* @param {String} text text message as native JavaScript string/binary string
|
* @param {String} data text/data message as native JavaScript string/binary string
|
||||||
* @param {(Array<String>|String)} passwords passwords for the message
|
* @param {(Array<String>|String)} passwords passwords for the message
|
||||||
|
* @param {Object} params parameter object with optional properties binary {Boolean},
|
||||||
|
* filename {String}, and packets {Boolean}
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.encryptMessage = function(keys, text, passwords) {
|
AsyncProxy.prototype.encryptMessage = function(keys, data, passwords, params) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return self.execute(function() {
|
return self.execute(function() {
|
||||||
|
@ -150,8 +152,9 @@ AsyncProxy.prototype.encryptMessage = function(keys, text, passwords) {
|
||||||
self.worker.postMessage({
|
self.worker.postMessage({
|
||||||
event: 'encrypt-message',
|
event: 'encrypt-message',
|
||||||
keys: keys,
|
keys: keys,
|
||||||
text: text,
|
data: data,
|
||||||
passwords: passwords
|
passwords: passwords,
|
||||||
|
params: params
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -188,7 +191,7 @@ AsyncProxy.prototype.signAndEncryptMessage = function(publicKeys, privateKey, te
|
||||||
* @param {module:message~Message} msg the message object with the encrypted data
|
* @param {module:message~Message} msg the message object with the encrypted data
|
||||||
* @param {Boolean} binary if true, return literal data binaryString instead of converting from UTF-8
|
* @param {Boolean} binary if true, return literal data binaryString instead of converting from UTF-8
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.decryptMessage = function(privateKey, message) {
|
AsyncProxy.prototype.decryptMessage = function(privateKey, message, binary) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return self.execute(function() {
|
return self.execute(function() {
|
||||||
|
@ -199,7 +202,8 @@ AsyncProxy.prototype.decryptMessage = function(privateKey, message) {
|
||||||
self.worker.postMessage({
|
self.worker.postMessage({
|
||||||
event: 'decrypt-message',
|
event: 'decrypt-message',
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
message: message
|
message: message,
|
||||||
|
binary: binary
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,7 +68,7 @@ self.onmessage = function (event) {
|
||||||
if(msg.keys) {
|
if(msg.keys) {
|
||||||
msg.keys = msg.keys.map(packetlistCloneToKey);
|
msg.keys = msg.keys.map(packetlistCloneToKey);
|
||||||
}
|
}
|
||||||
window.openpgp.encryptMessage(msg.keys, msg.text, msg.passwords).then(function(data) {
|
window.openpgp.encryptMessage(msg.keys, msg.data, msg.passwords, msg.params).then(function(data) {
|
||||||
response({event: 'method-return', data: data});
|
response({event: 'method-return', data: data});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
response({event: 'method-return', err: e.message});
|
response({event: 'method-return', err: e.message});
|
||||||
|
@ -91,7 +91,7 @@ self.onmessage = function (event) {
|
||||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||||
}
|
}
|
||||||
msg.message = packetlistCloneToMessage(msg.message.packets);
|
msg.message = packetlistCloneToMessage(msg.message.packets);
|
||||||
window.openpgp.decryptMessage(msg.privateKey, msg.message).then(function(data) {
|
window.openpgp.decryptMessage(msg.privateKey, msg.message, msg.binary).then(function(data) {
|
||||||
response({event: 'method-return', data: data});
|
response({event: 'method-return', data: data});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
response({event: 'method-return', err: e.message});
|
response({event: 'method-return', err: e.message});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user