Add compression support for the encrypt function
This commit is contained in:
parent
90337debfb
commit
9f7466ef45
|
@ -31,7 +31,7 @@ export default {
|
|||
/** @property {Integer} encryption_cipher Default encryption cipher {@link module:enums.symmetric} */
|
||||
encryption_cipher: enums.symmetric.aes256,
|
||||
/** @property {Integer} compression Default compression algorithm {@link module:enums.compression} */
|
||||
compression: enums.compression.zip,
|
||||
compression: enums.compression.uncompressed,
|
||||
|
||||
/**
|
||||
* Use Authenticated Encryption with Additional Data (AEAD) protection for symmetric encryption.
|
||||
|
|
|
@ -451,6 +451,26 @@ Message.prototype.sign = async function(privateKeys=[], signature=null) {
|
|||
return new Message(packetlist);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compresses the message (the literal and -if signed- signature data packets of the message)
|
||||
* @param {module:enums.compression} compression compression algorithm to be used
|
||||
* @return {module:message~Message} new message with signed content
|
||||
*/
|
||||
Message.prototype.compress = function(compression) {
|
||||
if (compression === enums.compression.uncompressed) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const compressed = new packet.Compressed();
|
||||
compressed.packets = this.packets;
|
||||
compressed.algorithm = enums.read(enums.compression, compression);
|
||||
|
||||
const packetList = new packet.List();
|
||||
packetList.push(compressed);
|
||||
|
||||
return new Message(packetList);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a detached signature for the message (the literal data packet of the message)
|
||||
* @param {Array<module:key~Key>} privateKey private keys with decrypted secret key data for signing
|
||||
|
|
|
@ -192,6 +192,7 @@ export function decryptKey({ privateKey, passphrase }) {
|
|||
* @param {String|Array<String>} passwords (optional) array of passwords or a single password to encrypt the message
|
||||
* @param {Object} sessionKey (optional) session key in the form: { data:Uint8Array, algorithm:String }
|
||||
* @param {String} filename (optional) a filename for the literal data packet
|
||||
* @param {Boolean} compression (optional) which compression algorithm to compress the message with, defaults to what is specified in config
|
||||
* @param {Boolean} armor (optional) if the return values should be ascii armored or the message/signature objects
|
||||
* @param {Boolean} detached (optional) if the signature should be detached (if true, signature will be added to returned object)
|
||||
* @param {Signature} signature (optional) a detached signature to add to the encrypted message
|
||||
|
@ -202,7 +203,7 @@ export function decryptKey({ privateKey, passphrase }) {
|
|||
* message: full Message object if 'armor' is false, signature: detached signature if 'detached' is true}
|
||||
* @static
|
||||
*/
|
||||
export function encrypt({ data, publicKeys, privateKeys, passwords, sessionKey, filename, armor=true, detached=false, signature=null, returnSessionKey=false, wildcard=false}) {
|
||||
export function encrypt({ data, publicKeys, privateKeys, passwords, sessionKey, filename, compression=config.compression, armor=true, detached=false, signature=null, returnSessionKey=false, wildcard=false}) {
|
||||
checkData(data); publicKeys = toArray(publicKeys); privateKeys = toArray(privateKeys); passwords = toArray(passwords);
|
||||
|
||||
if (!nativeAEAD() && asyncProxy) { // use web worker if web crypto apis are not supported
|
||||
|
@ -223,6 +224,7 @@ export function encrypt({ data, publicKeys, privateKeys, passwords, sessionKey,
|
|||
message = await message.sign(privateKeys, signature);
|
||||
}
|
||||
}
|
||||
message = message.compress(compression);
|
||||
return message.encrypt(publicKeys, passwords, sessionKey, wildcard);
|
||||
|
||||
}).then(encrypted => {
|
||||
|
|
|
@ -88,7 +88,7 @@ Compressed.prototype.write = function () {
|
|||
this.compress();
|
||||
}
|
||||
|
||||
return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed);
|
||||
return util.concatUint8Array([new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed]);
|
||||
};
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user