@unvision/jose
Version:
Implementation of the RFCs of the JOSE Working Group.
53 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEF = void 0;
const util_1 = require("util");
const zlib_1 = require("zlib");
const invalid_jsonwebencryption_exception_1 = require("../../../exceptions/invalid-jsonwebencryption.exception");
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 DefAlgorithm 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) {
try {
return await deflateRawAsync(plaintext);
}
catch (exc) {
throw new invalid_jsonwebencryption_exception_1.InvalidJsonWebEncryptionException(null, exc);
}
}
/**
* Decompresses the provided Compressed Plaintext after Decryption.
*
* @param plaintext Compressed Plaintext to be Decompressed.
* @returns Decompressed Plaintext.
*/
async decompress(plaintext) {
try {
return await inflateRawAsync(plaintext);
}
catch (exc) {
throw new invalid_jsonwebencryption_exception_1.InvalidJsonWebEncryptionException(null, exc);
}
}
}
/**
* JSON Web Encryption **DEFLATE** Compression Algorithm.
*/
exports.DEF = new DefAlgorithm();
//# sourceMappingURL=def.algorithm.js.map