change var names

This commit is contained in:
Sanjana Rajan 2018-02-08 12:30:34 +01:00
parent 6578a57968
commit e5e49901a7
2 changed files with 22 additions and 21 deletions

View File

@ -91,13 +91,13 @@ Message.prototype.getSigningKeyIds = function() {
/**
* Decrypt the message. Either a private key, a session key, or a password must be specified.
* @param {Key} privateKey (optional) private key with decrypted secret data
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
* @param {String} password (optional) password used to decrypt
* @param {Array<Key>} privateKeys (optional) private key with decrypted secret data
* @param {Array<String>} passwords (optional) password used to decrypt
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
* @return {Message} new message with decrypted content
*/
Message.prototype.decrypt = async function(privateKey, sessionKey, password) {
let keyObjs = sessionKey || await this.decryptSessionKeys(privateKey, password);
Message.prototype.decrypt = async function(privateKeys, passwords, sessionKey) {
let keyObjs = sessionKey || await this.decryptSessionKeys(privateKeys, passwords);
if (!util.isArray(keyObjs)) {
keyObjs = [keyObjs];
}
@ -140,15 +140,15 @@ Message.prototype.decrypt = async function(privateKey, sessionKey, password) {
};
/**
* Decrypt an encrypted session key either with a private key or a password.
* @param {Key} privateKey (optional) private key with decrypted secret data
* @param {String} password (optional) password used to decrypt
* Decrypt an encrypted session key either with private keys or passwords.
* @param {Array<Key>} privateKeys (optional) private key with decrypted secret data
* @param {Array<String>} passwords (optional) password used to decrypt
* @return {Array<{ data:Uint8Array, algorithm:String }>} array of object with potential sessionKey, algorithm pairs
*/
Message.prototype.decryptSessionKeys = function(privateKey, password) {
Message.prototype.decryptSessionKeys = function(privateKeys, passwords) {
var keyPackets = [];
return Promise.resolve().then(async () => {
if (password) {
if (passwords) {
var symESKeyPacketlist = this.packets.filterByTag(enums.packet.symEncryptedSessionKey);
if (!symESKeyPacketlist) {
throw new Error('No symmetrically encrypted session key packet found.');
@ -160,7 +160,7 @@ Message.prototype.decryptSessionKeys = function(privateKey, password) {
} catch (err) {}
}));
} else if (privateKey) {
} else if (privateKeys) {
var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
if (!pkESKeyPacketlist) {
throw new Error('No public key encrypted session key packet found.');

View File

@ -246,30 +246,31 @@ export function encrypt({ data, publicKeys, privateKeys, passwords, sessionKey,
* Decrypts a message with the user's private key, a session key or a password. Either a private key,
* a session key or a password must be specified.
* @param {Message} message the message object with the encrypted data
* @param {Key} privateKey (optional) private key with decrypted secret key data or session key
* @param {Key|Array<Key>} publicKeys (optional) array of public keys or single key, to verify signatures
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
* @param {String} password (optional) single password to decrypt the message
* @param {String} format (optional) return data format either as 'utf8' or 'binary'
* @param {Signature} signature (optional) detached signature for verification
* @param {Key|Array<Key>} privateKeys (optional) private key with decrypted secret key data or session key
* @param {String|Array<String>} passwords (optional) single password to decrypt the message
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
* @param {Key|Array<Key>} publicKeys (optional) array of public keys or single key, to verify signatures
* @param {String} format (optional) return data format either as 'utf8' or 'binary'
* @param {Signature} signature (optional) detached signature for verification
* @return {Promise<Object>} decrypted and verified message in the form:
* { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
* @static
*/
export function decrypt({ message, privateKey, publicKeys, sessionKey, password, format='utf8', signature=null }) {
checkMessage(message); publicKeys = toArray(publicKeys);
export function decrypt({ message, privateKeys, passwords, sessionKey, publicKeys, format='utf8', signature=null }) {
checkMessage(message); publicKeys = toArray(publicKeys); privateKeys = toArray(privateKeys); passwords = toArray(passwords);
if (!nativeAEAD() && asyncProxy) { // use web worker if web crypto apis are not supported
return asyncProxy.delegate('decrypt', { message, privateKey, publicKeys, sessionKey, password, format, signature });
return asyncProxy.delegate('decrypt', { message, privateKeys, passwords, sessionKey, publicKeys, format, signature });
}
return message.decrypt(privateKey, sessionKey, password).then(async function(message) {
return message.decrypt(privateKeys, passwords, sessionKey).then(async function(message) {
const result = parseMessage(message, format);
if (!publicKeys) {
publicKeys = [];
}
if (signature) {
//detached signature
result.signatures = await message.verifyDetached(signature, publicKeys);