change var names
This commit is contained in:
parent
6578a57968
commit
e5e49901a7
|
@ -91,13 +91,13 @@ Message.prototype.getSigningKeyIds = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt the message. Either a private key, a session key, or a password must be specified.
|
* 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 {Array<Key>} privateKeys (optional) private key with decrypted secret data
|
||||||
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
|
* @param {Array<String>} passwords (optional) password used to decrypt
|
||||||
* @param {String} password (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
|
* @return {Message} new message with decrypted content
|
||||||
*/
|
*/
|
||||||
Message.prototype.decrypt = async function(privateKey, sessionKey, password) {
|
Message.prototype.decrypt = async function(privateKeys, passwords, sessionKey) {
|
||||||
let keyObjs = sessionKey || await this.decryptSessionKeys(privateKey, password);
|
let keyObjs = sessionKey || await this.decryptSessionKeys(privateKeys, passwords);
|
||||||
if (!util.isArray(keyObjs)) {
|
if (!util.isArray(keyObjs)) {
|
||||||
keyObjs = [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.
|
* Decrypt an encrypted session key either with private keys or passwords.
|
||||||
* @param {Key} privateKey (optional) private key with decrypted secret data
|
* @param {Array<Key>} privateKeys (optional) private key with decrypted secret data
|
||||||
* @param {String} password (optional) password used to decrypt
|
* @param {Array<String>} passwords (optional) password used to decrypt
|
||||||
* @return {Array<{ data:Uint8Array, algorithm:String }>} array of object with potential sessionKey, algorithm pairs
|
* @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 = [];
|
var keyPackets = [];
|
||||||
return Promise.resolve().then(async () => {
|
return Promise.resolve().then(async () => {
|
||||||
if (password) {
|
if (passwords) {
|
||||||
var symESKeyPacketlist = this.packets.filterByTag(enums.packet.symEncryptedSessionKey);
|
var symESKeyPacketlist = this.packets.filterByTag(enums.packet.symEncryptedSessionKey);
|
||||||
if (!symESKeyPacketlist) {
|
if (!symESKeyPacketlist) {
|
||||||
throw new Error('No symmetrically encrypted session key packet found.');
|
throw new Error('No symmetrically encrypted session key packet found.');
|
||||||
|
@ -160,7 +160,7 @@ Message.prototype.decryptSessionKeys = function(privateKey, password) {
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
} else if (privateKey) {
|
} else if (privateKeys) {
|
||||||
var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
|
var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
|
||||||
if (!pkESKeyPacketlist) {
|
if (!pkESKeyPacketlist) {
|
||||||
throw new Error('No public key encrypted session key packet found.');
|
throw new Error('No public key encrypted session key packet found.');
|
||||||
|
|
|
@ -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,
|
* 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.
|
* a session key or a password must be specified.
|
||||||
* @param {Message} message the message object with the encrypted data
|
* @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>} privateKeys (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 {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 {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
|
||||||
* @param {String} password (optional) single password to decrypt the message
|
* @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 {String} format (optional) return data format either as 'utf8' or 'binary'
|
||||||
* @param {Signature} signature (optional) detached signature for verification
|
* @param {Signature} signature (optional) detached signature for verification
|
||||||
* @return {Promise<Object>} decrypted and verified message in the form:
|
* @return {Promise<Object>} decrypted and verified message in the form:
|
||||||
* { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
|
* { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
export function decrypt({ message, privateKey, publicKeys, sessionKey, password, format='utf8', signature=null }) {
|
export function decrypt({ message, privateKeys, passwords, sessionKey, publicKeys, format='utf8', signature=null }) {
|
||||||
checkMessage(message); publicKeys = toArray(publicKeys);
|
checkMessage(message); publicKeys = toArray(publicKeys); privateKeys = toArray(privateKeys); passwords = toArray(passwords);
|
||||||
|
|
||||||
if (!nativeAEAD() && asyncProxy) { // use web worker if web crypto apis are not supported
|
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);
|
const result = parseMessage(message, format);
|
||||||
|
|
||||||
if (!publicKeys) {
|
if (!publicKeys) {
|
||||||
publicKeys = [];
|
publicKeys = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signature) {
|
if (signature) {
|
||||||
//detached signature
|
//detached signature
|
||||||
result.signatures = await message.verifyDetached(signature, publicKeys);
|
result.signatures = await message.verifyDetached(signature, publicKeys);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user