@aws-sdk/checksums 3.1000.9 → 3.1000.11

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.
Files changed (131) hide show
  1. package/crc.d.ts +5 -0
  2. package/crc.js +5 -0
  3. package/dist-cjs/index.js +5 -551
  4. package/dist-cjs/submodules/crc/index.js +159 -0
  5. package/dist-cjs/submodules/flexible-checksums/index.js +444 -0
  6. package/dist-cjs/submodules/md5/index.js +4 -0
  7. package/dist-cjs/submodules/sha/index.js +312 -0
  8. package/dist-es/index.js +2 -8
  9. package/dist-es/submodules/crc/crc32c/Crc32cJs.js +31 -0
  10. package/dist-es/submodules/crc/crc32c/Crc32cNode.js +2 -0
  11. package/dist-es/submodules/crc/crc64-nvme/Crc64Nvme.js +18 -0
  12. package/dist-es/{crc64-nvme/Crc64Nvme.js → submodules/crc/crc64-nvme/Crc64NvmeJs.js} +2 -2
  13. package/dist-es/submodules/crc/index.browser.js +6 -0
  14. package/dist-es/submodules/crc/index.js +6 -0
  15. package/dist-es/submodules/flexible-checksums/index.js +6 -0
  16. package/dist-es/{flexible-checksums → submodules/flexible-checksums}/selectChecksumAlgorithmFunction.js +4 -10
  17. package/dist-es/submodules/md5/index.js +1 -0
  18. package/dist-es/submodules/sha/index.browser.js +4 -0
  19. package/dist-es/submodules/sha/index.js +4 -0
  20. package/dist-es/submodules/sha/sha1/Sha1Js.js +173 -0
  21. package/dist-es/submodules/sha/sha1/Sha1Node.js +59 -0
  22. package/dist-es/submodules/sha/sha1/Sha1WebCrypto.js +71 -0
  23. package/dist-types/index.d.ts +3 -11
  24. package/dist-types/submodules/crc/crc32c/Crc32cJs.d.ts +13 -0
  25. package/dist-types/submodules/crc/crc32c/Crc32cNode.d.ts +13 -0
  26. package/dist-types/{crc64-nvme → submodules/crc/crc64-nvme}/Crc64Nvme.d.ts +3 -6
  27. package/dist-types/submodules/crc/crc64-nvme/Crc64NvmeJs.d.ts +14 -0
  28. package/dist-types/{crc64-nvme → submodules/crc/crc64-nvme}/crc64-nvme-crt-container.d.ts +1 -3
  29. package/dist-types/submodules/crc/index.browser.d.ts +5 -0
  30. package/dist-types/submodules/crc/index.d.ts +6 -0
  31. package/dist-types/submodules/flexible-checksums/index.d.ts +9 -0
  32. package/dist-types/submodules/md5/index.d.ts +1 -0
  33. package/dist-types/submodules/sha/index.browser.d.ts +3 -0
  34. package/dist-types/submodules/sha/index.d.ts +4 -0
  35. package/dist-types/submodules/sha/sha1/Sha1Js.d.ts +26 -0
  36. package/dist-types/submodules/sha/sha1/Sha1Node.d.ts +13 -0
  37. package/dist-types/submodules/sha/sha1/Sha1WebCrypto.d.ts +22 -0
  38. package/dist-types/ts3.4/index.d.ts +11 -14
  39. package/dist-types/ts3.4/submodules/crc/crc32c/Crc32cJs.d.ts +8 -0
  40. package/dist-types/ts3.4/submodules/crc/crc32c/Crc32cNode.d.ts +5 -0
  41. package/dist-types/ts3.4/{crc64-nvme → submodules/crc/crc64-nvme}/Crc64Nvme.d.ts +1 -2
  42. package/dist-types/ts3.4/submodules/crc/crc64-nvme/Crc64NvmeJs.d.ts +9 -0
  43. package/dist-types/ts3.4/submodules/crc/index.browser.d.ts +8 -0
  44. package/dist-types/ts3.4/submodules/crc/index.d.ts +6 -0
  45. package/dist-types/ts3.4/submodules/flexible-checksums/index.d.ts +31 -0
  46. package/dist-types/ts3.4/submodules/md5/index.d.ts +1 -0
  47. package/dist-types/ts3.4/submodules/sha/index.browser.d.ts +8 -0
  48. package/dist-types/ts3.4/submodules/sha/index.d.ts +4 -0
  49. package/dist-types/ts3.4/submodules/sha/sha1/Sha1Js.d.ts +20 -0
  50. package/dist-types/ts3.4/submodules/sha/sha1/Sha1Node.d.ts +5 -0
  51. package/dist-types/ts3.4/submodules/sha/sha1/Sha1WebCrypto.d.ts +14 -0
  52. package/flexible-checksums.d.ts +5 -0
  53. package/flexible-checksums.js +5 -0
  54. package/md5.d.ts +5 -0
  55. package/md5.js +5 -0
  56. package/package.json +67 -10
  57. package/sha.d.ts +5 -0
  58. package/sha.js +5 -0
  59. package/dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction.browser.js +0 -2
  60. package/dist-es/flexible-checksums/getCrc32ChecksumAlgorithmFunction.js +0 -21
  61. package/dist-types/flexible-checksums/getCrc32ChecksumAlgorithmFunction.browser.d.ts +0 -2
  62. package/dist-types/flexible-checksums/getCrc32ChecksumAlgorithmFunction.d.ts +0 -10
  63. package/dist-types/ts3.4/flexible-checksums/getCrc32ChecksumAlgorithmFunction.browser.d.ts +0 -2
  64. package/dist-types/ts3.4/flexible-checksums/getCrc32ChecksumAlgorithmFunction.d.ts +0 -12
  65. /package/dist-es/{crc64-nvme → submodules/crc/crc64-nvme}/crc64-nvme-crt-container.js +0 -0
  66. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.js +0 -0
  67. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.js +0 -0
  68. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/configuration.js +0 -0
  69. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/constants.js +0 -0
  70. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsInputMiddleware.js +0 -0
  71. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsMiddleware.js +0 -0
  72. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsResponseMiddleware.js +0 -0
  73. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/getChecksum.js +0 -0
  74. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmForRequest.js +0 -0
  75. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmListForResponse.js +0 -0
  76. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/getChecksumLocationName.js +0 -0
  77. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/getFlexibleChecksumsPlugin.js +0 -0
  78. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/hasHeader.js +0 -0
  79. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/hasHeaderWithPrefix.js +0 -0
  80. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/isChecksumWithPartNumber.js +0 -0
  81. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/isStreaming.js +0 -0
  82. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/resolveFlexibleChecksumsConfig.js +0 -0
  83. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/stringHasher.js +0 -0
  84. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/stringUnionSelector.js +0 -0
  85. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/types.js +0 -0
  86. /package/dist-es/{flexible-checksums → submodules/flexible-checksums}/validateChecksumFromResponse.js +0 -0
  87. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +0 -0
  88. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +0 -0
  89. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/configuration.d.ts +0 -0
  90. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/constants.d.ts +0 -0
  91. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsInputMiddleware.d.ts +0 -0
  92. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsMiddleware.d.ts +0 -0
  93. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsResponseMiddleware.d.ts +0 -0
  94. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/getChecksum.d.ts +0 -0
  95. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmForRequest.d.ts +0 -0
  96. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmListForResponse.d.ts +0 -0
  97. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/getChecksumLocationName.d.ts +0 -0
  98. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/getFlexibleChecksumsPlugin.d.ts +0 -0
  99. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/hasHeader.d.ts +0 -0
  100. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/hasHeaderWithPrefix.d.ts +0 -0
  101. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/isChecksumWithPartNumber.d.ts +0 -0
  102. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/isStreaming.d.ts +0 -0
  103. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/resolveFlexibleChecksumsConfig.d.ts +0 -0
  104. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/selectChecksumAlgorithmFunction.d.ts +0 -0
  105. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/stringHasher.d.ts +0 -0
  106. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/stringUnionSelector.d.ts +0 -0
  107. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/types.d.ts +0 -0
  108. /package/dist-types/{flexible-checksums → submodules/flexible-checksums}/validateChecksumFromResponse.d.ts +0 -0
  109. /package/dist-types/ts3.4/{crc64-nvme → submodules/crc/crc64-nvme}/crc64-nvme-crt-container.d.ts +0 -0
  110. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +0 -0
  111. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +0 -0
  112. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/configuration.d.ts +0 -0
  113. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/constants.d.ts +0 -0
  114. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsInputMiddleware.d.ts +0 -0
  115. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsMiddleware.d.ts +0 -0
  116. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/flexibleChecksumsResponseMiddleware.d.ts +0 -0
  117. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/getChecksum.d.ts +0 -0
  118. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmForRequest.d.ts +0 -0
  119. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/getChecksumAlgorithmListForResponse.d.ts +0 -0
  120. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/getChecksumLocationName.d.ts +0 -0
  121. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/getFlexibleChecksumsPlugin.d.ts +0 -0
  122. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/hasHeader.d.ts +0 -0
  123. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/hasHeaderWithPrefix.d.ts +0 -0
  124. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/isChecksumWithPartNumber.d.ts +0 -0
  125. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/isStreaming.d.ts +0 -0
  126. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/resolveFlexibleChecksumsConfig.d.ts +0 -0
  127. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/selectChecksumAlgorithmFunction.d.ts +0 -0
  128. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/stringHasher.d.ts +0 -0
  129. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/stringUnionSelector.d.ts +0 -0
  130. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/types.d.ts +0 -0
  131. /package/dist-types/ts3.4/{flexible-checksums → submodules/flexible-checksums}/validateChecksumFromResponse.d.ts +0 -0
