@guarani/jose
Version:
Implementation of the RFCs of the JOSE Working Group.
42 lines (41 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEF = void 0;
const util_1 = require("util");
const zlib_1 = require("zlib");
const jsonwebencryption_compression_algorithm_1 = require("./jsonwebencryption-compression.algorithm");
const deflateRawAsync = (0, util_1.promisify)(zlib_1.deflateRaw);
const inflateRawAsync = (0, util_1.promisify)(zlib_1.inflateRaw);
/**
* Implementation of the DEFLATE JSON Web Encryption Compression Algorithm.
*/
class DEFCompressionAlgorithm extends jsonwebencryption_compression_algorithm_1.JsonWebEncryptionCompressionAlgorithm {
/**
* Instantiates a new DEFLATE JSON Web Encryption Compression Algorithm to Compress and Decompress a Plaintext.
*/
constructor() {
super('DEF');
}
/**
* Compresses the provided Plaintext before Encryption.
*
* @param plaintext Plaintext to be Compressed.
* @returns Compressed Plaintext.
*/
async compress(plaintext) {
return await inflateRawAsync(plaintext);
}
/**
* Decompresses the provided Compressed Plaintext after Decryption.
*
* @param plaintext Compressed Plaintext to be Decompressed.
* @returns Decompressed Plaintext.
*/
async decompress(plaintext) {
return await deflateRawAsync(plaintext);
}
}
/**
* JSON Web Encryption **DEFLATE** Compression Algorithm.
*/
exports.DEF = new DEFCompressionAlgorithm();