jose-node-esm-runtime
Advanced tools
Comparing version 4.9.2 to 4.9.3
@@ -1,8 +0,8 @@ | ||
import invalidKeyInput from './invalid_key_input.js'; | ||
import { withAlg as invalidKeyInput } from './invalid_key_input.js'; | ||
import isKeyLike, { types } from '../runtime/is_key_like.js'; | ||
const symmetricTypeCheck = (key) => { | ||
const symmetricTypeCheck = (alg, key) => { | ||
if (key instanceof Uint8Array) | ||
return; | ||
if (!isKeyLike(key)) { | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(alg, key, ...types, 'Uint8Array')); | ||
} | ||
@@ -13,5 +13,5 @@ if (key.type !== 'secret') { | ||
}; | ||
const asymmetricTypeCheck = (key, usage) => { | ||
const asymmetricTypeCheck = (alg, key, usage) => { | ||
if (!isKeyLike(key)) { | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
throw new TypeError(invalidKeyInput(alg, key, ...types)); | ||
} | ||
@@ -40,8 +40,8 @@ if (key.type === 'secret') { | ||
if (symmetric) { | ||
symmetricTypeCheck(key); | ||
symmetricTypeCheck(alg, key); | ||
} | ||
else { | ||
asymmetricTypeCheck(key, usage); | ||
asymmetricTypeCheck(alg, key, usage); | ||
} | ||
}; | ||
export default checkKeyType; |
@@ -1,3 +0,2 @@ | ||
export default (actual, ...types) => { | ||
let msg = 'Key must be '; | ||
function message(msg, actual, ...types) { | ||
if (types.length > 2) { | ||
@@ -25,2 +24,8 @@ const last = types.pop(); | ||
return msg; | ||
} | ||
export default (actual, ...types) => { | ||
return message('Key must be ', actual, ...types); | ||
}; | ||
export function withAlg(alg, actual, ...types) { | ||
return message(`Key for the ${alg} algorithm must be `, actual, ...types); | ||
} |
@@ -20,4 +20,5 @@ import { JWEInvalid, JOSENotSupported } from '../util/errors.js'; | ||
if (cek instanceof Uint8Array) { | ||
if (cek.length << 3 !== expected) { | ||
throw new JWEInvalid('Invalid Content Encryption Key length'); | ||
const actual = cek.byteLength << 3; | ||
if (actual !== expected) { | ||
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`); | ||
} | ||
@@ -27,4 +28,5 @@ return; | ||
if (isKeyObject(cek) && cek.type === 'secret') { | ||
if (cek.symmetricKeySize << 3 !== expected) { | ||
throw new JWEInvalid('Invalid Content Encryption Key length'); | ||
const actual = cek.symmetricKeySize << 3; | ||
if (actual !== expected) { | ||
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`); | ||
} | ||
@@ -31,0 +33,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-esm-runtime", | ||
"version": "4.9.2", | ||
"version": "4.9.3", | ||
"homepage": "https://github.com/panva/jose", | ||
@@ -5,0 +5,0 @@ "repository": "panva/jose", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232653
5933