summaryrefslogtreecommitdiff
path: root/std/jwt/_signature.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/jwt/_signature.ts')
-rw-r--r--std/jwt/_signature.ts63
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));
-}