From ebdb0f61068f0e3356441fb48e24203c0ea1cab7 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:49:01 -0800 Subject: [PATCH] chore(middleware-flexible-checksums): use switch for selecting checksum algorithm function (#6741) --- .../src/selectChecksumAlgorithmFunction.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.ts b/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.ts index 74a09add4a30..a06fea4feee8 100644 --- a/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.ts +++ b/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.ts @@ -11,11 +11,19 @@ import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFu export const selectChecksumAlgorithmFunction = ( checksumAlgorithm: ChecksumAlgorithm, config: PreviouslyResolved -): ChecksumConstructor | HashConstructor => - ({ - [ChecksumAlgorithm.MD5]: config.md5, - [ChecksumAlgorithm.CRC32]: getCrc32ChecksumAlgorithmFunction(), - [ChecksumAlgorithm.CRC32C]: AwsCrc32c, - [ChecksumAlgorithm.SHA1]: config.sha1, - [ChecksumAlgorithm.SHA256]: config.sha256, - }[checksumAlgorithm]); +): ChecksumConstructor | HashConstructor => { + switch (checksumAlgorithm) { + case ChecksumAlgorithm.MD5: + return config.md5; + case ChecksumAlgorithm.CRC32: + return getCrc32ChecksumAlgorithmFunction(); + case ChecksumAlgorithm.CRC32C: + return AwsCrc32c; + case ChecksumAlgorithm.SHA1: + return config.sha1; + case ChecksumAlgorithm.SHA256: + return config.sha256; + default: + throw new Error(`Unsupported checksum algorithm: ${checksumAlgorithm}`); + } +};