MCPcopy Create free account
hub / github.com/cloudflare/wildebeest / validateAlgorithm

Function validateAlgorithm

backend/src/utils/httpsigjs/utils.ts:33–53  ·  view source on GitHub ↗
(algorithm: string, publicKeyType?: string)

Source from the content-addressed store, hash-verified

31 * @returns {[string, string]}
32 */
33export function validateAlgorithm(algorithm: string, publicKeyType?: string): [string, string] {
34 const alg = algorithm.toLowerCase().split('-')
35
36 if (alg[0] === 'hs2019') {
37 return publicKeyType !== undefined ? validateAlgorithm(publicKeyType + '-sha256') : ['hs2019', 'sha256']
38 }
39
40 if (alg.length !== 2) {
41 throw new InvalidAlgorithmError(alg[0].toUpperCase() + ' is not a ' + 'valid algorithm')
42 }
43
44 if (alg[0] !== 'hmac' && !PK_ALGOS.has(alg[0])) {
45 throw new InvalidAlgorithmError(alg[0].toUpperCase() + ' type keys ' + 'are not supported')
46 }
47
48 if (!HASH_ALGOS.has(alg[1])) {
49 throw new InvalidAlgorithmError(alg[1].toUpperCase() + ' is not a ' + 'supported hash algorithm')
50 }
51
52 return alg as [string, string]
53}

Callers 1

parseRequestFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected