@aws-sdk/middleware-flexible-checksums 3.974.25 → 3.974.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.js +21 -447
- package/dist-es/index.js +1 -6
- package/dist-types/index.d.ts +2 -6
- package/package.json +4 -35
- package/dist-cjs/getCrc32ChecksumAlgorithmFunction.browser.js +0 -6
- package/dist-cjs/getCrc32ChecksumAlgorithmFunction.js +0 -26
- package/dist-es/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.js +0 -9
- package/dist-es/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.js +0 -9
- package/dist-es/configuration.js +0 -1
- package/dist-es/constants.js +0 -25
- package/dist-es/flexibleChecksumsInputMiddleware.js +0 -37
- package/dist-es/flexibleChecksumsMiddleware.js +0 -123
- package/dist-es/flexibleChecksumsResponseMiddleware.js +0 -48
- package/dist-es/getChecksum.js +0 -2
- package/dist-es/getChecksumAlgorithmForRequest.js +0 -13
- package/dist-es/getChecksumAlgorithmListForResponse.js +0 -15
- package/dist-es/getChecksumLocationName.js +0 -2
- package/dist-es/getCrc32ChecksumAlgorithmFunction.browser.js +0 -2
- package/dist-es/getCrc32ChecksumAlgorithmFunction.js +0 -21
- package/dist-es/getFlexibleChecksumsPlugin.js +0 -10
- package/dist-es/hasHeader.js +0 -9
- package/dist-es/hasHeaderWithPrefix.js +0 -9
- package/dist-es/isChecksumWithPartNumber.js +0 -13
- package/dist-es/isStreaming.js +0 -2
- package/dist-es/resolveFlexibleChecksumsConfig.js +0 -11
- package/dist-es/selectChecksumAlgorithmFunction.js +0 -32
- package/dist-es/stringHasher.js +0 -6
- package/dist-es/stringUnionSelector.js +0 -14
- package/dist-es/types.js +0 -15
- package/dist-es/validateChecksumFromResponse.js +0 -45
- package/dist-types/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +0 -14
- package/dist-types/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +0 -14
- package/dist-types/configuration.d.ts +0 -58
- package/dist-types/constants.d.ts +0 -83
- package/dist-types/flexibleChecksumsInputMiddleware.d.ts +0 -22
- package/dist-types/flexibleChecksumsMiddleware.d.ts +0 -33
- package/dist-types/flexibleChecksumsResponseMiddleware.d.ts +0 -27
- package/dist-types/getChecksum.d.ts +0 -6
- package/dist-types/getChecksumAlgorithmForRequest.d.ts +0 -22
- package/dist-types/getChecksumAlgorithmListForResponse.d.ts +0 -6
- package/dist-types/getChecksumLocationName.d.ts +0 -5
- package/dist-types/getCrc32ChecksumAlgorithmFunction.browser.d.ts +0 -2
- package/dist-types/getCrc32ChecksumAlgorithmFunction.d.ts +0 -10
- package/dist-types/getFlexibleChecksumsPlugin.d.ts +0 -14
- package/dist-types/hasHeader.d.ts +0 -6
- package/dist-types/hasHeaderWithPrefix.d.ts +0 -6
- package/dist-types/isChecksumWithPartNumber.d.ts +0 -1
- package/dist-types/isStreaming.d.ts +0 -4
- package/dist-types/resolveFlexibleChecksumsConfig.d.ts +0 -57
- package/dist-types/selectChecksumAlgorithmFunction.d.ts +0 -7
- package/dist-types/stringHasher.d.ts +0 -5
- package/dist-types/stringUnionSelector.d.ts +0 -12
- package/dist-types/ts3.4/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +0 -7
- package/dist-types/ts3.4/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +0 -7
- package/dist-types/ts3.4/configuration.d.ts +0 -29
- package/dist-types/ts3.4/constants.d.ts +0 -27
- package/dist-types/ts3.4/flexibleChecksumsInputMiddleware.d.ts +0 -10
- package/dist-types/ts3.4/flexibleChecksumsMiddleware.d.ts +0 -14
- package/dist-types/ts3.4/flexibleChecksumsResponseMiddleware.d.ts +0 -14
- package/dist-types/ts3.4/getChecksum.d.ts +0 -9
- package/dist-types/ts3.4/getChecksumAlgorithmForRequest.d.ts +0 -15
- package/dist-types/ts3.4/getChecksumAlgorithmListForResponse.d.ts +0 -4
- package/dist-types/ts3.4/getChecksumLocationName.d.ts +0 -4
- package/dist-types/ts3.4/getCrc32ChecksumAlgorithmFunction.browser.d.ts +0 -2
- package/dist-types/ts3.4/getCrc32ChecksumAlgorithmFunction.d.ts +0 -12
- package/dist-types/ts3.4/getFlexibleChecksumsPlugin.d.ts +0 -13
- package/dist-types/ts3.4/hasHeader.d.ts +0 -2
- package/dist-types/ts3.4/hasHeaderWithPrefix.d.ts +0 -5
- package/dist-types/ts3.4/index.d.ts +0 -6
- package/dist-types/ts3.4/isChecksumWithPartNumber.d.ts +0 -1
- package/dist-types/ts3.4/isStreaming.d.ts +0 -1
- package/dist-types/ts3.4/resolveFlexibleChecksumsConfig.d.ts +0 -32
- package/dist-types/ts3.4/selectChecksumAlgorithmFunction.d.ts +0 -7
- package/dist-types/ts3.4/stringHasher.d.ts +0 -5
- package/dist-types/ts3.4/stringUnionSelector.d.ts +0 -10
- package/dist-types/ts3.4/types.d.ts +0 -3
- package/dist-types/ts3.4/validateChecksumFromResponse.d.ts +0 -12
- package/dist-types/types.d.ts +0 -9
- package/dist-types/validateChecksumFromResponse.d.ts +0 -13
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { setFeature } from "@aws-sdk/core/client";
|
|
2
|
-
import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants";
|
|
3
|
-
export const flexibleChecksumsInputMiddlewareOptions = {
|
|
4
|
-
name: "flexibleChecksumsInputMiddleware",
|
|
5
|
-
toMiddleware: "serializerMiddleware",
|
|
6
|
-
relation: "before",
|
|
7
|
-
tags: ["BODY_CHECKSUM"],
|
|
8
|
-
override: true,
|
|
9
|
-
};
|
|
10
|
-
export const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
11
|
-
const input = args.input;
|
|
12
|
-
const { requestValidationModeMember } = middlewareConfig;
|
|
13
|
-
const requestChecksumCalculation = await config.requestChecksumCalculation();
|
|
14
|
-
const responseChecksumValidation = await config.responseChecksumValidation();
|
|
15
|
-
switch (requestChecksumCalculation) {
|
|
16
|
-
case RequestChecksumCalculation.WHEN_REQUIRED:
|
|
17
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a");
|
|
18
|
-
break;
|
|
19
|
-
case RequestChecksumCalculation.WHEN_SUPPORTED:
|
|
20
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z");
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
switch (responseChecksumValidation) {
|
|
24
|
-
case ResponseChecksumValidation.WHEN_REQUIRED:
|
|
25
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c");
|
|
26
|
-
break;
|
|
27
|
-
case ResponseChecksumValidation.WHEN_SUPPORTED:
|
|
28
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b");
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
if (requestValidationModeMember && !input[requestValidationModeMember]) {
|
|
32
|
-
if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) {
|
|
33
|
-
input[requestValidationModeMember] = "ENABLED";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return next(args);
|
|
37
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { setFeature } from "@aws-sdk/core/client";
|
|
2
|
-
import { HttpRequest } from "@smithy/core/protocols";
|
|
3
|
-
import { createBufferedReadable } from "@smithy/core/serde";
|
|
4
|
-
import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants";
|
|
5
|
-
import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest";
|
|
6
|
-
import { getChecksumLocationName } from "./getChecksumLocationName";
|
|
7
|
-
import { hasHeader } from "./hasHeader";
|
|
8
|
-
import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix";
|
|
9
|
-
import { isStreaming } from "./isStreaming";
|
|
10
|
-
import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";
|
|
11
|
-
import { stringHasher } from "./stringHasher";
|
|
12
|
-
export const flexibleChecksumsMiddlewareOptions = {
|
|
13
|
-
name: "flexibleChecksumsMiddleware",
|
|
14
|
-
step: "build",
|
|
15
|
-
tags: ["BODY_CHECKSUM"],
|
|
16
|
-
override: true,
|
|
17
|
-
};
|
|
18
|
-
export const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
19
|
-
if (!HttpRequest.isInstance(args.request)) {
|
|
20
|
-
return next(args);
|
|
21
|
-
}
|
|
22
|
-
if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) {
|
|
23
|
-
return next(args);
|
|
24
|
-
}
|
|
25
|
-
const { request, input } = args;
|
|
26
|
-
const { body: requestBody, headers } = request;
|
|
27
|
-
const { base64Encoder, streamHasher } = config;
|
|
28
|
-
const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig;
|
|
29
|
-
const requestChecksumCalculation = await config.requestChecksumCalculation();
|
|
30
|
-
const requestAlgorithmMemberName = requestAlgorithmMember?.name;
|
|
31
|
-
const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader;
|
|
32
|
-
if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) {
|
|
33
|
-
if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) {
|
|
34
|
-
input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM;
|
|
35
|
-
if (requestAlgorithmMemberHttpHeader) {
|
|
36
|
-
headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const checksumAlgorithm = getChecksumAlgorithmForRequest(input, {
|
|
41
|
-
requestChecksumRequired,
|
|
42
|
-
requestAlgorithmMember: requestAlgorithmMember?.name,
|
|
43
|
-
requestChecksumCalculation,
|
|
44
|
-
});
|
|
45
|
-
let updatedBody = requestBody;
|
|
46
|
-
let updatedHeaders = headers;
|
|
47
|
-
if (checksumAlgorithm) {
|
|
48
|
-
switch (checksumAlgorithm) {
|
|
49
|
-
case ChecksumAlgorithm.CRC32:
|
|
50
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U");
|
|
51
|
-
break;
|
|
52
|
-
case ChecksumAlgorithm.CRC32C:
|
|
53
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V");
|
|
54
|
-
break;
|
|
55
|
-
case ChecksumAlgorithm.CRC64NVME:
|
|
56
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W");
|
|
57
|
-
break;
|
|
58
|
-
case ChecksumAlgorithm.SHA1:
|
|
59
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X");
|
|
60
|
-
break;
|
|
61
|
-
case ChecksumAlgorithm.SHA256:
|
|
62
|
-
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y");
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
const checksumLocationName = getChecksumLocationName(checksumAlgorithm);
|
|
66
|
-
const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config);
|
|
67
|
-
if (isStreaming(requestBody)) {
|
|
68
|
-
const { getAwsChunkedEncodingStream, bodyLengthChecker } = config;
|
|
69
|
-
updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024
|
|
70
|
-
? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger)
|
|
71
|
-
: requestBody, {
|
|
72
|
-
base64Encoder,
|
|
73
|
-
bodyLengthChecker,
|
|
74
|
-
checksumLocationName,
|
|
75
|
-
checksumAlgorithmFn,
|
|
76
|
-
streamHasher,
|
|
77
|
-
});
|
|
78
|
-
updatedHeaders = {
|
|
79
|
-
...headers,
|
|
80
|
-
"content-encoding": headers["content-encoding"]
|
|
81
|
-
? `${headers["content-encoding"]},aws-chunked`
|
|
82
|
-
: "aws-chunked",
|
|
83
|
-
"transfer-encoding": "chunked",
|
|
84
|
-
"x-amz-decoded-content-length": headers["content-length"],
|
|
85
|
-
"x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
|
|
86
|
-
"x-amz-trailer": checksumLocationName,
|
|
87
|
-
};
|
|
88
|
-
delete updatedHeaders["content-length"];
|
|
89
|
-
}
|
|
90
|
-
else if (!hasHeader(checksumLocationName, headers)) {
|
|
91
|
-
const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody);
|
|
92
|
-
updatedHeaders = {
|
|
93
|
-
...headers,
|
|
94
|
-
[checksumLocationName]: base64Encoder(rawChecksum),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
const result = await next({
|
|
100
|
-
...args,
|
|
101
|
-
request: {
|
|
102
|
-
...request,
|
|
103
|
-
headers: updatedHeaders,
|
|
104
|
-
body: updatedBody,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
if (e instanceof Error && e.name === "InvalidChunkSizeError") {
|
|
111
|
-
try {
|
|
112
|
-
if (!e.message.endsWith(".")) {
|
|
113
|
-
e.message += ".";
|
|
114
|
-
}
|
|
115
|
-
e.message +=
|
|
116
|
-
" Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream.";
|
|
117
|
-
}
|
|
118
|
-
catch (ignored) {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
throw e;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { HttpRequest } from "@smithy/core/protocols";
|
|
2
|
-
import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse";
|
|
3
|
-
import { getChecksumLocationName } from "./getChecksumLocationName";
|
|
4
|
-
import { isChecksumWithPartNumber } from "./isChecksumWithPartNumber";
|
|
5
|
-
import { validateChecksumFromResponse } from "./validateChecksumFromResponse";
|
|
6
|
-
export const flexibleChecksumsResponseMiddlewareOptions = {
|
|
7
|
-
name: "flexibleChecksumsResponseMiddleware",
|
|
8
|
-
toMiddleware: "deserializerMiddleware",
|
|
9
|
-
relation: "after",
|
|
10
|
-
tags: ["BODY_CHECKSUM"],
|
|
11
|
-
override: true,
|
|
12
|
-
};
|
|
13
|
-
export const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
14
|
-
if (!HttpRequest.isInstance(args.request)) {
|
|
15
|
-
return next(args);
|
|
16
|
-
}
|
|
17
|
-
const input = args.input;
|
|
18
|
-
const result = await next(args);
|
|
19
|
-
const response = result.response;
|
|
20
|
-
const { requestValidationModeMember, responseAlgorithms } = middlewareConfig;
|
|
21
|
-
if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") {
|
|
22
|
-
const { clientName, commandName } = context;
|
|
23
|
-
const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => {
|
|
24
|
-
const responseHeader = getChecksumLocationName(algorithm);
|
|
25
|
-
return response.headers[responseHeader] !== undefined;
|
|
26
|
-
});
|
|
27
|
-
const algoList = getChecksumAlgorithmListForResponse([
|
|
28
|
-
...(responseAlgorithms ?? []),
|
|
29
|
-
...customChecksumAlgorithms,
|
|
30
|
-
]);
|
|
31
|
-
const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" &&
|
|
32
|
-
commandName === "GetObjectCommand" &&
|
|
33
|
-
algoList.every((algorithm) => {
|
|
34
|
-
const responseHeader = getChecksumLocationName(algorithm);
|
|
35
|
-
const checksumFromResponse = response.headers[responseHeader];
|
|
36
|
-
return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse);
|
|
37
|
-
});
|
|
38
|
-
if (isS3WholeObjectMultipartGetResponseChecksum) {
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
await validateChecksumFromResponse(response, {
|
|
42
|
-
config,
|
|
43
|
-
responseAlgorithms: algoList,
|
|
44
|
-
logger: context.logger,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
package/dist-es/getChecksum.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants";
|
|
2
|
-
export const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => {
|
|
3
|
-
if (!requestAlgorithmMember) {
|
|
4
|
-
return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired
|
|
5
|
-
? DEFAULT_CHECKSUM_ALGORITHM
|
|
6
|
-
: undefined;
|
|
7
|
-
}
|
|
8
|
-
if (!input[requestAlgorithmMember]) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
const checksumAlgorithm = input[requestAlgorithmMember];
|
|
12
|
-
return checksumAlgorithm;
|
|
13
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PRIORITY_ORDER_ALGORITHMS } from "./types";
|
|
2
|
-
export const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => {
|
|
3
|
-
const validChecksumAlgorithms = [];
|
|
4
|
-
let i = PRIORITY_ORDER_ALGORITHMS.length;
|
|
5
|
-
for (const algorithm of responseAlgorithms) {
|
|
6
|
-
const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm);
|
|
7
|
-
if (priority !== -1) {
|
|
8
|
-
validChecksumAlgorithms[priority] = algorithm;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
validChecksumAlgorithms[i++] = algorithm;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return validChecksumAlgorithms.filter(Boolean);
|
|
15
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AwsCrc32 } from "@aws-crypto/crc32";
|
|
2
|
-
import { numToUint8 } from "@aws-crypto/util";
|
|
3
|
-
import * as zlib from "node:zlib";
|
|
4
|
-
class NodeCrc32 {
|
|
5
|
-
checksum = 0;
|
|
6
|
-
update(data) {
|
|
7
|
-
this.checksum = zlib.crc32(data, this.checksum);
|
|
8
|
-
}
|
|
9
|
-
async digest() {
|
|
10
|
-
return numToUint8(this.checksum);
|
|
11
|
-
}
|
|
12
|
-
reset() {
|
|
13
|
-
this.checksum = 0;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export const getCrc32ChecksumAlgorithmFunction = () => {
|
|
17
|
-
if (typeof zlib.crc32 === "undefined") {
|
|
18
|
-
return AwsCrc32;
|
|
19
|
-
}
|
|
20
|
-
return NodeCrc32;
|
|
21
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { flexibleChecksumsInputMiddleware, flexibleChecksumsInputMiddlewareOptions, } from "./flexibleChecksumsInputMiddleware";
|
|
2
|
-
import { flexibleChecksumsMiddleware, flexibleChecksumsMiddlewareOptions } from "./flexibleChecksumsMiddleware";
|
|
3
|
-
import { flexibleChecksumsResponseMiddleware, flexibleChecksumsResponseMiddlewareOptions, } from "./flexibleChecksumsResponseMiddleware";
|
|
4
|
-
export const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({
|
|
5
|
-
applyToStack: (clientStack) => {
|
|
6
|
-
clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions);
|
|
7
|
-
clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions);
|
|
8
|
-
clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions);
|
|
9
|
-
},
|
|
10
|
-
});
|
package/dist-es/hasHeader.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const hasHeaderWithPrefix = (headerPrefix, headers) => {
|
|
2
|
-
const soughtHeaderPrefix = headerPrefix.toLowerCase();
|
|
3
|
-
for (const headerName of Object.keys(headers)) {
|
|
4
|
-
if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
9
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const isChecksumWithPartNumber = (checksum) => {
|
|
2
|
-
const lastHyphenIndex = checksum.lastIndexOf("-");
|
|
3
|
-
if (lastHyphenIndex !== -1) {
|
|
4
|
-
const numberPart = checksum.slice(lastHyphenIndex + 1);
|
|
5
|
-
if (!numberPart.startsWith("0")) {
|
|
6
|
-
const number = parseInt(numberPart, 10);
|
|
7
|
-
if (!isNaN(number) && number >= 1 && number <= 10000) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
};
|
package/dist-es/isStreaming.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { normalizeProvider } from "@smithy/core/client";
|
|
2
|
-
import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants";
|
|
3
|
-
export const resolveFlexibleChecksumsConfig = (input) => {
|
|
4
|
-
const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input;
|
|
5
|
-
return Object.assign(input, {
|
|
6
|
-
requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION),
|
|
7
|
-
responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION),
|
|
8
|
-
requestStreamBufferSize: Number(requestStreamBufferSize ?? 0),
|
|
9
|
-
checksumAlgorithms: input.checksumAlgorithms ?? {},
|
|
10
|
-
});
|
|
11
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AwsCrc32c } from "@aws-crypto/crc32c";
|
|
2
|
-
import { Crc64Nvme, crc64NvmeCrtContainer } from "@aws-sdk/crc64-nvme";
|
|
3
|
-
import { ChecksumAlgorithm } from "./constants";
|
|
4
|
-
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
|
|
5
|
-
import { CLIENT_SUPPORTED_ALGORITHMS } from "./types";
|
|
6
|
-
export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
|
|
7
|
-
const { checksumAlgorithms = {} } = config;
|
|
8
|
-
switch (checksumAlgorithm) {
|
|
9
|
-
case ChecksumAlgorithm.MD5:
|
|
10
|
-
return checksumAlgorithms?.MD5 ?? config.md5;
|
|
11
|
-
case ChecksumAlgorithm.CRC32:
|
|
12
|
-
return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction();
|
|
13
|
-
case ChecksumAlgorithm.CRC32C:
|
|
14
|
-
return checksumAlgorithms?.CRC32C ?? AwsCrc32c;
|
|
15
|
-
case ChecksumAlgorithm.CRC64NVME:
|
|
16
|
-
if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
|
|
17
|
-
return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme;
|
|
18
|
-
}
|
|
19
|
-
return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme;
|
|
20
|
-
case ChecksumAlgorithm.SHA1:
|
|
21
|
-
return checksumAlgorithms?.SHA1 ?? config.sha1;
|
|
22
|
-
case ChecksumAlgorithm.SHA256:
|
|
23
|
-
return checksumAlgorithms?.SHA256 ?? config.sha256;
|
|
24
|
-
default:
|
|
25
|
-
if (checksumAlgorithms?.[checksumAlgorithm]) {
|
|
26
|
-
return checksumAlgorithms[checksumAlgorithm];
|
|
27
|
-
}
|
|
28
|
-
throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` +
|
|
29
|
-
` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` +
|
|
30
|
-
` the client constructor checksums field.`);
|
|
31
|
-
}
|
|
32
|
-
};
|
package/dist-es/stringHasher.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export var SelectorType;
|
|
2
|
-
(function (SelectorType) {
|
|
3
|
-
SelectorType["ENV"] = "env";
|
|
4
|
-
SelectorType["CONFIG"] = "shared config entry";
|
|
5
|
-
})(SelectorType || (SelectorType = {}));
|
|
6
|
-
export const stringUnionSelector = (obj, key, union, type) => {
|
|
7
|
-
if (!(key in obj))
|
|
8
|
-
return undefined;
|
|
9
|
-
const value = obj[key].toUpperCase();
|
|
10
|
-
if (!Object.values(union).includes(value)) {
|
|
11
|
-
throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`);
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
};
|
package/dist-es/types.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ChecksumAlgorithm } from "./constants";
|
|
2
|
-
export const CLIENT_SUPPORTED_ALGORITHMS = [
|
|
3
|
-
ChecksumAlgorithm.CRC32,
|
|
4
|
-
ChecksumAlgorithm.CRC32C,
|
|
5
|
-
ChecksumAlgorithm.CRC64NVME,
|
|
6
|
-
ChecksumAlgorithm.SHA1,
|
|
7
|
-
ChecksumAlgorithm.SHA256,
|
|
8
|
-
];
|
|
9
|
-
export const PRIORITY_ORDER_ALGORITHMS = [
|
|
10
|
-
ChecksumAlgorithm.SHA256,
|
|
11
|
-
ChecksumAlgorithm.SHA1,
|
|
12
|
-
ChecksumAlgorithm.CRC32,
|
|
13
|
-
ChecksumAlgorithm.CRC32C,
|
|
14
|
-
ChecksumAlgorithm.CRC64NVME,
|
|
15
|
-
];
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createChecksumStream } from "@smithy/core/serde";
|
|
2
|
-
import { ChecksumAlgorithm } from "./constants";
|
|
3
|
-
import { getChecksum } from "./getChecksum";
|
|
4
|
-
import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse";
|
|
5
|
-
import { getChecksumLocationName } from "./getChecksumLocationName";
|
|
6
|
-
import { isStreaming } from "./isStreaming";
|
|
7
|
-
import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";
|
|
8
|
-
export const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => {
|
|
9
|
-
const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms);
|
|
10
|
-
const { body: responseBody, headers: responseHeaders } = response;
|
|
11
|
-
for (const algorithm of checksumAlgorithms) {
|
|
12
|
-
const responseHeader = getChecksumLocationName(algorithm);
|
|
13
|
-
const checksumFromResponse = responseHeaders[responseHeader];
|
|
14
|
-
if (checksumFromResponse) {
|
|
15
|
-
let checksumAlgorithmFn;
|
|
16
|
-
try {
|
|
17
|
-
checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
if (algorithm === ChecksumAlgorithm.CRC64NVME) {
|
|
21
|
-
logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
const { base64Encoder } = config;
|
|
27
|
-
if (isStreaming(responseBody)) {
|
|
28
|
-
response.body = createChecksumStream({
|
|
29
|
-
expectedChecksum: checksumFromResponse,
|
|
30
|
-
checksumSourceLocation: responseHeader,
|
|
31
|
-
checksum: new checksumAlgorithmFn(),
|
|
32
|
-
source: responseBody,
|
|
33
|
-
base64Encoder,
|
|
34
|
-
});
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder });
|
|
38
|
-
if (checksum === checksumFromResponse) {
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` +
|
|
42
|
-
` in response header "${responseHeader}".`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LoadedConfigSelectors } from "@smithy/core/config";
|
|
2
|
-
import { RequestChecksumCalculation } from "./constants";
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation";
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS: LoadedConfigSelectors<RequestChecksumCalculation>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LoadedConfigSelectors } from "@smithy/core/config";
|
|
2
|
-
import { ResponseChecksumValidation } from "./constants";
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation";
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS: LoadedConfigSelectors<ResponseChecksumValidation>;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { BodyLengthCalculator, ChecksumConstructor, Encoder, GetAwsChunkedEncodingStream, HashConstructor, Provider, StreamCollector, StreamHasher } from "@smithy/types";
|
|
2
|
-
import type { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants";
|
|
3
|
-
import type { FlexibleChecksumsInputConfig } from "./resolveFlexibleChecksumsConfig";
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export interface PreviouslyResolved {
|
|
8
|
-
/**
|
|
9
|
-
* The function that will be used to convert binary data to a base64-encoded string.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
base64Encoder: Encoder;
|
|
13
|
-
/**
|
|
14
|
-
* A function that can calculate the length of a body.
|
|
15
|
-
*/
|
|
16
|
-
bodyLengthChecker: BodyLengthCalculator;
|
|
17
|
-
/**
|
|
18
|
-
* A function that returns Readable Stream which follows aws-chunked encoding stream.
|
|
19
|
-
*/
|
|
20
|
-
getAwsChunkedEncodingStream: GetAwsChunkedEncodingStream;
|
|
21
|
-
/**
|
|
22
|
-
* A constructor for a class implementing the {@link Hash} interface that computes MD5 hashes.
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
md5: ChecksumConstructor | HashConstructor;
|
|
26
|
-
/**
|
|
27
|
-
* Determines when a checksum will be calculated for request payloads
|
|
28
|
-
*/
|
|
29
|
-
requestChecksumCalculation: Provider<RequestChecksumCalculation>;
|
|
30
|
-
/**
|
|
31
|
-
* Determines when a checksum will be calculated for response payloads
|
|
32
|
-
*/
|
|
33
|
-
responseChecksumValidation: Provider<ResponseChecksumValidation>;
|
|
34
|
-
/**
|
|
35
|
-
* A constructor for a class implementing the {@link Hash} interface that computes SHA1 hashes.
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
sha1: ChecksumConstructor | HashConstructor;
|
|
39
|
-
/**
|
|
40
|
-
* A constructor for a class implementing the {@link Hash} interface that computes SHA256 hashes.
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
sha256: ChecksumConstructor | HashConstructor;
|
|
44
|
-
/**
|
|
45
|
-
* A function that, given a hash constructor and a stream, calculates the hash of the streamed value.
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
streamHasher: StreamHasher<any>;
|
|
49
|
-
/**
|
|
50
|
-
* Collects streams into buffers.
|
|
51
|
-
*/
|
|
52
|
-
streamCollector: StreamCollector;
|
|
53
|
-
/**
|
|
54
|
-
* Minimum bytes from a stream to buffer into a chunk before passing to chunked encoding.
|
|
55
|
-
*/
|
|
56
|
-
requestStreamBufferSize: number;
|
|
57
|
-
checksumAlgorithms?: FlexibleChecksumsInputConfig["checksumAlgorithms"];
|
|
58
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines when a checksum will be calculated for request payloads.
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export declare const RequestChecksumCalculation: {
|
|
6
|
-
/**
|
|
7
|
-
* When set, a checksum will be calculated for all request payloads of operations
|
|
8
|
-
* modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true`
|
|
9
|
-
* AND/OR a `requestAlgorithmMember` is modeled.
|
|
10
|
-
* {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum}
|
|
11
|
-
*/
|
|
12
|
-
readonly WHEN_SUPPORTED: "WHEN_SUPPORTED";
|
|
13
|
-
/**
|
|
14
|
-
* When set, a checksum will only be calculated for request payloads of operations
|
|
15
|
-
* modeled with the {@link httpChecksum} trait where `requestChecksumRequired` is `true`
|
|
16
|
-
* OR where a `requestAlgorithmMember` is modeled and the user sets it.
|
|
17
|
-
* {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum}
|
|
18
|
-
*/
|
|
19
|
-
readonly WHEN_REQUIRED: "WHEN_REQUIRED";
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export type RequestChecksumCalculation = (typeof RequestChecksumCalculation)[keyof typeof RequestChecksumCalculation];
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export declare const DEFAULT_REQUEST_CHECKSUM_CALCULATION: "WHEN_SUPPORTED";
|
|
29
|
-
/**
|
|
30
|
-
* Determines when checksum validation will be performed on response payloads.
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export declare const ResponseChecksumValidation: {
|
|
34
|
-
/**
|
|
35
|
-
* When set, checksum validation MUST be performed on all response payloads of operations
|
|
36
|
-
* modeled with the {@link httpChecksum} trait where `responseAlgorithms` is modeled,
|
|
37
|
-
* except when no modeled checksum algorithms are supported by an SDK.
|
|
38
|
-
* {@link https://smithy.io/2.0/aws/aws-core.html#aws-protocols-httpchecksum-trait httpChecksum}
|
|
39
|
-
*/
|
|
40
|
-
readonly WHEN_SUPPORTED: "WHEN_SUPPORTED";
|
|
41
|
-
/**
|
|
42
|
-
* When set, checksum validation MUST NOT be performed on response payloads of operations UNLESS
|
|
43
|
-
* the SDK supports the modeled checksum algorithms AND the user has set the `requestValidationModeMember` to `ENABLED`.
|
|
44
|
-
* It is currently impossible to model an operation as requiring a response checksum,
|
|
45
|
-
* but this setting leaves the door open for future updates.
|
|
46
|
-
*/
|
|
47
|
-
readonly WHEN_REQUIRED: "WHEN_REQUIRED";
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* @public
|
|
51
|
-
*/
|
|
52
|
-
export type ResponseChecksumValidation = (typeof ResponseChecksumValidation)[keyof typeof ResponseChecksumValidation];
|
|
53
|
-
/**
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
export declare const DEFAULT_RESPONSE_CHECKSUM_VALIDATION: "WHEN_SUPPORTED";
|
|
57
|
-
/**
|
|
58
|
-
* Checksum Algorithms supported by the SDK.
|
|
59
|
-
* @public
|
|
60
|
-
*/
|
|
61
|
-
export declare enum ChecksumAlgorithm {
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated Use {@link ChecksumAlgorithm.CRC32} instead.
|
|
64
|
-
*/
|
|
65
|
-
MD5 = "MD5",
|
|
66
|
-
CRC32 = "CRC32",
|
|
67
|
-
CRC32C = "CRC32C",
|
|
68
|
-
CRC64NVME = "CRC64NVME",
|
|
69
|
-
SHA1 = "SHA1",
|
|
70
|
-
SHA256 = "SHA256"
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Location when the checksum is stored in the request body.
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
export declare enum ChecksumLocation {
|
|
77
|
-
HEADER = "header",
|
|
78
|
-
TRAILER = "trailer"
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
83
|
-
export declare const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { RelativeMiddlewareOptions, SerializeMiddleware } from "@smithy/types";
|
|
2
|
-
import type { PreviouslyResolved } from "./configuration";
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export interface FlexibleChecksumsInputMiddlewareConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Defines a top-level operation input member used to opt-in to best-effort validation
|
|
9
|
-
* of a checksum returned in the HTTP response of the operation.
|
|
10
|
-
*/
|
|
11
|
-
requestValidationModeMember?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export declare const flexibleChecksumsInputMiddlewareOptions: RelativeMiddlewareOptions;
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*
|
|
20
|
-
* The input counterpart to the flexibleChecksumsMiddleware.
|
|
21
|
-
*/
|
|
22
|
-
export declare const flexibleChecksumsInputMiddleware: (config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsInputMiddlewareConfig) => SerializeMiddleware<any, any>;
|