jose-node-esm-runtime
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -11,14 +11,9 @@ import { FlattenedEncrypt, unprotected } from '../flattened/encrypt.js'; | ||
setUnprotectedHeader(unprotectedHeader) { | ||
if (this._unprotectedHeader) { | ||
const ref = recipientRef.get(this); | ||
if (ref.unprotectedHeader) { | ||
throw new TypeError('setUnprotectedHeader can only be called once'); | ||
} | ||
this._unprotectedHeader = unprotectedHeader; | ||
ref.unprotectedHeader = unprotectedHeader; | ||
return this; | ||
} | ||
set _unprotectedHeader(value) { | ||
recipientRef.get(this).unprotectedHeader = value; | ||
} | ||
get _unprotectedHeader() { | ||
return recipientRef.get(this).unprotectedHeader; | ||
} | ||
} | ||
@@ -25,0 +20,0 @@ export class GeneralEncrypt { |
@@ -6,27 +6,17 @@ import { FlattenedSign } from '../flattened/sign.js'; | ||
setProtectedHeader(protectedHeader) { | ||
if (this._protectedHeader) { | ||
const ref = signatureRef.get(this); | ||
if (ref.protectedHeader) { | ||
throw new TypeError('setProtectedHeader can only be called once'); | ||
} | ||
this._protectedHeader = protectedHeader; | ||
ref.protectedHeader = protectedHeader; | ||
return this; | ||
} | ||
setUnprotectedHeader(unprotectedHeader) { | ||
if (this._unprotectedHeader) { | ||
const ref = signatureRef.get(this); | ||
if (ref.unprotectedHeader) { | ||
throw new TypeError('setUnprotectedHeader can only be called once'); | ||
} | ||
this._unprotectedHeader = unprotectedHeader; | ||
ref.unprotectedHeader = unprotectedHeader; | ||
return this; | ||
} | ||
set _protectedHeader(value) { | ||
signatureRef.get(this).protectedHeader = value; | ||
} | ||
get _protectedHeader() { | ||
return signatureRef.get(this).protectedHeader; | ||
} | ||
set _unprotectedHeader(value) { | ||
signatureRef.get(this).unprotectedHeader = value; | ||
} | ||
get _unprotectedHeader() { | ||
return signatureRef.get(this).unprotectedHeader; | ||
} | ||
} | ||
@@ -33,0 +23,0 @@ export class GeneralSign { |
@@ -5,2 +5,7 @@ import { JOSENotSupported } from '../util/errors.js'; | ||
switch (alg) { | ||
case 'A128GCM': | ||
return 128; | ||
case 'A192GCM': | ||
return 192; | ||
case 'A256GCM': | ||
case 'A128CBC-HS256': | ||
@@ -12,8 +17,2 @@ return 256; | ||
return 512; | ||
case 'A128GCM': | ||
return 128; | ||
case 'A192GCM': | ||
return 192; | ||
case 'A256GCM': | ||
return 256; | ||
default: | ||
@@ -20,0 +19,0 @@ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); |
@@ -43,3 +43,3 @@ import { unwrap as aesKw } from '../runtime/aeskw.js'; | ||
} | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLength(joseHeader.enc), partyUInfo, partyVInfo); | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.substr(-5, 3), 10), partyUInfo, partyVInfo); | ||
if (alg === 'ECDH-ES') | ||
@@ -46,0 +46,0 @@ return sharedSecret; |
@@ -32,3 +32,3 @@ import { wrap as aesKw } from '../runtime/aeskw.js'; | ||
const { x, y, crv, kty } = await exportJWK(ephemeralKey); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, parseInt(alg.substr(-5, 3), 10) || cekLength(enc), apu, apv); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.substr(-5, 3), 10), apu, apv); | ||
parameters = { epk: { x, y, crv, kty } }; | ||
@@ -35,0 +35,0 @@ if (apu) |
@@ -5,20 +5,13 @@ import { JOSENotSupported } from '../util/errors.js'; | ||
switch (alg) { | ||
case 'A128CBC-HS256': | ||
return 128; | ||
case 'A128GCM': | ||
return 96; | ||
case 'A128GCMKW': | ||
return 96; | ||
case 'A192CBC-HS384': | ||
return 128; | ||
case 'A192GCM': | ||
return 96; | ||
case 'A192GCMKW': | ||
case 'A256GCM': | ||
case 'A256GCMKW': | ||
return 96; | ||
case 'A128CBC-HS256': | ||
case 'A192CBC-HS384': | ||
case 'A256CBC-HS512': | ||
return 128; | ||
case 'A256GCM': | ||
return 96; | ||
case 'A256GCMKW': | ||
return 96; | ||
default: | ||
@@ -25,0 +18,0 @@ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); |
@@ -11,2 +11,3 @@ import { Buffer } from 'buffer'; | ||
import supported from './ciphers.js'; | ||
import { types } from './is_key_like.js'; | ||
function checkKeySize(key, alg) { | ||
@@ -28,5 +29,5 @@ if (key.symmetricKeySize << 3 !== parseInt(alg.substr(1, 3), 10)) { | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
export const wrap = async (alg, key, cek) => { | ||
export const wrap = (alg, key, cek) => { | ||
const size = parseInt(alg.substr(1, 3), 10); | ||
@@ -42,3 +43,3 @@ const algorithm = `aes${size}-wrap`; | ||
}; | ||
export const unwrap = async (alg, key, encryptedKey) => { | ||
export const unwrap = (alg, key, encryptedKey) => { | ||
const size = parseInt(alg.substr(1, 3), 10); | ||
@@ -45,0 +46,0 @@ const algorithm = `aes${size}-wrap`; |
@@ -6,2 +6,3 @@ import { createPrivateKey, createPublicKey, KeyObject } from 'crypto'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const genericExport = (keyType, keyFormat, key) => { | ||
@@ -19,3 +20,3 @@ let keyObject; | ||
else { | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -22,0 +23,0 @@ if (keyObject.type !== keyType) { |
@@ -13,3 +13,4 @@ import { createDecipheriv, KeyObject } from 'crypto'; | ||
import supported from './ciphers.js'; | ||
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
import { types } from './is_key_like.js'; | ||
function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
@@ -48,3 +49,3 @@ if (isKeyObject(cek)) { | ||
} | ||
async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
@@ -69,3 +70,3 @@ const algorithm = `aes-${keySize}-gcm`; | ||
} | ||
const decrypt = async (enc, cek, ciphertext, iv, tag, aad) => { | ||
const decrypt = (enc, cek, ciphertext, iv, tag, aad) => { | ||
let key; | ||
@@ -80,3 +81,3 @@ if (isCryptoKey(cek)) { | ||
else { | ||
throw new TypeError(invalidKeyInput(cek, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array')); | ||
} | ||
@@ -83,0 +84,0 @@ checkCekLength(enc, key); |
@@ -11,4 +11,5 @@ import { diffieHellman, generateKeyPair as generateKeyPairCb, KeyObject } from 'crypto'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const generateKeyPair = promisify(generateKeyPairCb); | ||
export const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => { | ||
export const deriveKey = (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => { | ||
let publicKey; | ||
@@ -23,3 +24,3 @@ if (isCryptoKey(publicKee)) { | ||
else { | ||
throw new TypeError(invalidKeyInput(publicKee, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(publicKee, ...types)); | ||
} | ||
@@ -35,3 +36,3 @@ let privateKey; | ||
else { | ||
throw new TypeError(invalidKeyInput(privateKee, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(privateKee, ...types)); | ||
} | ||
@@ -51,3 +52,3 @@ const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength)); | ||
else { | ||
throw new TypeError(invalidKeyInput(kee, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(kee, ...types)); | ||
} | ||
@@ -54,0 +55,0 @@ switch (key.asymmetricKeyType) { |
@@ -12,3 +12,4 @@ import { createCipheriv, KeyObject } from 'crypto'; | ||
import supported from './ciphers.js'; | ||
async function cbcEncrypt(enc, plaintext, cek, iv, aad) { | ||
import { types } from './is_key_like.js'; | ||
function cbcEncrypt(enc, plaintext, cek, iv, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
@@ -30,3 +31,3 @@ if (isKeyObject(cek)) { | ||
} | ||
async function gcmEncrypt(enc, plaintext, cek, iv, aad) { | ||
function gcmEncrypt(enc, plaintext, cek, iv, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
@@ -46,3 +47,3 @@ const algorithm = `aes-${keySize}-gcm`; | ||
} | ||
const encrypt = async (enc, plaintext, cek, iv, aad) => { | ||
const encrypt = (enc, plaintext, cek, iv, aad) => { | ||
let key; | ||
@@ -57,3 +58,3 @@ if (isCryptoKey(cek)) { | ||
else { | ||
throw new TypeError(invalidKeyInput(cek, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array')); | ||
} | ||
@@ -60,0 +61,0 @@ checkCekLength(enc, key); |
@@ -7,2 +7,3 @@ import { Buffer } from 'buffer'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const p256 = Buffer.from([42, 134, 72, 206, 61, 3, 1, 7]); | ||
@@ -37,3 +38,3 @@ const p384 = Buffer.from([43, 129, 4, 0, 34]); | ||
else { | ||
throw new TypeError(invalidKeyInput(kee, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(kee, ...types)); | ||
} | ||
@@ -40,0 +41,0 @@ if (key.type === 'secret') { |
@@ -6,6 +6,7 @@ import { KeyObject } from 'crypto'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
export default function getSignVerifyKey(alg, key, usage) { | ||
if (key instanceof Uint8Array) { | ||
if (!alg.startsWith('HS')) { | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
@@ -21,3 +22,3 @@ return getSecretKey(key); | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} |
@@ -9,2 +9,3 @@ import { KeyObject, createPublicKey } from 'crypto'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const [major, minor] = process.version | ||
@@ -33,3 +34,3 @@ .substr(1) | ||
else { | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
@@ -36,0 +37,0 @@ if (jwkExportSupported) { |
@@ -12,2 +12,3 @@ import { promisify } from 'util'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const pbkdf2 = promisify(pbkdf2cb); | ||
@@ -25,3 +26,3 @@ function getPassword(key, alg) { | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey', 'Uint8Array')); | ||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array')); | ||
} | ||
@@ -28,0 +29,0 @@ export const encrypt = async (alg, key, cek, p2c = Math.floor(Math.random() * 2049) + 2048, p2s = random(new Uint8Array(16))) => { |
@@ -7,2 +7,3 @@ import { KeyObject, publicEncrypt, constants, privateDecrypt } from 'crypto'; | ||
import invalidKeyInput from '../lib/invalid_key_input.js'; | ||
import { types } from './is_key_like.js'; | ||
const checkKey = (key, alg) => { | ||
@@ -49,5 +50,5 @@ if (key.asymmetricKeyType !== 'rsa') { | ||
} | ||
throw new TypeError(invalidKeyInput(key, 'KeyObject', 'CryptoKey')); | ||
throw new TypeError(invalidKeyInput(key, ...types)); | ||
} | ||
export const encrypt = async (alg, key, cek) => { | ||
export const encrypt = (alg, key, cek) => { | ||
const padding = resolvePadding(alg); | ||
@@ -59,3 +60,3 @@ const oaepHash = resolveOaepHash(alg); | ||
}; | ||
export const decrypt = async (alg, key, encryptedKey) => { | ||
export const decrypt = (alg, key, encryptedKey) => { | ||
const padding = resolvePadding(alg); | ||
@@ -62,0 +63,0 @@ const oaepHash = resolveOaepHash(alg); |
{ | ||
"name": "jose-node-esm-runtime", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"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
175961
4416