mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
27 lines
1 KiB
JavaScript
27 lines
1 KiB
JavaScript
import { isCloudflareWorkers, isNodeJs } from './global.js';
|
|
import { JOSENotSupported } from '../util/errors.js';
|
|
export default function subtleDsa(alg, namedCurve) {
|
|
const length = parseInt(alg.substr(-3), 10);
|
|
switch (alg) {
|
|
case 'HS256':
|
|
case 'HS384':
|
|
case 'HS512':
|
|
return { hash: `SHA-${length}`, name: 'HMAC' };
|
|
case 'PS256':
|
|
case 'PS384':
|
|
case 'PS512':
|
|
return { hash: `SHA-${length}`, name: 'RSA-PSS', saltLength: length >> 3 };
|
|
case 'RS256':
|
|
case 'RS384':
|
|
case 'RS512':
|
|
return { hash: `SHA-${length}`, name: 'RSASSA-PKCS1-v1_5' };
|
|
case 'ES256':
|
|
case 'ES384':
|
|
case 'ES512':
|
|
return { hash: `SHA-${length}`, name: 'ECDSA', namedCurve };
|
|
case (isCloudflareWorkers() || isNodeJs()) && 'EdDSA':
|
|
return { name: namedCurve, namedCurve };
|
|
default:
|
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
}
|
|
}
|