summaryrefslogtreecommitdiff
path: root/std/jwt/_algorithm.ts
blob: c9c5257e10c722e9cf9fee4b35fedd27cc3c2c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * JSW §1: Cryptographic algorithms and identifiers for use with this specification
 * are described in the separate JSON Web Algorithms (JWA) specification:
 * https://www.rfc-editor.org/rfc/rfc7518
 */
export type Algorithm = "none" | "HS256" | "HS512";
export type AlgorithmInput = Algorithm | Array<Exclude<Algorithm, "none">>;
/**
 * Verify the algorithm
 * @param algorithm as string or multiple algorithms in an array excluding 'none'
 * @param the algorithm from the jwt header
 */
export function verify(algorithm: AlgorithmInput, jwtAlg: string): boolean {
  return Array.isArray(algorithm)
    ? (algorithm as string[]).includes(jwtAlg)
    : algorithm === jwtAlg;
}