package/crc.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Do not edit:
3
+ * This is a compatibility redirect for contexts that do not understand package.json exports field.
4
+ */
5
+ export * from "./dist-types/submodules/crc/index";
package/crc.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Do not edit:
3
+ * This is a compatibility redirect for contexts that do not understand package.json exports field.
4
+ */
5
+ module.exports = require("./dist-cjs/submodules/crc/index.js");
package/dist-cjs/index.js CHANGED
@@ -1,557 +1,12 @@
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 { AwsCrc32 } = require("@aws-crypto/crc32");
6
- const { numToUint8 } = require("@aws-crypto/util");
7
- const zlib = require("node:zlib");
8
- const { normalizeProvider } = require("@smithy/core/client");
9
-
10
- const generateCRC64NVMETable = () => {
11
- const sliceLength = 8;
12
- const tables = new Array(sliceLength);
13
- for (let slice = 0; slice < sliceLength; slice++) {
14
- const table = new Array(512);
15
- for (let i = 0; i < 256; i++) {
16
- let crc = BigInt(i);
17
- for (let j = 0; j < 8 * (slice + 1); j++) {
18
- if (crc & 1n) {
19
- crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n;
20
- }
21
- else {
22
- crc = crc >> 1n;
23
- }
24
- }
25
- table[i * 2] = Number((crc >> 32n) & 0xffffffffn);
26
- table[i * 2 + 1] = Number(crc & 0xffffffffn);
27
- }
28
- tables[slice] = new Uint32Array(table);
29
- }
30
- return tables;
31
- };
32
- let CRC64_NVME_REVERSED_TABLE;
33
- let t0, t1, t2, t3;
34
- let t4, t5, t6, t7;
35
- const ensureTablesInitialized = () => {
36
- if (!CRC64_NVME_REVERSED_TABLE) {
37
- CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable();
38
- [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE;
39
- }
40
- };
41
- class Crc64Nvme {
42
- c1 = 0;
43
- c2 = 0;
44
- constructor() {
45
- ensureTablesInitialized();
46
- this.reset();
47
- }
48
- update(data) {
49
- const len = data.length;
50
- let i = 0;
51
- let crc1 = this.c1;
52
- let crc2 = this.c2;
53
- while (i + 8 <= len) {
54
- const idx0 = ((crc2 ^ data[i++]) & 255) << 1;
55
- const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1;
56
- const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1;
57
- const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1;
58
- const idx4 = ((crc1 ^ data[i++]) & 255) << 1;
59
- const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1;
60
- const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1;
61
- const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1;
62
- crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7];
63
- crc2 =
64
- t7[idx0 + 1] ^
65
- t6[idx1 + 1] ^
66
- t5[idx2 + 1] ^
67
- t4[idx3 + 1] ^
68
- t3[idx4 + 1] ^
69
- t2[idx5 + 1] ^
70
- t1[idx6 + 1] ^
71
- t0[idx7 + 1];
72
- }
73
- while (i < len) {
74
- const idx = ((crc2 ^ data[i]) & 255) << 1;
75
- crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0;
76
- crc1 = (crc1 >>> 8) ^ t0[idx];
77
- crc2 ^= t0[idx + 1];
78
- i++;
79
- }
80
- this.c1 = crc1;
81
- this.c2 = crc2;
82
- }
83
- async digest() {
84
- const c1 = this.c1 ^ 4294967295;
85
- const c2 = this.c2 ^ 4294967295;
86
- return new Uint8Array([
87
- c1 >>> 24,
88
- (c1 >>> 16) & 255,
89
- (c1 >>> 8) & 255,
90
- c1 & 255,
91
- c2 >>> 24,
92
- (c2 >>> 16) & 255,
93
- (c2 >>> 8) & 255,
94
- c2 & 255,
95
- ]);
96
- }
97
- reset() {
98
- this.c1 = 4294967295;
99
- this.c2 = 4294967295;
100
- }
101
- }
102
-
103
- const crc64NvmeCrtContainer = {
104
- CrtCrc64Nvme: null,
105
- };
106
-
107
- const RequestChecksumCalculation = {
108
- WHEN_SUPPORTED: "WHEN_SUPPORTED",
109
- WHEN_REQUIRED: "WHEN_REQUIRED",
110
- };
111
- const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED;
112
- const ResponseChecksumValidation = {
113
- WHEN_SUPPORTED: "WHEN_SUPPORTED",
114
- WHEN_REQUIRED: "WHEN_REQUIRED",
115
- };
116
- const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED;
117
- var ChecksumAlgorithm;
118
- (function (ChecksumAlgorithm) {
119
- ChecksumAlgorithm["MD5"] = "MD5";
120
- ChecksumAlgorithm["CRC32"] = "CRC32";
121
- ChecksumAlgorithm["CRC32C"] = "CRC32C";
122
- ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME";
123
- ChecksumAlgorithm["SHA1"] = "SHA1";
124
- ChecksumAlgorithm["SHA256"] = "SHA256";
125
- })(ChecksumAlgorithm || (ChecksumAlgorithm = {}));
126
- var ChecksumLocation;
127
- (function (ChecksumLocation) {
128
- ChecksumLocation["HEADER"] = "header";
129
- ChecksumLocation["TRAILER"] = "trailer";
130
- })(ChecksumLocation || (ChecksumLocation = {}));
131
- const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32;
132
-
133
- var SelectorType;
134
- (function (SelectorType) {
135
- SelectorType["ENV"] = "env";
136
- SelectorType["CONFIG"] = "shared config entry";
137
- })(SelectorType || (SelectorType = {}));
138
- const stringUnionSelector = (obj, key, union, type) => {
139
- if (!(key in obj))
140
- return undefined;
141
- const value = obj[key].toUpperCase();
142
- if (!Object.values(union).includes(value)) {
143
- throw new TypeError(`Cannot load ${type} '${key}'. Expected one of ${Object.values(union)}, got '${obj[key]}'.`);
144
- }
145
- return value;
146
- };
147
-
148
- const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION";
149
- const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation";
150
- const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = {
151
- environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV),
152
- configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG),
153
- default: DEFAULT_REQUEST_CHECKSUM_CALCULATION,
154
- };
155
-
156
- const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION";
157
- const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation";
158
- const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = {
159
- environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV),
160
- configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG),
161
- default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION,
162
- };
163
-
164
- const getChecksumAlgorithmForRequest = (input, { requestChecksumRequired, requestAlgorithmMember, requestChecksumCalculation }) => {
165
- if (!requestAlgorithmMember) {
166
- return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired
167
- ? DEFAULT_CHECKSUM_ALGORITHM
168
- : undefined;
169
- }
170
- if (!input[requestAlgorithmMember]) {
171
- return undefined;
172
- }
173
- const checksumAlgorithm = input[requestAlgorithmMember];
174
- return checksumAlgorithm;
175
- };
176
-
177
- const getChecksumLocationName = (algorithm) => algorithm === ChecksumAlgorithm.MD5 ? "content-md5" : `x-amz-checksum-${algorithm.toLowerCase()}`;
178
-
179
- const hasHeader = (header, headers) => {
180
- const soughtHeader = header.toLowerCase();
181
- for (const headerName of Object.keys(headers)) {
182
- if (soughtHeader === headerName.toLowerCase()) {
183
- return true;
184
- }
185
- }
186
- return false;
187
- };
188
-
189
- const hasHeaderWithPrefix = (headerPrefix, headers) => {
190
- const soughtHeaderPrefix = headerPrefix.toLowerCase();
191
- for (const headerName of Object.keys(headers)) {
192
- if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) {
193
- return true;
194
- }
195
- }
196
- return false;
197
- };
198
-
199
- const isStreaming = (body) => body !== undefined && typeof body !== "string" && !ArrayBuffer.isView(body) && !isArrayBuffer(body);
200
-
201
- class NodeCrc32 {
202
- checksum = 0;
203
- update(data) {
204
- this.checksum = zlib.crc32(data, this.checksum);
205
- }
206
- async digest() {
207
- return numToUint8(this.checksum);
208
- }
209
- reset() {
210
- this.checksum = 0;
211
- }
212
- }
213
- const getCrc32ChecksumAlgorithmFunction = () => {
214
- if (typeof zlib.crc32 === "undefined") {
215
- return AwsCrc32;
216
- }
217
- return NodeCrc32;
218
- };
219
-
220
- const CLIENT_SUPPORTED_ALGORITHMS = [
221
- ChecksumAlgorithm.CRC32,
222
- ChecksumAlgorithm.CRC32C,
223
- ChecksumAlgorithm.CRC64NVME,
224
- ChecksumAlgorithm.SHA1,
225
- ChecksumAlgorithm.SHA256,
226
- ];
227
- const PRIORITY_ORDER_ALGORITHMS = [
228
- ChecksumAlgorithm.SHA256,
229
- ChecksumAlgorithm.SHA1,
230
- ChecksumAlgorithm.CRC32,
231
- ChecksumAlgorithm.CRC32C,
232
- ChecksumAlgorithm.CRC64NVME,
233
- ];
234
-
235
- const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
236
- const { checksumAlgorithms = {} } = config;
237
- switch (checksumAlgorithm) {
238
- case ChecksumAlgorithm.MD5:
239
- return checksumAlgorithms?.MD5 ?? config.md5;
240
- case ChecksumAlgorithm.CRC32:
241
- return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction();
242
- case ChecksumAlgorithm.CRC32C:
243
- return checksumAlgorithms?.CRC32C ?? AwsCrc32c;
244
- case ChecksumAlgorithm.CRC64NVME:
245
- if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
246
- return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme;
247
- }
248
- return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme;
249
- case ChecksumAlgorithm.SHA1:
250
- return checksumAlgorithms?.SHA1 ?? config.sha1;
251
- case ChecksumAlgorithm.SHA256:
252
- return checksumAlgorithms?.SHA256 ?? config.sha256;
253
- default:
254
- if (checksumAlgorithms?.[checksumAlgorithm]) {
255
- return checksumAlgorithms[checksumAlgorithm];
256
- }
257
- throw new Error(`The checksum algorithm "${checksumAlgorithm}" is not supported by the client.` +
258
- ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}, or provide an implementation to ` +
259
- ` the client constructor checksums field.`);
260
- }
261
- };
262
-
263
- const stringHasher = (checksumAlgorithmFn, body) => {
264
- const hash = new checksumAlgorithmFn();
265
- hash.update(toUint8Array(body || ""));
266
- return hash.digest();
267
- };
268
-
269
- const flexibleChecksumsMiddlewareOptions = {
270
- name: "flexibleChecksumsMiddleware",
271
- step: "build",
272
- tags: ["BODY_CHECKSUM"],
273
- override: true,
274
- };
275
- const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
276
- if (!HttpRequest.isInstance(args.request)) {
277
- return next(args);
278
- }
279
- if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) {
280
- return next(args);
281
- }
282
- const { request, input } = args;
283
- const { body: requestBody, headers } = request;
284
- const { base64Encoder, streamHasher } = config;
285
- const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig;
286
- const requestChecksumCalculation = await config.requestChecksumCalculation();
287
- const requestAlgorithmMemberName = requestAlgorithmMember?.name;
288
- const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader;
289
- if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) {
290
- if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) {
291
- input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM;
292
- if (requestAlgorithmMemberHttpHeader) {
293
- headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM;
294
- }
295
- }
296
- }
297
- const checksumAlgorithm = getChecksumAlgorithmForRequest(input, {
298
- requestChecksumRequired,
299
- requestAlgorithmMember: requestAlgorithmMember?.name,
300
- requestChecksumCalculation,
301
- });
302
- let updatedBody = requestBody;
303
- let updatedHeaders = headers;
304
- if (checksumAlgorithm) {
305
- switch (checksumAlgorithm) {
306
- case ChecksumAlgorithm.CRC32:
307
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32", "U");
308
- break;
309
- case ChecksumAlgorithm.CRC32C:
310
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC32C", "V");
311
- break;
312
- case ChecksumAlgorithm.CRC64NVME:
313
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_CRC64", "W");
314
- break;
315
- case ChecksumAlgorithm.SHA1:
316
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA1", "X");
317
- break;
318
- case ChecksumAlgorithm.SHA256:
319
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_SHA256", "Y");
320
- break;
321
- }
322
- const checksumLocationName = getChecksumLocationName(checksumAlgorithm);
323
- const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config);
324
- if (isStreaming(requestBody)) {
325
- const { getAwsChunkedEncodingStream, bodyLengthChecker } = config;
326
- updatedBody = getAwsChunkedEncodingStream(typeof config.requestStreamBufferSize === "number" && config.requestStreamBufferSize >= 8 * 1024
327
- ? createBufferedReadable(requestBody, config.requestStreamBufferSize, context.logger)
328
- : requestBody, {
329
- base64Encoder,
330
- bodyLengthChecker,
331
- checksumLocationName,
332
- checksumAlgorithmFn,
333
- streamHasher,
334
- });
335
- updatedHeaders = {
336
- ...headers,
337
- "content-encoding": headers["content-encoding"]
338
- ? `${headers["content-encoding"]},aws-chunked`
339
- : "aws-chunked",
340
- "transfer-encoding": "chunked",
341
- "x-amz-decoded-content-length": headers["content-length"],
342
- "x-amz-content-sha256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
343
- "x-amz-trailer": checksumLocationName,
344
- };
345
- delete updatedHeaders["content-length"];
346
- }
347
- else if (!hasHeader(checksumLocationName, headers)) {
348
- const rawChecksum = await stringHasher(checksumAlgorithmFn, requestBody);
349
- updatedHeaders = {
350
- ...headers,
351
- [checksumLocationName]: base64Encoder(rawChecksum),
352
- };
353
- }
354
- }
355
- try {
356
- const result = await next({
357
- ...args,
358
- request: {
359
- ...request,
360
- headers: updatedHeaders,
361
- body: updatedBody,
362
- },
363
- });
364
- return result;
365
- }
366
- catch (e) {
367
- if (e instanceof Error && e.name === "InvalidChunkSizeError") {
368
- try {
369
- if (!e.message.endsWith(".")) {
370
- e.message += ".";
371
- }
372
- e.message +=
373
- " Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream.";
374
- }
375
- catch (ignored) {
376
- }
377
- }
378
- throw e;
379
- }
380
- };
381
-
382
- const flexibleChecksumsInputMiddlewareOptions = {
383
- name: "flexibleChecksumsInputMiddleware",
384
- toMiddleware: "serializerMiddleware",
385
- relation: "before",
386
- tags: ["BODY_CHECKSUM"],
387
- override: true,
388
- };
389
- const flexibleChecksumsInputMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
390
- const input = args.input;
391
- const { requestValidationModeMember } = middlewareConfig;
392
- const requestChecksumCalculation = await config.requestChecksumCalculation();
393
- const responseChecksumValidation = await config.responseChecksumValidation();
394
- switch (requestChecksumCalculation) {
395
- case RequestChecksumCalculation.WHEN_REQUIRED:
396
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED", "a");
397
- break;
398
- case RequestChecksumCalculation.WHEN_SUPPORTED:
399
- setFeature(context, "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED", "Z");
400
- break;
401
- }
402
- switch (responseChecksumValidation) {
403
- case ResponseChecksumValidation.WHEN_REQUIRED:
404
- setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED", "c");
405
- break;
406
- case ResponseChecksumValidation.WHEN_SUPPORTED:
407
- setFeature(context, "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED", "b");
408
- break;
409
- }
410
- if (requestValidationModeMember && !input[requestValidationModeMember]) {
411
- if (responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) {
412
- input[requestValidationModeMember] = "ENABLED";
413
- }
414
- }
415
- return next(args);
416
- };
417
-
418
- const getChecksumAlgorithmListForResponse = (responseAlgorithms = []) => {
419
- const validChecksumAlgorithms = [];
420
- let i = PRIORITY_ORDER_ALGORITHMS.length;
421
- for (const algorithm of responseAlgorithms) {
422
- const priority = PRIORITY_ORDER_ALGORITHMS.indexOf(algorithm);
423
- if (priority !== -1) {
424
- validChecksumAlgorithms[priority] = algorithm;
425
- }
426
- else {
427
- validChecksumAlgorithms[i++] = algorithm;
428
- }
429
- }
430
- return validChecksumAlgorithms.filter(Boolean);
431
- };
432
-
433
- const isChecksumWithPartNumber = (checksum) => {
434
- const lastHyphenIndex = checksum.lastIndexOf("-");
435
- if (lastHyphenIndex !== -1) {
436
- const numberPart = checksum.slice(lastHyphenIndex + 1);
437
- if (!numberPart.startsWith("0")) {
438
- const number = parseInt(numberPart, 10);
439
- if (!isNaN(number) && number >= 1 && number <= 10000) {
440
- return true;
441
- }
442
- }
443
- }
444
- return false;
445
- };
446
-
447
- const getChecksum = async (body, { checksumAlgorithmFn, base64Encoder }) => base64Encoder(await stringHasher(checksumAlgorithmFn, body));
448
-
449
- const validateChecksumFromResponse = async (response, { config, responseAlgorithms, logger }) => {
450
- const checksumAlgorithms = getChecksumAlgorithmListForResponse(responseAlgorithms);
451
- const { body: responseBody, headers: responseHeaders } = response;
452
- for (const algorithm of checksumAlgorithms) {
453
- const responseHeader = getChecksumLocationName(algorithm);
454
- const checksumFromResponse = responseHeaders[responseHeader];
455
- if (checksumFromResponse) {
456
- let checksumAlgorithmFn;
457
- try {
458
- checksumAlgorithmFn = selectChecksumAlgorithmFunction(algorithm, config);
459
- }
460
- catch (error) {
461
- if (algorithm === ChecksumAlgorithm.CRC64NVME) {
462
- logger?.warn(`Skipping ${ChecksumAlgorithm.CRC64NVME} checksum validation: ${error.message}`);
463
- continue;
464
- }
465
- throw error;
466
- }
467
- const { base64Encoder } = config;
468
- if (isStreaming(responseBody)) {
469
- response.body = createChecksumStream({
470
- expectedChecksum: checksumFromResponse,
471
- checksumSourceLocation: responseHeader,
472
- checksum: new checksumAlgorithmFn(),
473
- source: responseBody,
474
- base64Encoder,
475
- });
476
- return;
477
- }
478
- const checksum = await getChecksum(responseBody, { checksumAlgorithmFn, base64Encoder });
479
- if (checksum === checksumFromResponse) {
480
- break;
481
- }
482
- throw new Error(`Checksum mismatch: expected "${checksum}" but received "${checksumFromResponse}"` +
483
- ` in response header "${responseHeader}".`);
484
- }
485
- }
486
- };
487
-
488
- const flexibleChecksumsResponseMiddlewareOptions = {
489
- name: "flexibleChecksumsResponseMiddleware",
490
- toMiddleware: "deserializerMiddleware",
491
- relation: "after",
492
- tags: ["BODY_CHECKSUM"],
493
- override: true,
494
- };
495
- const flexibleChecksumsResponseMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
496
- if (!HttpRequest.isInstance(args.request)) {
497
- return next(args);
498
- }
499
- const input = args.input;
500
- const result = await next(args);
501
- const response = result.response;
502
- const { requestValidationModeMember, responseAlgorithms } = middlewareConfig;
503
- if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") {
504
- const { clientName, commandName } = context;
505
- const customChecksumAlgorithms = Object.keys(config.checksumAlgorithms ?? {}).filter((algorithm) => {
506
- const responseHeader = getChecksumLocationName(algorithm);
507
- return response.headers[responseHeader] !== undefined;
508
- });
509
- const algoList = getChecksumAlgorithmListForResponse([
510
- ...(responseAlgorithms ?? []),
511
- ...customChecksumAlgorithms,
512
- ]);
513
- const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" &&
514
- commandName === "GetObjectCommand" &&
515
- algoList.every((algorithm) => {
516
- const responseHeader = getChecksumLocationName(algorithm);
517
- const checksumFromResponse = response.headers[responseHeader];
518
- return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse);
519
- });
520
- if (isS3WholeObjectMultipartGetResponseChecksum) {
521
- return result;
522
- }
523
- await validateChecksumFromResponse(response, {
524
- config,
525
- responseAlgorithms: algoList,
526
- logger: context.logger,
527
- });
528
- }
529
- return result;
530
- };
531
-
532
- const getFlexibleChecksumsPlugin = (config, middlewareConfig) => ({
533
- applyToStack: (clientStack) => {
534
- clientStack.add(flexibleChecksumsMiddleware(config, middlewareConfig), flexibleChecksumsMiddlewareOptions);
535
- clientStack.addRelativeTo(flexibleChecksumsInputMiddleware(config, middlewareConfig), flexibleChecksumsInputMiddlewareOptions);
536
- clientStack.addRelativeTo(flexibleChecksumsResponseMiddleware(config, middlewareConfig), flexibleChecksumsResponseMiddlewareOptions);
537
- },
538
- });
539
-
540
- const resolveFlexibleChecksumsConfig = (input) => {
541
- const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input;
542
- return Object.assign(input, {
543
- requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION),
544
- responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION),
545
- requestStreamBufferSize: Number(requestStreamBufferSize ?? 0),
546
- checksumAlgorithms: input.checksumAlgorithms ?? {},
547
- });
548
- };
549
-
1
+ const { Crc64Nvme, Crc64NvmeJs, crc64NvmeCrtContainer } = require("@aws-sdk/checksums/crc");
2
+ exports.Crc64Nvme = Crc64Nvme;
3
+ exports.Crc64NvmeJs = Crc64NvmeJs;
4
+ exports.crc64NvmeCrtContainer = crc64NvmeCrtContainer;
5
+ const { CONFIG_REQUEST_CHECKSUM_CALCULATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ENV_REQUEST_CHECKSUM_CALCULATION, ENV_RESPONSE_CHECKSUM_VALIDATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, RequestChecksumCalculation, ResponseChecksumValidation, flexibleChecksumsMiddleware, flexibleChecksumsMiddlewareOptions, getFlexibleChecksumsPlugin, resolveFlexibleChecksumsConfig } = require("@aws-sdk/checksums/flexible-checksums");
550
6
  exports.CONFIG_REQUEST_CHECKSUM_CALCULATION = CONFIG_REQUEST_CHECKSUM_CALCULATION;
551
7
  exports.CONFIG_RESPONSE_CHECKSUM_VALIDATION = CONFIG_RESPONSE_CHECKSUM_VALIDATION;
552
8
  exports.ChecksumAlgorithm = ChecksumAlgorithm;
553
9
  exports.ChecksumLocation = ChecksumLocation;
554
- exports.Crc64Nvme = Crc64Nvme;
555
10
  exports.DEFAULT_CHECKSUM_ALGORITHM = DEFAULT_CHECKSUM_ALGORITHM;
556
11
  exports.DEFAULT_REQUEST_CHECKSUM_CALCULATION = DEFAULT_REQUEST_CHECKSUM_CALCULATION;
557
12
  exports.DEFAULT_RESPONSE_CHECKSUM_VALIDATION = DEFAULT_RESPONSE_CHECKSUM_VALIDATION;
@@ -561,7 +16,6 @@ exports.NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = NODE_REQUEST_CHECKSUM
561
16
  exports.NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS;
562
17
  exports.RequestChecksumCalculation = RequestChecksumCalculation;
563
18
  exports.ResponseChecksumValidation = ResponseChecksumValidation;
564
- exports.crc64NvmeCrtContainer = crc64NvmeCrtContainer;
565
19
  exports.flexibleChecksumsMiddleware = flexibleChecksumsMiddleware;
566
20
  exports.flexibleChecksumsMiddlewareOptions = flexibleChecksumsMiddlewareOptions;
567
21
  exports.getFlexibleChecksumsPlugin = getFlexibleChecksumsPlugin;