jose-node-cjs-runtime
Advanced tools
Comparing version 4.9.2 to 4.9.3
@@ -5,7 +5,7 @@ "use strict"; | ||
const is_key_like_js_1 = require("../runtime/is_key_like.js"); | ||
const symmetricTypeCheck = (key) => { | ||
const symmetricTypeCheck = (alg, key) => { | ||
if (key instanceof Uint8Array) | ||
return; | ||
if (!(0, is_key_like_js_1.default)(key)) { | ||
throw new TypeError((0, invalid_key_input_js_1.default)(key, ...is_key_like_js_1.types, 'Uint8Array')); | ||
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types, 'Uint8Array')); | ||
} | ||
@@ -16,5 +16,5 @@ if (key.type !== 'secret') { | ||
}; | ||
const asymmetricTypeCheck = (key, usage) => { | ||
const asymmetricTypeCheck = (alg, key, usage) => { | ||
if (!(0, is_key_like_js_1.default)(key)) { | ||
throw new TypeError((0, invalid_key_input_js_1.default)(key, ...is_key_like_js_1.types)); | ||
throw new TypeError((0, invalid_key_input_js_1.withAlg)(alg, key, ...is_key_like_js_1.types)); | ||
} | ||
@@ -43,8 +43,8 @@ if (key.type === 'secret') { | ||
if (symmetric) { | ||
symmetricTypeCheck(key); | ||
symmetricTypeCheck(alg, key); | ||
} | ||
else { | ||
asymmetricTypeCheck(key, usage); | ||
asymmetricTypeCheck(alg, key, usage); | ||
} | ||
}; | ||
exports.default = checkKeyType; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (actual, ...types) => { | ||
let msg = 'Key must be '; | ||
exports.withAlg = void 0; | ||
function message(msg, actual, ...types) { | ||
if (types.length > 2) { | ||
@@ -27,2 +27,9 @@ const last = types.pop(); | ||
return msg; | ||
} | ||
exports.default = (actual, ...types) => { | ||
return message('Key must be ', actual, ...types); | ||
}; | ||
function withAlg(alg, actual, ...types) { | ||
return message(`Key for the ${alg} algorithm must be `, actual, ...types); | ||
} | ||
exports.withAlg = withAlg; |
@@ -22,4 +22,5 @@ "use strict"; | ||
if (cek instanceof Uint8Array) { | ||
if (cek.length << 3 !== expected) { | ||
throw new errors_js_1.JWEInvalid('Invalid Content Encryption Key length'); | ||
const actual = cek.byteLength << 3; | ||
if (actual !== expected) { | ||
throw new errors_js_1.JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`); | ||
} | ||
@@ -29,4 +30,5 @@ return; | ||
if ((0, is_key_object_js_1.default)(cek) && cek.type === 'secret') { | ||
if (cek.symmetricKeySize << 3 !== expected) { | ||
throw new errors_js_1.JWEInvalid('Invalid Content Encryption Key length'); | ||
const actual = cek.symmetricKeySize << 3; | ||
if (actual !== expected) { | ||
throw new errors_js_1.JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`); | ||
} | ||
@@ -33,0 +35,0 @@ return; |
@@ -23,4 +23,4 @@ /** | ||
* [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a | ||
* key/secret available in the Browser and Deno runtimes. In addition to the import functions of | ||
* this library you may use the | ||
* key/secret available in the Browser and Web-interoperable runtimes. In addition to the import | ||
* functions of this library you may use the | ||
* [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey) | ||
@@ -27,0 +27,0 @@ * API to obtain a CryptoKey from your existing key material. |
{ | ||
"name": "jose-node-cjs-runtime", | ||
"version": "4.9.2", | ||
"version": "4.9.3", | ||
"homepage": "https://github.com/panva/jose", | ||
@@ -5,0 +5,0 @@ "repository": "panva/jose", |
259447
6284