Files
jose/test/jwk/import.test.ts
Filip Skokan 30494d7538 refactor: generate and import keys from the entry
Use algorithm registry entries to supply WebCrypto parameters and key
usages for asymmetric key generation and ASN.1 imports.

Signed-off-by: Filip Skokan <[email protected]>
2026-07-29 18:52:03 +02:00

25 lines
672 B
TypeScript

import test from 'ava'
import {
exportPKCS8,
exportSPKI,
generateKeyPair,
importPKCS8,
importSPKI,
} from '../../src/index.js'
test('PEM imports reject symmetric algorithms', async (t) => {
const { privateKey, publicKey } = await generateKeyPair('ES256', { extractable: true })
const spki = await exportSPKI(publicKey)
const pkcs8 = await exportPKCS8(privateKey)
const expected = {
code: 'ERR_JOSE_NOT_SUPPORTED',
message: 'Invalid or unsupported "alg" (Algorithm) value',
}
for (const alg of ['HS256', 'A128KW']) {
await t.throwsAsync(importSPKI(spki, alg), expected)
await t.throwsAsync(importPKCS8(pkcs8, alg), expected)
}
})