@aws-sdk/checksums 3.1000.5 → 3.1000.6
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.
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCrc32ChecksumAlgorithmFunction = void 0;
|
|
4
|
-
const crc32_1 = require("@aws-crypto/crc32");
|
|
5
|
-
const getCrc32ChecksumAlgorithmFunction = () => crc32_1.AwsCrc32;
|
|
6
|
-
exports.getCrc32ChecksumAlgorithmFunction = getCrc32ChecksumAlgorithmFunction;
|
|
1
|
+
const { AwsCrc32 } = require("@aws-crypto/crc32");
|
|
2
|
+
exports.getCrc32ChecksumAlgorithmFunction = () => AwsCrc32;
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const crc32_1 = require("@aws-crypto/crc32");
|
|
6
|
-
const util_1 = require("@aws-crypto/util");
|
|
7
|
-
const zlib = tslib_1.__importStar(require("node:zlib"));
|
|
1
|
+
const { AwsCrc32 } = require("@aws-crypto/crc32");
|
|
2
|
+
const { numToUint8 } = require("@aws-crypto/util");
|
|
3
|
+
const zlib = require("node:zlib");
|
|
8
4
|
class NodeCrc32 {
|
|
9
5
|
checksum = 0;
|
|
10
6
|
update(data) {
|
|
11
7
|
this.checksum = zlib.crc32(data, this.checksum);
|
|
12
8
|
}
|
|
13
9
|
async digest() {
|
|
14
|
-
return
|
|
10
|
+
return numToUint8(this.checksum);
|
|
15
11
|
}
|
|
16
12
|
reset() {
|
|
17
13
|
this.checksum = 0;
|
|
18
14
|
}
|
|
19
15
|
}
|
|
20
|
-
|
|
16
|
+
exports.getCrc32ChecksumAlgorithmFunction = () => {
|
|
21
17
|
if (typeof zlib.crc32 === "undefined") {
|
|
22
|
-
return
|
|
18
|
+
return AwsCrc32;
|
|
23
19
|
}
|
|
24
20
|
return NodeCrc32;
|
|
25
21
|
};
|
|
26
|
-
exports.getCrc32ChecksumAlgorithmFunction = getCrc32ChecksumAlgorithmFunction;
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var getCrc32ChecksumAlgorithmFunction = require('./flexible-checksums/getCrc32ChecksumAlgorithmFunction');
|
|
8
|
-
var client$1 = require('@smithy/core/client');
|
|
1
|
+
const { setFeature } = require("@aws-sdk/core/client");
|
|
2
|
+
const { HttpRequest } = require("@smithy/core/protocols");
|
|
3
|
+
const { isArrayBuffer, toUint8Array, createBufferedReadable, createChecksumStream } = require("@smithy/core/serde");
|
|
4
|
+
const { AwsCrc32c } = require("@aws-crypto/crc32c");
|
|
5
|
+
const { getCrc32ChecksumAlgorithmFunction } = require("./flexible-checksums/getCrc32ChecksumAlgorithmFunction");
|
|
6
|
+
const { normalizeProvider } = require("@smithy/core/client");
|
|
9
7
|
|
|
10
8
|
const generateCRC64NVMETable = () => {
|
|
11
9
|
const sliceLength = 8;
|
|
@@ -114,7 +112,7 @@ const ResponseChecksumValidation = {
|
|
|
114
112
|
WHEN_REQUIRED: "WHEN_REQUIRED",
|
|
115
113
|
};
|
|
116
114
|
const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED;
|
|
117
|
-
|
|
115
|
+
var ChecksumAlgorithm;
|
|
118
116
|
(function (ChecksumAlgorithm) {
|
|
119
117
|
ChecksumAlgorithm["MD5"] = "MD5";
|
|
120
118
|
ChecksumAlgorithm["CRC32"] = "CRC32";
|
|
@@ -122,13 +120,13 @@ exports.ChecksumAlgorithm = void 0;
|
|
|
122
120
|
ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME";
|
|
123
121
|
ChecksumAlgorithm["SHA1"] = "SHA1";
|
|
124
122
|
ChecksumAlgorithm["SHA256"] = "SHA256";
|
|
125
|
-
})(
|
|
126
|
-
|
|
123
|
+
})(ChecksumAlgorithm || (ChecksumAlgorithm = {}));
|
|
124
|
+
var ChecksumLocation;
|
|
127
125
|
(function (ChecksumLocation) {
|
|
128
126
|
ChecksumLocation["HEADER"] = "header";
|
|
129
127
|
ChecksumLocation["TRAILER"] = "trailer";
|
|
130
|
-
})(
|
|
131
|
-
const DEFAULT_CHECKSUM_ALGORITHM =
|
|
128
|
+
})(ChecksumLocation || (ChecksumLocation = {}));
|
|
129
|
+
const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32;
|
|
132
130
|
|
|
133
131
|
var SelectorType;
|
|
134
132
|
(function (SelectorType) {
|
|
@@ -174,7 +172,7 @@ const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, reques
|
|
|
174
172
|
return checksumAlgorithm;
|
|
175
173
|
};
|
|
176
174
|
|
|
177
|
-
const getChecksumLocationName = (algorithm) => algorithm ===
|
|
175
|
+
const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`;
|
|
178
176
|
|
|
179
177
|
const hasHeader = (header, headers) => {
|
|
180
178
|
const soughtHeader = header.toLowerCase();
|
|
@@ -196,40 +194,40 @@ const hasHeaderWithPrefix = (headerPrefix, headers) => {
|
|
|
196
194
|
return false;
|
|
197
195
|
};
|
|
198
196
|
|
|
199
|
-
const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !
|
|
197
|
+
const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body);
|
|
200
198
|
|
|
201
199
|
const CLIENT_SUPPORTED_ALGORITHMS = [
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
200
|
+
ChecksumAlgorithm.CRC32,
|
|
201
|
+
ChecksumAlgorithm.CRC32C,
|
|
202
|
+
ChecksumAlgorithm.CRC64NVME,
|
|
203
|
+
ChecksumAlgorithm.SHA1,
|
|
204
|
+
ChecksumAlgorithm.SHA256,
|
|
207
205
|
];
|
|
208
206
|
const PRIORITY_ORDER_ALGORITHMS = [
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
207
|
+
ChecksumAlgorithm.SHA256,
|
|
208
|
+
ChecksumAlgorithm.SHA1,
|
|
209
|
+
ChecksumAlgorithm.CRC32,
|
|
210
|
+
ChecksumAlgorithm.CRC32C,
|
|
211
|
+
ChecksumAlgorithm.CRC64NVME,
|
|
214
212
|
];
|
|
215
213
|
|
|
216
214
|
const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
|
|
217
215
|
const { checksumAlgorithms = {} } = config;
|
|
218
216
|
switch (checksumAlgorithm) {
|
|
219
|
-
case
|
|
217
|
+
case ChecksumAlgorithm.MD5:
|
|
220
218
|
return checksumAlgorithms?.MD5 ?? config.md5;
|
|
221
|
-
case
|
|
222
|
-
return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction
|
|
223
|
-
case
|
|
224
|
-
return checksumAlgorithms?.CRC32C ??
|
|
225
|
-
case
|
|
219
|
+
case ChecksumAlgorithm.CRC32:
|
|
220
|
+
return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction();
|
|
221
|
+
case ChecksumAlgorithm.CRC32C:
|
|
222
|
+
return checksumAlgorithms?.CRC32C ?? AwsCrc32c;
|
|
223
|
+
case ChecksumAlgorithm.CRC64NVME:
|
|
226
224
|
if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
|
|
227
225
|
return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme;
|
|
228
226
|
}
|
|
229
227
|
return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme;
|
|
230
|
-
case
|
|
228
|
+
case ChecksumAlgorithm.SHA1:
|
|
231
229
|
return checksumAlgorithms?.SHA1 ?? config.sha1;
|
|
232
|
-
case
|
|
230
|
+
case ChecksumAlgorithm.SHA256:
|
|
233
231
|
return checksumAlgorithms?.SHA256 ?? config.sha256;
|
|
234
232
|
default:
|
|
235
233
|
if (checksumAlgorithms?.[checksumAlgorithm]) {
|
|
@@ -243,7 +241,7 @@ const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
|
|
|
243
241
|
|
|
244
242
|
const stringHasher = (checksumAlgorithmFn, body) => {
|
|
245
243
|
const hash = new checksumAlgorithmFn();
|
|
246
|
-
hash.update(
|
|
244
|
+
hash.update(toUint8Array(body || ""));
|
|
247
245
|
return hash.digest();
|
|
248
246
|
};
|
|
249
247
|
|
|
@@ -254,7 +252,7 @@ const flexibleChecksumsMiddlewareOptions = {
|
|
|
254
252
|
override: true,
|
|
255
253
|
};
|
|
256
254
|
const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
257
|
-
if (!
|
|
255
|
+
if (!HttpRequest.isInstance(args.request)) {
|
|
258
256
|
return next(args);
|
|
259
257
|
}
|
|
260
258
|
if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) {
|
|
@@ -284,20 +282,20 @@ const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context
|
|
|
284
282
|
let updatedHeaders = headers;
|
|
285
283
|
if (checksumAlgorithm) {
|
|
286
284
|
switch (checksumAlgorithm) {
|
|
287
|
-
case
|
|
288
|
-
|
|
285
|
+
case ChecksumAlgorithm.CRC32:
|
|
286
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U");
|
|
289
287
|
break;
|
|
290
|
-
case
|
|
291
|
-
|
|
288
|
+
case ChecksumAlgorithm.CRC32C:
|
|
289
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V");
|
|
292
290
|
break;
|
|
293
|
-
case
|
|
294
|
-
|
|
291
|
+
case ChecksumAlgorithm.CRC64NVME:
|
|
292
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W");
|
|
295
293
|
break;
|
|
296
|
-
case
|
|
297
|
-
|
|
294
|
+
case ChecksumAlgorithm.SHA1:
|
|
295
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X");
|
|
298
296
|
break;
|
|
299
|
-
case
|
|
300
|
-
|
|
297
|
+
case ChecksumAlgorithm.SHA256:
|
|
298
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y");
|
|
301
299
|
break;
|
|
302
300
|
}
|
|
303
301
|
const checksumLocationName = getChecksumLocationName(checksumAlgorithm);
|
|
@@ -305,7 +303,7 @@ const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context
|
|
|
305
303
|
if (isStreaming(requestBody)) {
|
|
306
304
|
const { getAwsChunkedEncodingStream, bodyLengthChecker } = config;
|
|
307
305
|
updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024
|
|
308
|
-
?
|
|
306
|
+
? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger)
|
|
309
307
|
: requestBody, {
|
|
310
308
|
base64Encoder,
|
|
311
309
|
bodyLengthChecker,
|
|
@@ -374,18 +372,18 @@ const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, co
|
|
|
374
372
|
const responseChecksumValidation = await config.responseChecksumValidation();
|
|
375
373
|
switch (requestChecksumCalculation) {
|
|
376
374
|
case RequestChecksumCalculation.WHEN_REQUIRED:
|
|
377
|
-
|
|
375
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a");
|
|
378
376
|
break;
|
|
379
377
|
case RequestChecksumCalculation.WHEN_SUPPORTED:
|
|
380
|
-
|
|
378
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z");
|
|
381
379
|
break;
|
|
382
380
|
}
|
|
383
381
|
switch (responseChecksumValidation) {
|
|
384
382
|
case ResponseChecksumValidation.WHEN_REQUIRED:
|
|
385
|
-
|
|
383
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c");
|
|
386
384
|
break;
|
|
387
385
|
case ResponseChecksumValidation.WHEN_SUPPORTED:
|
|
388
|
-
|
|
386
|
+
setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b");
|
|
389
387
|
break;
|
|
390
388
|
}
|
|
391
389
|
if (requestValidationModeMember && !input[requestValidationModeMember]) {
|
|
@@ -439,15 +437,15 @@ const validateChecksumFromResponse = async (response, { config, responseAlgorith
|
|
|
439
437
|
checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config);
|
|
440
438
|
}
|
|
441
439
|
catch (error) {
|
|
442
|
-
if (algorithm ===
|
|
443
|
-
logger?.warn(`Skipping ${
|
|
440
|
+
if (algorithm === ChecksumAlgorithm.CRC64NVME) {
|
|
441
|
+
logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`);
|
|
444
442
|
continue;
|
|
445
443
|
}
|
|
446
444
|
throw error;
|
|
447
445
|
}
|
|
448
446
|
const { base64Encoder } = config;
|
|
449
447
|
if (isStreaming(responseBody)) {
|
|
450
|
-
response.body =
|
|
448
|
+
response.body = createChecksumStream({
|
|
451
449
|
expectedChecksum: checksumFromResponse,
|
|
452
450
|
checksumSourceLocation: responseHeader,
|
|
453
451
|
checksum: new checksumAlgorithmFn(),
|
|
@@ -474,7 +472,7 @@ const flexibleChecksumsResponseMiddlewareOptions = {
|
|
|
474
472
|
override: true,
|
|
475
473
|
};
|
|
476
474
|
const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
477
|
-
if (!
|
|
475
|
+
if (!HttpRequest.isInstance(args.request)) {
|
|
478
476
|
return next(args);
|
|
479
477
|
}
|
|
480
478
|
const input = args.input;
|
|
@@ -521,8 +519,8 @@ const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({
|
|
|
521
519
|
const resolveFlexibleChecksumsConfig = (input) => {
|
|
522
520
|
const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input;
|
|
523
521
|
return Object.assign(input, {
|
|
524
|
-
requestChecksumCalculation:
|
|
525
|
-
responseChecksumValidation:
|
|
522
|
+
requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION),
|
|
523
|
+
responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION),
|
|
526
524
|
requestStreamBufferSize: Number(requestStreamBufferSize ?? 0),
|
|
527
525
|
checksumAlgorithms: input.checksumAlgorithms ?? {},
|
|
528
526
|
});
|
|
@@ -530,6 +528,8 @@ const resolveFlexibleChecksumsConfig = (input) => {
|
|
|
530
528
|
|
|
531
529
|
exports.CONFIG_REQUEST_CHECKSUM_CALCULATION = CONFIG_REQUEST_CHECKSUM_CALCULATION;
|
|
532
530
|
exports.CONFIG_RESPONSE_CHECKSUM_VALIDATION = CONFIG_RESPONSE_CHECKSUM_VALIDATION;
|
|
531
|
+
exports.ChecksumAlgorithm = ChecksumAlgorithm;
|
|
532
|
+
exports.ChecksumLocation = ChecksumLocation;
|
|
533
533
|
exports.Crc64Nvme = Crc64Nvme;
|
|
534
534
|
exports.DEFAULT_CHECKSUM_ALGORITHM = DEFAULT_CHECKSUM_ALGORITHM;
|
|
535
535
|
exports.DEFAULT_REQUEST_CHECKSUM_CALCULATION = DEFAULT_REQUEST_CHECKSUM_CALCULATION;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/checksums",
|
|
3
|
-
"version": "3.1000.
|
|
3
|
+
"version": "3.1000.6",
|
|
4
4
|
"description": "Checksum algorithms and flexible checksums middleware for the AWS SDK",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
7
7
|
"build:cjs": "node ../../scripts/compilation/inline",
|
|
8
|
-
"build:es": "tsc -p tsconfig.es.json",
|
|
8
|
+
"build:es": "premove dist-es && tsc -p tsconfig.es.json",
|
|
9
9
|
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
10
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
10
|
+
"build:types": "premove dist-types && tsc -p tsconfig.types.json",
|
|
11
11
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
12
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
12
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
13
13
|
"extract:docs": "api-extractor run --local",
|
|
14
14
|
"test": "yarn g:vitest run",
|
|
15
15
|
"test:watch": "yarn g:vitest watch",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@aws-crypto/crc32": "5.2.0",
|
|
32
32
|
"@aws-crypto/crc32c": "5.2.0",
|
|
33
33
|
"@aws-crypto/util": "5.2.0",
|
|
34
|
-
"@aws-sdk/core": "^3.974.
|
|
35
|
-
"@aws-sdk/types": "^3.973.
|
|
34
|
+
"@aws-sdk/core": "^3.974.21",
|
|
35
|
+
"@aws-sdk/types": "^3.973.13",
|
|
36
36
|
"@smithy/core": "^3.24.6",
|
|
37
37
|
"@smithy/types": "^4.14.3",
|
|
38
38
|
"tslib": "^2.6.2"
|