blob: be5527478bc2eb28f785ba172bed1742b8390dfc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import { COSEALG } from '../../cose.ts';
import { SubtleCryptoKeyAlgName } from './structs.ts';
/**
* Convert a COSE alg ID into a corresponding key algorithm string value that WebCrypto APIs expect
*/
export function mapCoseAlgToWebCryptoKeyAlgName(
alg: COSEALG,
): SubtleCryptoKeyAlgName {
if ([COSEALG.EdDSA].indexOf(alg) >= 0) {
return 'Ed25519';
} else if (
[COSEALG.ES256, COSEALG.ES384, COSEALG.ES512, COSEALG.ES256K].indexOf(
alg,
) >= 0
) {
return 'ECDSA';
} else if (
[COSEALG.RS256, COSEALG.RS384, COSEALG.RS512, COSEALG.RS1].indexOf(alg) >= 0
) {
return 'RSASSA-PKCS1-v1_5';
} else if ([COSEALG.PS256, COSEALG.PS384, COSEALG.PS512].indexOf(alg) >= 0) {
return 'RSA-PSS';
}
throw new Error(
`Could not map COSE alg value of ${alg} to a WebCrypto key alg name`,
);
}
|