jose/dist/node/cjs/lib/iv.js
2021-10-14 12:24:49 +02:00

25 lines
779 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bitLengths = void 0;
const errors_js_1 = require("../util/errors.js");
const random_js_1 = require("../runtime/random.js");
const bitLengths = new Map([
['A128CBC-HS256', 128],
['A128GCM', 96],
['A128GCMKW', 96],
['A192CBC-HS384', 128],
['A192GCM', 96],
['A192GCMKW', 96],
['A256CBC-HS512', 128],
['A256GCM', 96],
['A256GCMKW', 96],
]);
exports.bitLengths = bitLengths;
const generateIv = (alg) => {
const bitLength = bitLengths.get(alg);
if (!bitLength) {
throw new errors_js_1.JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
}
return (0, random_js_1.default)(new Uint8Array(bitLength >> 3));
};
exports.default = generateIv;