jose-node-esm-runtime
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -23,3 +23,3 @@ import { Buffer } from 'buffer'; | ||
if (isCryptoKey(key)) { | ||
return getKeyObject(key, alg, new Set([usage])); | ||
return getKeyObject(key, alg, usage); | ||
} | ||
@@ -26,0 +26,0 @@ throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); |
@@ -67,3 +67,3 @@ import { createDecipheriv } from 'crypto'; | ||
if (isCryptoKey(cek)) { | ||
key = getKeyObject(cek, enc, new Set(['decrypt'])); | ||
key = getKeyObject(cek, enc, 'decrypt'); | ||
} | ||
@@ -70,0 +70,0 @@ else if (cek instanceof Uint8Array || isKeyObject(cek)) { |
@@ -24,3 +24,3 @@ import { diffieHellman, generateKeyPair as generateKeyPairCb } from 'crypto'; | ||
if (isCryptoKey(privateKee)) { | ||
privateKey = getKeyObject(privateKee, 'ECDH-ES', new Set(['deriveBits', 'deriveKey'])); | ||
privateKey = getKeyObject(privateKee, 'ECDH-ES', 'deriveBits', 'deriveKey'); | ||
} | ||
@@ -27,0 +27,0 @@ else if (isKeyObject(privateKee)) { |
@@ -45,3 +45,3 @@ import { createCipheriv } from 'crypto'; | ||
if (isCryptoKey(cek)) { | ||
key = getKeyObject(cek, enc, new Set(['encrypt'])); | ||
key = getKeyObject(cek, enc, 'encrypt'); | ||
} | ||
@@ -48,0 +48,0 @@ else if (cek instanceof Uint8Array || isKeyObject(cek)) { |
@@ -16,5 +16,5 @@ import * as crypto from 'crypto'; | ||
if (isCryptoKey(key)) { | ||
return getKeyObject(key, alg, new Set([usage])); | ||
return getKeyObject(key, alg, usage); | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
} |
@@ -20,3 +20,3 @@ import { promisify } from 'util'; | ||
if (isCryptoKey(key)) { | ||
return getKeyObject(key, alg, new Set(['deriveBits', 'deriveKey'])).export(); | ||
return getKeyObject(key, alg, 'deriveBits', 'deriveKey').export(); | ||
} | ||
@@ -23,0 +23,0 @@ throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); |
@@ -44,3 +44,3 @@ import { publicEncrypt, constants, privateDecrypt } from 'crypto'; | ||
if (isCryptoKey(key)) { | ||
return getKeyObject(key, alg, new Set(usages)); | ||
return getKeyObject(key, alg, ...usages); | ||
} | ||
@@ -47,0 +47,0 @@ throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey')); |
@@ -22,3 +22,3 @@ import * as crypto from 'crypto'; | ||
} | ||
export function getKeyObject(key, alg, usage) { | ||
export function checkCryptoKey(key, alg, ...usages) { | ||
switch (alg) { | ||
@@ -140,4 +140,3 @@ case undefined: | ||
} | ||
if (usage && !key.usages.find(Set.prototype.has.bind(usage))) { | ||
const usages = [...usage]; | ||
if (usages.length && !usages.some((expected) => key.usages.includes(expected))) { | ||
let msg = 'CryptoKey does not support this operation, its usages must include '; | ||
@@ -152,7 +151,10 @@ if (usages.length > 2) { | ||
else { | ||
msg += ` ${usages[0]}.`; | ||
msg += `${usages[0]}.`; | ||
} | ||
throw new TypeError(msg); | ||
} | ||
} | ||
export function getKeyObject(key, alg, ...usages) { | ||
checkCryptoKey(key, alg, ...usages); | ||
return crypto.KeyObject.from(key); | ||
} |
{ | ||
"name": "jose-node-esm-runtime", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "(Node.JS ESM Runtime) 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
167614
4213