From 6a3a627c4bd74b8e541d9e95a6f4cc3c033b0b8f Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:18:13 +0000 Subject: [PATCH 1/3] chore(middleware-flexible-checksums): move inline class NodeCrc32 outside --- .../src/getCrc32ChecksumAlgorithmFunction.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts b/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts index 3803ccfdedae..ce5521771d74 100644 --- a/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts +++ b/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts @@ -3,26 +3,28 @@ import { numToUint8 } from "@aws-crypto/util"; import { Checksum } from "@smithy/types"; import * as zlib from "zlib"; +class NodeCrc32 implements Checksum { + checksum = 0; + + update(data: Uint8Array) { + // @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0. + this.checksum = zlib.crc32(data, this.checksum); + } + + async digest() { + return numToUint8(this.checksum); + } + + reset() { + this.checksum = 0; + } +} + export const getCrc32ChecksumAlgorithmFunction = () => { // @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0. if (typeof zlib.crc32 === "undefined") { return AwsCrc32; } - return class NodeCrc32 implements Checksum { - checksum = 0; - - update(data: Uint8Array) { - // @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0. - this.checksum = zlib.crc32(data, this.checksum); - } - - async digest() { - return numToUint8(this.checksum); - } - - reset() { - this.checksum = 0; - } - }; + return NodeCrc32; }; From ccab35cd154d7df5fb23a92464e6828ca79bc37e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:27:09 +0000 Subject: [PATCH 2/3] test: enable CRC32 test --- .../src/selectChecksumAlgorithmFunction.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts b/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts index e3c41477aea4..7d1e7b785e81 100644 --- a/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts +++ b/packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts @@ -2,7 +2,7 @@ import { AwsCrc32c } from "@aws-crypto/crc32c"; import { describe, expect, test as it, vi } from "vitest"; import { ChecksumAlgorithm } from "./constants"; -// import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction"; +import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction"; import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction"; describe(selectChecksumAlgorithmFunction.name, () => { @@ -14,7 +14,7 @@ describe(selectChecksumAlgorithmFunction.name, () => { it.each([ [ChecksumAlgorithm.MD5, mockConfig.md5], - // [ChecksumAlgorithm.CRC32, getCrc32ChecksumAlgorithmFunction()], + [ChecksumAlgorithm.CRC32, getCrc32ChecksumAlgorithmFunction()], [ChecksumAlgorithm.CRC32C, AwsCrc32c], [ChecksumAlgorithm.SHA1, mockConfig.sha1], [ChecksumAlgorithm.SHA256, mockConfig.sha256], From 3925f8aa79a0a23bf5227cc21261335dc3091a02 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:29:38 +0000 Subject: [PATCH 3/3] chore: make NodeCrc32.checkum private --- .../src/getCrc32ChecksumAlgorithmFunction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts b/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts index ce5521771d74..92046dfdd7a1 100644 --- a/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts +++ b/packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts @@ -4,7 +4,7 @@ import { Checksum } from "@smithy/types"; import * as zlib from "zlib"; class NodeCrc32 implements Checksum { - checksum = 0; + private checksum = 0; update(data: Uint8Array) { // @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.