Skip to content

Commit 2a78a0b

Browse files
author
awstools
committed
Merge customizations for S3
1 parent 9ec4c95 commit 2a78a0b

File tree

11 files changed

+78
-2
lines changed

11 files changed

+78
-2
lines changed

packages/crc64-nvme-crt/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"license": "Apache-2.0",
2525
"dependencies": {
2626
"@aws-sdk/crt-loader": "*",
27+
"@aws-sdk/middleware-flexible-checksums": "*",
2728
"@smithy/types": "^4.0.0",
2829
"@smithy/util-utf8": "^4.0.0",
2930
"tslib": "^2.6.2"
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
// ToDo: set implementation in middleware-flexible-checksums container.
1+
import { crc64NvmeCrtContainer } from "@aws-sdk/middleware-flexible-checksums";
2+
3+
import { CrtCrc64Nvme } from "./CrtCrc64Nvme";
4+
5+
crc64NvmeCrtContainer.CrtCrc64Nvme = CrtCrc64Nvme;
6+
27
export * from "./CrtCrc64Nvme";

packages/middleware-flexible-checksums/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export enum ChecksumAlgorithm {
5858
MD5 = "MD5",
5959
CRC32 = "CRC32",
6060
CRC32C = "CRC32C",
61+
CRC64NVME = "CRC64NVME",
6162
SHA1 = "SHA1",
6263
SHA256 = "SHA256",
6364
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ChecksumConstructor } from "@smithy/types";
2+
3+
/**
4+
* @public
5+
*
6+
* \@aws-sdk/crc64-nvme-crt will install the constructor in this
7+
* container if it is installed.
8+
*
9+
* This avoids a runtime-require being interpreted statically by bundlers.
10+
*
11+
*/
12+
export const crc64NvmeCrtContainer: {
13+
CrtCrc64Nvme: null | ChecksumConstructor;
14+
} = {
15+
CrtCrc64Nvme: null,
16+
};

packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export const flexibleChecksumsMiddleware =
105105
case ChecksumAlgorithm.CRC32C:
106106
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V");
107107
break;
108+
case ChecksumAlgorithm.CRC64NVME:
109+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W");
110+
break;
108111
case ChecksumAlgorithm.SHA1:
109112
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X");
110113
break;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS";
22
export * from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS";
33
export * from "./constants";
4+
export * from "./crc64-nvme-crt-container";
45
export * from "./flexibleChecksumsMiddleware";
56
export * from "./getFlexibleChecksumsPlugin";
67
export * from "./resolveFlexibleChecksumsConfig";

packages/middleware-flexible-checksums/src/middleware-flexible-checksums.integ.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Required for testing CRC64NVME
2+
import "@aws-sdk/crc64-nvme-crt";
3+
14
import { ChecksumAlgorithm, S3 } from "@aws-sdk/client-s3";
25
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
36
import { Readable, Transform } from "stream";
@@ -24,6 +27,10 @@ describe("middleware-flexible-checksums", () => {
2427
["abc", ChecksumAlgorithm.CRC32C, "Nks/tw=="],
2528
["Hello world", ChecksumAlgorithm.CRC32C, "crUfeA=="],
2629

30+
["", ChecksumAlgorithm.CRC64NVME, "AAAAAAAAAAA="],
31+
["abc", ChecksumAlgorithm.CRC64NVME, "BeXKuz/B+us="],
32+
["Hello world", ChecksumAlgorithm.CRC64NVME, "OOJZ0D8xKts="],
33+
2734
["", ChecksumAlgorithm.SHA1, "2jmj7l5rSw0yVb/vlWAYkK/YBwk="],
2835
["abc", ChecksumAlgorithm.SHA1, "qZk+NkcGgWq6PiVxeFDCbJzQ2J0="],
2936
["Hello world", ChecksumAlgorithm.SHA1, "e1AsOh9IyGCa4hLN+2Od7jlnP14="],
@@ -209,6 +216,7 @@ describe("middleware-flexible-checksums", () => {
209216
["SHA1", "X"],
210217
["CRC32", "U"],
211218
["CRC32C", "V"],
219+
["CRC64NVME", "W"],
212220
].forEach(([algo, id]) => {
213221
it(`should feature-detect checksum ${algo}=${id}`, async () => {
214222
const client = new S3({ region: "us-west-2", logger });

packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AwsCrc32c } from "@aws-crypto/crc32c";
22
import { describe, expect, test as it, vi } from "vitest";
33

44
import { ChecksumAlgorithm } from "./constants";
5+
import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container";
56
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
67
import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";
78

@@ -21,4 +22,19 @@ describe(selectChecksumAlgorithmFunction.name, () => {
2122
])("testing %s", (checksumAlgorithm, output) => {
2223
expect(selectChecksumAlgorithmFunction(checksumAlgorithm, mockConfig as any)).toEqual(output);
2324
});
25+
26+
it("throws an error for unsupported checksum algorithm", () => {
27+
expect(() => selectChecksumAlgorithmFunction("UNSUPPORTED" as any, mockConfig as any)).toThrow();
28+
});
29+
30+
it("throws error if crc64NvmeCrtContainer.CrtCrc64Nvme is not a function", () => {
31+
expect(() => selectChecksumAlgorithmFunction(ChecksumAlgorithm.CRC64NVME, mockConfig as any)).toThrow();
32+
});
33+
34+
it("returns crc64NvmeCrtContainer.CrtCrc64Nvme if available from container", () => {
35+
crc64NvmeCrtContainer.CrtCrc64Nvme = vi.fn();
36+
expect(selectChecksumAlgorithmFunction(ChecksumAlgorithm.CRC64NVME, mockConfig as any)).toEqual(
37+
crc64NvmeCrtContainer.CrtCrc64Nvme
38+
);
39+
});
2440
});

packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ChecksumConstructor, HashConstructor } from "@smithy/types";
33

44
import { PreviouslyResolved } from "./configuration";
55
import { ChecksumAlgorithm } from "./constants";
6+
import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container";
67
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
78

89
/**
@@ -19,6 +20,17 @@ export const selectChecksumAlgorithmFunction = (
1920
return getCrc32ChecksumAlgorithmFunction();
2021
case ChecksumAlgorithm.CRC32C:
2122
return AwsCrc32c;
23+
case ChecksumAlgorithm.CRC64NVME:
24+
if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
25+
throw new Error(
26+
`Please check whether you have installed the "@aws-sdk/crc64-nvme-crt" package explicitly. \n` +
27+
`You must also register the package by calling [require("@aws-sdk/crc64-nvme-crt");] ` +
28+
`or an ESM equivalent such as [import "@aws-sdk/crc64-nvme-crt";]. \n` +
29+
"For more information please go to " +
30+
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
31+
);
32+
}
33+
return crc64NvmeCrtContainer.CrtCrc64Nvme;
2234
case ChecksumAlgorithm.SHA1:
2335
return config.sha1;
2436
case ChecksumAlgorithm.SHA256:

packages/middleware-flexible-checksums/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ChecksumAlgorithm } from "./constants";
66
export const CLIENT_SUPPORTED_ALGORITHMS = [
77
ChecksumAlgorithm.CRC32,
88
ChecksumAlgorithm.CRC32C,
9+
ChecksumAlgorithm.CRC64NVME,
910
ChecksumAlgorithm.SHA1,
1011
ChecksumAlgorithm.SHA256,
1112
];
@@ -18,4 +19,5 @@ export const PRIORITY_ORDER_ALGORITHMS = [
1819
ChecksumAlgorithm.SHA1,
1920
ChecksumAlgorithm.CRC32,
2021
ChecksumAlgorithm.CRC32C,
22+
ChecksumAlgorithm.CRC64NVME,
2123
];

0 commit comments

Comments
 (0)