From 735a2774653b6e5e08c594f55bb2d65deeca6805 Mon Sep 17 00:00:00 2001 From: sanderPostma Date: Wed, 28 Aug 2024 20:33:51 +0200 Subject: [PATCH] chore: sanitizedAlgorithm --- packages/common/lib/hasher.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/common/lib/hasher.ts b/packages/common/lib/hasher.ts index 4a7e3d61..2b1d4c2b 100644 --- a/packages/common/lib/hasher.ts +++ b/packages/common/lib/hasher.ts @@ -5,12 +5,13 @@ const supportedAlgorithms = ['sha256', 'sha384', 'sha512'] as const; type SupportedAlgorithms = (typeof supportedAlgorithms)[number]; export const defaultHasher: Hasher = (data, algorithm) => { - if (!supportedAlgorithms.includes(algorithm as SupportedAlgorithms)) { + const sanitizedAlgorithm = algorithm.toLowerCase().replace(/[-_]/g, '') + if (!supportedAlgorithms.includes(sanitizedAlgorithm as SupportedAlgorithms)) { throw new Error(`Unsupported hashing algorithm ${algorithm}`); } return new Uint8Array( - sha(algorithm as SupportedAlgorithms) + sha(sanitizedAlgorithm as SupportedAlgorithms) .update(data) .digest(), );