From e5e49901a7316254486737d7452a09e585247a32 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Thu, 8 Feb 2018 12:30:34 +0100 Subject: [PATCH] change var names --- src/message.js | 22 +++++++++++----------- src/openpgp.js | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/message.js b/src/message.js index 10073ae2..2036710c 100644 --- a/src/message.js +++ b/src/message.js @@ -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} privateKeys (optional) private key with decrypted secret data + * @param {Array} 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} privateKeys (optional) private key with decrypted secret data + * @param {Array} 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.'); diff --git a/src/openpgp.js b/src/openpgp.js index 2b38859f..24399e73 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -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} 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} privateKeys (optional) private key with decrypted secret key data or session key + * @param {String|Array} passwords (optional) single password to decrypt the message + * @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String } + * @param {Key|Array} 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} 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);