UNPKG

@unvision/jose

Version:

Implementation of the RFCs of the JOSE Working Group.

53 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dir = void 0; const invalid_jsonwebencryption_exception_1 = require("../../../exceptions/invalid-jsonwebencryption.exception"); const jsonwebencryption_key_wrap_algorithm_1 = require("./jsonwebencryption-key-wrap.algorithm"); /** * Implementation of the JSON Web Encryption Direct Key Wrap Algorithm. * * @see https://www.rfc-editor.org/rfc/rfc7518.html#section-4.5 */ class DirAlgorithm extends jsonwebencryption_key_wrap_algorithm_1.JsonWebEncryptionKeyWrapAlgorithm { /** * Instantiates a new JSON Web Encryption Direct Key Wrap Algorithm to Wrap and Unwrap Content Encryption Keys. */ constructor() { super('dir', 'oct'); } /** * Returns an empty Buffer as the Wrapped Key since the Algorithm does not Wrap the provided Content Encryption Key. * * @param enc JSON Web Encryption Content Encryption Algorithm. * @param key JSON Web Key to be used as the Content Encryption Key used to Encrypt the Plaintext. * @returns Wrap Key as the Content Encryption Key and an empty Buffer as the Wrapped Content Encryption Key. */ async wrap(enc, key) { this.validateJsonWebKey(key); const cek = key['cryptoKey'].export(); const ek = Buffer.alloc(0); enc.validateContentEncryptionKey(cek); return [cek, ek]; } /** * Returns the provided JSON Web Key as the Content Encryption Key. * * @param enc JSON Web Encryption Content Encryption Algorithm. * @param key JSON Web Key used as the Content Encryption Key. * @param ek ~Wrapped Content Encryption Key~. * @returns Provided JSON Web Key as the Content Encryption Key. */ async unwrap(enc, key, ek) { if (ek.length !== 0) { throw new invalid_jsonwebencryption_exception_1.InvalidJsonWebEncryptionException('Expected the Encrypted Content Encryption Key to be empty.'); } const cek = key['cryptoKey'].export(); enc.validateContentEncryptionKey(cek); return cek; } } /** * Direct use of a shared symmetric key as the CEK. */ exports.dir = new DirAlgorithm(); //# sourceMappingURL=dir.algorithm.js.map