mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
17 lines
566 B
JavaScript
17 lines
566 B
JavaScript
import { JOSENotSupported } from '../util/errors.js';
|
|
import { maybeJWSAlgorithm } from './jws_algorithms.js';
|
|
import { maybeJWEAlgorithm } from './jwe_algorithms.js';
|
|
function unsupportedAlgorithm() {
|
|
return new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
}
|
|
export function keyAlgorithm(alg) {
|
|
if (typeof alg !== 'string') {
|
|
throw unsupportedAlgorithm();
|
|
}
|
|
const entry = maybeJWSAlgorithm(alg) ?? maybeJWEAlgorithm(alg);
|
|
if (!entry) {
|
|
throw unsupportedAlgorithm();
|
|
}
|
|
return entry;
|
|
}
|