MCPcopy Create free account
hub / github.com/Zaubrik/djwt / getAlgorithm

Function getAlgorithm

algorithm.ts:60–101  ·  view source on GitHub ↗
(alg: Algorithm)

Source from the content-addressed store, hash-verified

58}
59
60export function getAlgorithm(alg: Algorithm) {
61 switch (alg) {
62 case "HS256":
63 return { hash: { name: "SHA-256" }, name: "HMAC" };
64 case "HS384":
65 return { hash: { name: "SHA-384" }, name: "HMAC" };
66 case "HS512":
67 return { hash: { name: "SHA-512" }, name: "HMAC" };
68 case "PS256":
69 return {
70 hash: { name: "SHA-256" },
71 name: "RSA-PSS",
72 saltLength: 256 >> 3,
73 };
74 case "PS384":
75 return {
76 hash: { name: "SHA-384" },
77 name: "RSA-PSS",
78 saltLength: 384 >> 3,
79 };
80 case "PS512":
81 return {
82 hash: { name: "SHA-512" },
83 name: "RSA-PSS",
84 saltLength: 512 >> 3,
85 };
86 case "RS256":
87 return { hash: { name: "SHA-256" }, name: "RSASSA-PKCS1-v1_5" };
88 case "RS384":
89 return { hash: { name: "SHA-384" }, name: "RSASSA-PKCS1-v1_5" };
90 case "RS512":
91 return { hash: { name: "SHA-512" }, name: "RSASSA-PKCS1-v1_5" };
92 case "ES256":
93 return { hash: { name: "SHA-256" }, name: "ECDSA", namedCurve: "P-256" };
94 case "ES384":
95 return { hash: { name: "SHA-384" }, name: "ECDSA", namedCurve: "P-384" };
96 // case "ES512":
97 // return { hash: { name: "SHA-512" }, name: "ECDSA", namedCurve: "P-521" };
98 default:
99 throw new Error(`The jwt's alg '${alg}' is not supported.`);
100 }
101}

Callers 3

verifyFunction · 0.90
createFunction · 0.90
verifyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected