diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-10-26 23:10:48 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 08:10:48 -0400 |
commit | 78429496e0625a68ccfdd215c7e240eddb3b5b66 (patch) | |
tree | 6dc8d84116e201da44390d4b97b2ca06c8196309 /std/jwt/_signature.ts | |
parent | 822e5b653685d539c492b87cf5ae77d0223d9b32 (diff) |
revert new std/jwt module so issues can be addressed (#8127)
This reverts commit aa0e64b5794e4515d5e1911107ba54ce7e0dcc3c.
This reverts commit 034ab48086557af00216ffe311c71ad4eb0ec4d5.
Diffstat (limited to 'std/jwt/_signature.ts')
-rw-r--r-- | std/jwt/_signature.ts | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/std/jwt/_signature.ts b/std/jwt/_signature.ts deleted file mode 100644 index 81c1309d1..000000000 --- a/std/jwt/_signature.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Algorithm } from "./_algorithm.ts"; -import { HmacSha256 } from "../hash/sha256.ts"; -import { HmacSha512 } from "../hash/sha512.ts"; -import { encode as convertUint8ArrayToBase64url } from "../encoding/base64url.ts"; -import { decodeString as convertHexToUint8Array } from "../encoding/hex.ts"; - -export function convertHexToBase64url(input: string): string { - return convertUint8ArrayToBase64url(convertHexToUint8Array(input)); -} - -function encrypt( - algorithm: Algorithm, - key: string, - message: string, -): string { - switch (algorithm) { - case "none": - return ""; - case "HS256": - return new HmacSha256(key).update(message).toString(); - case "HS512": - return new HmacSha512(key).update(message).toString(); - default: - throw new RangeError( - `The algorithm of '${algorithm}' in the header is not supported.`, - ); - } -} - -/** - * Create a signature - * @param algorithm - * @param key - * @param input - */ -export async function create( - algorithm: Algorithm, - key: string, - input: string, -): Promise<string> { - return convertHexToBase64url(await encrypt(algorithm, key, input)); -} - -/** - * Verify a signature - * @param signature - * @param key - * @param alg - * @param signingInput - */ -export async function verify({ - signature, - key, - algorithm, - signingInput, -}: { - signature: string; - key: string; - algorithm: Algorithm; - signingInput: string; -}): Promise<boolean> { - return signature === (await encrypt(algorithm, key, signingInput)); -} |