@depup/aws-sdk__checksums 3.1000.18-depup.0

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 (128) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/crc.d.ts +5 -0
  5. package/crc.js +5 -0
  6. package/dist-cjs/index.js +22 -0
  7. package/dist-cjs/submodules/crc/index.js +159 -0
  8. package/dist-cjs/submodules/flexible-checksums/index.js +444 -0
  9. package/dist-cjs/submodules/md5/index.js +4 -0
  10. package/dist-cjs/submodules/sha/index.js +312 -0
  11. package/dist-es/index.js +2 -0
  12. package/dist-es/submodules/crc/crc32c/Crc32cJs.js +31 -0
  13. package/dist-es/submodules/crc/crc32c/Crc32cNode.js +2 -0
  14. package/dist-es/submodules/crc/crc64-nvme/Crc64Nvme.js +18 -0
  15. package/dist-es/submodules/crc/crc64-nvme/Crc64NvmeJs.js +92 -0
  16. package/dist-es/submodules/crc/crc64-nvme/crc64-nvme-crt-container.js +3 -0
  17. package/dist-es/submodules/crc/index.browser.js +6 -0
  18. package/dist-es/submodules/crc/index.js +6 -0
  19. package/dist-es/submodules/flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.js +9 -0
  20. package/dist-es/submodules/flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.js +9 -0
  21. package/dist-es/submodules/flexible-checksums/configuration.js +1 -0
  22. package/dist-es/submodules/flexible-checksums/constants.js +25 -0
  23. package/dist-es/submodules/flexible-checksums/flexibleChecksumsInputMiddleware.js +37 -0
  24. package/dist-es/submodules/flexible-checksums/flexibleChecksumsMiddleware.js +123 -0
  25. package/dist-es/submodules/flexible-checksums/flexibleChecksumsResponseMiddleware.js +48 -0
  26. package/dist-es/submodules/flexible-checksums/getChecksum.js +2 -0
  27. package/dist-es/submodules/flexible-checksums/getChecksumAlgorithmForRequest.js +13 -0
  28. package/dist-es/submodules/flexible-checksums/getChecksumAlgorithmListForResponse.js +15 -0
  29. package/dist-es/submodules/flexible-checksums/getChecksumLocationName.js +2 -0
  30. package/dist-es/submodules/flexible-checksums/getFlexibleChecksumsPlugin.js +10 -0
  31. package/dist-es/submodules/flexible-checksums/hasHeader.js +9 -0
  32. package/dist-es/submodules/flexible-checksums/hasHeaderWithPrefix.js +9 -0
  33. package/dist-es/submodules/flexible-checksums/index.js +6 -0
  34. package/dist-es/submodules/flexible-checksums/isChecksumWithPartNumber.js +13 -0
  35. package/dist-es/submodules/flexible-checksums/isStreaming.js +2 -0
  36. package/dist-es/submodules/flexible-checksums/resolveFlexibleChecksumsConfig.js +11 -0
  37. package/dist-es/submodules/flexible-checksums/selectChecksumAlgorithmFunction.js +27 -0
  38. package/dist-es/submodules/flexible-checksums/stringHasher.js +6 -0
  39. package/dist-es/submodules/flexible-checksums/stringUnionSelector.js +14 -0
  40. package/dist-es/submodules/flexible-checksums/types.js +15 -0
  41. package/dist-es/submodules/flexible-checksums/validateChecksumFromResponse.js +45 -0
  42. package/dist-es/submodules/md5/index.js +1 -0
  43. package/dist-es/submodules/sha/index.browser.js +4 -0
  44. package/dist-es/submodules/sha/index.js +4 -0
  45. package/dist-es/submodules/sha/sha1/Sha1Js.js +173 -0
  46. package/dist-es/submodules/sha/sha1/Sha1Node.js +59 -0
  47. package/dist-es/submodules/sha/sha1/Sha1WebCrypto.js +71 -0
  48. package/dist-types/index.d.ts +3 -0
  49. package/dist-types/submodules/crc/crc32c/Crc32cJs.d.ts +13 -0
  50. package/dist-types/submodules/crc/crc32c/Crc32cNode.d.ts +13 -0
  51. package/dist-types/submodules/crc/crc64-nvme/Crc64Nvme.d.ts +21 -0
  52. package/dist-types/submodules/crc/crc64-nvme/Crc64NvmeJs.d.ts +14 -0
  53. package/dist-types/submodules/crc/crc64-nvme/crc64-nvme-crt-container.d.ts +11 -0
  54. package/dist-types/submodules/crc/index.browser.d.ts +5 -0
  55. package/dist-types/submodules/crc/index.d.ts +6 -0
  56. package/dist-types/submodules/flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +14 -0
  57. package/dist-types/submodules/flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +14 -0
  58. package/dist-types/submodules/flexible-checksums/configuration.d.ts +58 -0
  59. package/dist-types/submodules/flexible-checksums/constants.d.ts +83 -0
  60. package/dist-types/submodules/flexible-checksums/flexibleChecksumsInputMiddleware.d.ts +22 -0
  61. package/dist-types/submodules/flexible-checksums/flexibleChecksumsMiddleware.d.ts +33 -0
  62. package/dist-types/submodules/flexible-checksums/flexibleChecksumsResponseMiddleware.d.ts +27 -0
  63. package/dist-types/submodules/flexible-checksums/getChecksum.d.ts +6 -0
  64. package/dist-types/submodules/flexible-checksums/getChecksumAlgorithmForRequest.d.ts +22 -0
  65. package/dist-types/submodules/flexible-checksums/getChecksumAlgorithmListForResponse.d.ts +6 -0
  66. package/dist-types/submodules/flexible-checksums/getChecksumLocationName.d.ts +5 -0
  67. package/dist-types/submodules/flexible-checksums/getFlexibleChecksumsPlugin.d.ts +14 -0
  68. package/dist-types/submodules/flexible-checksums/hasHeader.d.ts +6 -0
  69. package/dist-types/submodules/flexible-checksums/hasHeaderWithPrefix.d.ts +6 -0
  70. package/dist-types/submodules/flexible-checksums/index.d.ts +9 -0
  71. package/dist-types/submodules/flexible-checksums/isChecksumWithPartNumber.d.ts +1 -0
  72. package/dist-types/submodules/flexible-checksums/isStreaming.d.ts +4 -0
  73. package/dist-types/submodules/flexible-checksums/resolveFlexibleChecksumsConfig.d.ts +57 -0
  74. package/dist-types/submodules/flexible-checksums/selectChecksumAlgorithmFunction.d.ts +7 -0
  75. package/dist-types/submodules/flexible-checksums/stringHasher.d.ts +5 -0
  76. package/dist-types/submodules/flexible-checksums/stringUnionSelector.d.ts +12 -0
  77. package/dist-types/submodules/flexible-checksums/types.d.ts +9 -0
  78. package/dist-types/submodules/flexible-checksums/validateChecksumFromResponse.d.ts +13 -0
  79. package/dist-types/submodules/md5/index.d.ts +1 -0
  80. package/dist-types/submodules/sha/index.browser.d.ts +3 -0
  81. package/dist-types/submodules/sha/index.d.ts +4 -0
  82. package/dist-types/submodules/sha/sha1/Sha1Js.d.ts +26 -0
  83. package/dist-types/submodules/sha/sha1/Sha1Node.d.ts +13 -0
  84. package/dist-types/submodules/sha/sha1/Sha1WebCrypto.d.ts +22 -0
  85. package/dist-types/ts3.4/index.d.ts +26 -0
  86. package/dist-types/ts3.4/submodules/crc/crc32c/Crc32cJs.d.ts +8 -0
  87. package/dist-types/ts3.4/submodules/crc/crc32c/Crc32cNode.d.ts +5 -0
  88. package/dist-types/ts3.4/submodules/crc/crc64-nvme/Crc64Nvme.d.ts +8 -0
  89. package/dist-types/ts3.4/submodules/crc/crc64-nvme/Crc64NvmeJs.d.ts +9 -0
  90. package/dist-types/ts3.4/submodules/crc/crc64-nvme/crc64-nvme-crt-container.d.ts +4 -0
  91. package/dist-types/ts3.4/submodules/crc/index.browser.d.ts +5 -0
  92. package/dist-types/ts3.4/submodules/crc/index.d.ts +6 -0
  93. package/dist-types/ts3.4/submodules/flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.d.ts +5 -0
  94. package/dist-types/ts3.4/submodules/flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.d.ts +5 -0
  95. package/dist-types/ts3.4/submodules/flexible-checksums/configuration.d.ts +26 -0
  96. package/dist-types/ts3.4/submodules/flexible-checksums/constants.d.ts +27 -0
  97. package/dist-types/ts3.4/submodules/flexible-checksums/flexibleChecksumsInputMiddleware.d.ts +10 -0
  98. package/dist-types/ts3.4/submodules/flexible-checksums/flexibleChecksumsMiddleware.d.ts +14 -0
  99. package/dist-types/ts3.4/submodules/flexible-checksums/flexibleChecksumsResponseMiddleware.d.ts +11 -0
  100. package/dist-types/ts3.4/submodules/flexible-checksums/getChecksum.d.ts +9 -0
  101. package/dist-types/ts3.4/submodules/flexible-checksums/getChecksumAlgorithmForRequest.d.ts +15 -0
  102. package/dist-types/ts3.4/submodules/flexible-checksums/getChecksumAlgorithmListForResponse.d.ts +4 -0
  103. package/dist-types/ts3.4/submodules/flexible-checksums/getChecksumLocationName.d.ts +2 -0
  104. package/dist-types/ts3.4/submodules/flexible-checksums/getFlexibleChecksumsPlugin.d.ts +14 -0
  105. package/dist-types/ts3.4/submodules/flexible-checksums/hasHeader.d.ts +2 -0
  106. package/dist-types/ts3.4/submodules/flexible-checksums/hasHeaderWithPrefix.d.ts +2 -0
  107. package/dist-types/ts3.4/submodules/flexible-checksums/index.d.ts +31 -0
  108. package/dist-types/ts3.4/submodules/flexible-checksums/isChecksumWithPartNumber.d.ts +1 -0
  109. package/dist-types/ts3.4/submodules/flexible-checksums/isStreaming.d.ts +1 -0
  110. package/dist-types/ts3.4/submodules/flexible-checksums/resolveFlexibleChecksumsConfig.d.ts +25 -0
  111. package/dist-types/ts3.4/submodules/flexible-checksums/selectChecksumAlgorithmFunction.d.ts +7 -0
  112. package/dist-types/ts3.4/submodules/flexible-checksums/stringHasher.d.ts +5 -0
  113. package/dist-types/ts3.4/submodules/flexible-checksums/stringUnionSelector.d.ts +10 -0
  114. package/dist-types/ts3.4/submodules/flexible-checksums/types.d.ts +3 -0
  115. package/dist-types/ts3.4/submodules/flexible-checksums/validateChecksumFromResponse.d.ts +12 -0
  116. package/dist-types/ts3.4/submodules/md5/index.d.ts +1 -0
  117. package/dist-types/ts3.4/submodules/sha/index.browser.d.ts +3 -0
  118. package/dist-types/ts3.4/submodules/sha/index.d.ts +4 -0
  119. package/dist-types/ts3.4/submodules/sha/sha1/Sha1Js.d.ts +20 -0
  120. package/dist-types/ts3.4/submodules/sha/sha1/Sha1Node.d.ts +5 -0
  121. package/dist-types/ts3.4/submodules/sha/sha1/Sha1WebCrypto.d.ts +14 -0
  122. package/flexible-checksums.d.ts +5 -0
  123. package/flexible-checksums.js +5 -0
  124. package/md5.d.ts +5 -0
  125. package/md5.js +5 -0
  126. package/package.json +159 -0
  127. package/sha.d.ts +5 -0
  128. package/sha.js +5 -0
@@ -0,0 +1,312 @@
1
+ const { toUint8Array, concatBytes } = require("@smithy/core/serde");
2
+ const { createHmac, createHash } = require("node:crypto");
3
+ const { Sha256, Sha256Js, Sha256Node } = require("@smithy/core/checksum");
4
+ exports.Sha256 = Sha256;
5
+ exports.Sha256Js = Sha256Js;
6
+ exports.Sha256Node = Sha256Node;
7
+
8
+ const BLOCK = 64;
9
+ const DIGEST_LENGTH = 20;
10
+ const INIT = new Int32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
11
+ const K = new Int32Array([0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]);
12
+ class Sha1Js {
13
+ digestLength = DIGEST_LENGTH;
14
+ state = Int32Array.from(INIT);
15
+ w;
16
+ buffer = new Uint8Array(BLOCK);
17
+ bufferLength = 0;
18
+ bytesHashed = 0;
19
+ finished = false;
20
+ inner;
21
+ outer;
22
+ constructor(secret) {
23
+ if (secret) {
24
+ const key = Sha1Js.normalizeKey(secret);
25
+ this.inner = new Sha1Js();
26
+ this.outer = new Sha1Js();
27
+ const pad = new Uint8Array(BLOCK * 2);
28
+ for (let i = 0; i < BLOCK; ++i) {
29
+ pad[i] = 0x36 ^ key[i];
30
+ pad[i + BLOCK] = 0x5c ^ key[i];
31
+ }
32
+ this.inner.update(pad.subarray(0, BLOCK));
33
+ this.outer.update(pad.subarray(BLOCK));
34
+ }
35
+ }
36
+ update(data) {
37
+ if (this.finished) {
38
+ throw new Error("Attempted to update an already finished HMAC.");
39
+ }
40
+ if (this.inner) {
41
+ this.inner.update(data);
42
+ return;
43
+ }
44
+ let pos = 0;
45
+ let { length } = data;
46
+ this.bytesHashed += length;
47
+ if (this.bufferLength > 0) {
48
+ while (length > 0 && this.bufferLength < BLOCK) {
49
+ this.buffer[this.bufferLength++] = data[pos++];
50
+ --length;
51
+ }
52
+ if (this.bufferLength === BLOCK) {
53
+ this.hashBuffer(this.buffer, 0);
54
+ this.bufferLength = 0;
55
+ }
56
+ }
57
+ while (length >= BLOCK) {
58
+ this.hashBuffer(data, pos);
59
+ pos += BLOCK;
60
+ length -= BLOCK;
61
+ }
62
+ while (length > 0) {
63
+ this.buffer[this.bufferLength++] = data[pos++];
64
+ --length;
65
+ }
66
+ }
67
+ async digest() {
68
+ if (this.inner && this.outer) {
69
+ if (this.finished) {
70
+ throw new Error("Attempted to digest an already finished HMAC.");
71
+ }
72
+ this.finished = true;
73
+ const innerDigest = this.inner.digestSync();
74
+ this.outer.update(innerDigest);
75
+ return this.outer.digestSync();
76
+ }
77
+ return this.digestSync();
78
+ }
79
+ reset() {
80
+ this.state = Int32Array.from(INIT);
81
+ this.buffer = new Uint8Array(BLOCK);
82
+ this.bufferLength = 0;
83
+ this.bytesHashed = 0;
84
+ }
85
+ digestSync() {
86
+ const state = this.state.slice();
87
+ const buffer = this.buffer.slice();
88
+ let bufferLength = this.bufferLength;
89
+ const bitsHi = (this.bytesHashed / 0x20000000) | 0;
90
+ const bitsLo = this.bytesHashed << 3;
91
+ buffer[bufferLength++] = 0x80;
92
+ if (bufferLength > BLOCK - 8) {
93
+ for (let i = bufferLength; i < BLOCK; ++i) {
94
+ buffer[i] = 0;
95
+ }
96
+ this.hashBufferWith(state, buffer, 0);
97
+ bufferLength = 0;
98
+ }
99
+ for (let i = bufferLength; i < BLOCK - 8; ++i) {
100
+ buffer[i] = 0;
101
+ }
102
+ const v = new DataView(buffer.buffer, buffer.byteOffset, BLOCK);
103
+ v.setUint32(BLOCK - 8, bitsHi, false);
104
+ v.setUint32(BLOCK - 4, bitsLo, false);
105
+ this.hashBufferWith(state, buffer, 0);
106
+ const out = new Uint8Array(DIGEST_LENGTH);
107
+ out[0] = (state[0] >>> 24) & 0xff;
108
+ out[1] = (state[0] >>> 16) & 0xff;
109
+ out[2] = (state[0] >>> 8) & 0xff;
110
+ out[3] = state[0] & 0xff;
111
+ out[4] = (state[1] >>> 24) & 0xff;
112
+ out[5] = (state[1] >>> 16) & 0xff;
113
+ out[6] = (state[1] >>> 8) & 0xff;
114
+ out[7] = state[1] & 0xff;
115
+ out[8] = (state[2] >>> 24) & 0xff;
116
+ out[9] = (state[2] >>> 16) & 0xff;
117
+ out[10] = (state[2] >>> 8) & 0xff;
118
+ out[11] = state[2] & 0xff;
119
+ out[12] = (state[3] >>> 24) & 0xff;
120
+ out[13] = (state[3] >>> 16) & 0xff;
121
+ out[14] = (state[3] >>> 8) & 0xff;
122
+ out[15] = state[3] & 0xff;
123
+ out[16] = (state[4] >>> 24) & 0xff;
124
+ out[17] = (state[4] >>> 16) & 0xff;
125
+ out[18] = (state[4] >>> 8) & 0xff;
126
+ out[19] = state[4] & 0xff;
127
+ return out;
128
+ }
129
+ static normalizeKey(secret) {
130
+ const key = toUint8Array(secret);
131
+ if (key.byteLength > BLOCK) {
132
+ const h = new Sha1Js();
133
+ h.update(key);
134
+ const digest = h.digestSync();
135
+ const padded = new Uint8Array(BLOCK);
136
+ padded.set(digest);
137
+ return padded;
138
+ }
139
+ const padded = new Uint8Array(BLOCK);
140
+ padded.set(key);
141
+ return padded;
142
+ }
143
+ hashBuffer(data, offset) {
144
+ this.hashBufferWith(this.state, data, offset);
145
+ }
146
+ hashBufferWith(state, data, offset) {
147
+ const w = (this.w ??= new Int32Array(80));
148
+ let s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3], s4 = state[4];
149
+ for (let t = 0; t < 16; ++t) {
150
+ w[t] =
151
+ ((data[offset + t * 4] & 0xff) << 24) |
152
+ ((data[offset + t * 4 + 1] & 0xff) << 16) |
153
+ ((data[offset + t * 4 + 2] & 0xff) << 8) |
154
+ (data[offset + t * 4 + 3] & 0xff);
155
+ }
156
+ for (let t = 16; t < 80; ++t) {
157
+ const x = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16];
158
+ w[t] = (x << 1) | (x >>> 31);
159
+ }
160
+ for (let t = 0; t < 80; ++t) {
161
+ const r = t < 20 ? 0 : t < 40 ? 1 : t < 60 ? 2 : 3;
162
+ const temp = (((((s0 << 5) | (s0 >>> 27)) +
163
+ (r === 0 ? (s1 & s2) ^ (~s1 & s3) : r === 2 ? (s1 & s2) ^ (s1 & s3) ^ (s2 & s3) : s1 ^ s2 ^ s3)) |
164
+ 0) +
165
+ ((s4 + ((K[r] + w[t]) | 0)) | 0)) |
166
+ 0;
167
+ s4 = s3;
168
+ s3 = s2;
169
+ s2 = (s1 << 30) | (s1 >>> 2);
170
+ s1 = s0;
171
+ s0 = temp;
172
+ }
173
+ state[0] = (state[0] + s0) | 0;
174
+ state[1] = (state[1] + s1) | 0;
175
+ state[2] = (state[2] + s2) | 0;
176
+ state[3] = (state[3] + s3) | 0;
177
+ state[4] = (state[4] + s4) | 0;
178
+ }
179
+ }
180
+
181
+ const hasNativeCrypto = (() => {
182
+ try {
183
+ createHash("sha1");
184
+ return true;
185
+ }
186
+ catch {
187
+ return false;
188
+ }
189
+ })();
190
+ const Sha1Node = hasNativeCrypto ? buildNativeClass() : Sha1Js;
191
+ function buildNativeClass() {
192
+ return class Sha1Node {
193
+ digestLength = 20;
194
+ secret;
195
+ hash;
196
+ isHmac;
197
+ finished = false;
198
+ constructor(secret) {
199
+ this.secret = secret;
200
+ this.isHmac = !!secret;
201
+ this.hash = this.createHash();
202
+ }
203
+ update(data) {
204
+ if (this.finished) {
205
+ throw new Error("Attempted to update an already finished hash.");
206
+ }
207
+ this.hash.update(data);
208
+ }
209
+ async digest() {
210
+ let buf;
211
+ if (this.isHmac) {
212
+ this.finished = true;
213
+ buf = this.hash.digest();
214
+ }
215
+ else {
216
+ buf = this.hash.copy().digest();
217
+ }
218
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
219
+ }
220
+ reset() {
221
+ this.hash = this.createHash();
222
+ this.finished = false;
223
+ }
224
+ createHash() {
225
+ return this.secret ? createHmac("sha1", toBuffer(this.secret)) : createHash("sha1");
226
+ }
227
+ };
228
+ }
229
+ function toBuffer(data) {
230
+ if (typeof data === "string") {
231
+ return data;
232
+ }
233
+ if (ArrayBuffer.isView(data)) {
234
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
235
+ }
236
+ return Buffer.from(data);
237
+ }
238
+
239
+ const { digest, sign, importKey } = globalThis?.crypto?.subtle ?? {};
240
+ const subtle = typeof digest === "function" && typeof sign === "function" && typeof importKey === "function"
241
+ ? globalThis.crypto.subtle
242
+ : undefined;
243
+ const MAX_PENDING_BYTES = 8 * 1024 * 1024;
244
+ class Sha1WebCrypto {
245
+ digestLength = 20;
246
+ secret;
247
+ pending = [];
248
+ pendingBytes = 0;
249
+ fallback;
250
+ finished = false;
251
+ constructor(secret) {
252
+ if (secret) {
253
+ this.secret = toUint8Array(secret);
254
+ }
255
+ }
256
+ update(data) {
257
+ if (this.finished) {
258
+ throw new Error("Attempted to update an already finished HMAC.");
259
+ }
260
+ if (this.fallback) {
261
+ this.fallback.update(data);
262
+ return;
263
+ }
264
+ this.pending.push(data.slice());
265
+ this.pendingBytes += data.byteLength;
266
+ if (this.pendingBytes >= MAX_PENDING_BYTES) {
267
+ this.switchToFallback();
268
+ }
269
+ }
270
+ async digest() {
271
+ if (this.fallback) {
272
+ return this.fallback.digest();
273
+ }
274
+ if (this.secret && this.finished) {
275
+ throw new Error("Attempted to digest an already finished HMAC.");
276
+ }
277
+ const data = concatBytes(this.pending);
278
+ if (subtle) {
279
+ if (this.secret) {
280
+ this.finished = true;
281
+ const key = await subtle.importKey("raw", this.secret, { name: "HMAC", hash: "SHA-1" }, false, ["sign"]);
282
+ const sig = await subtle.sign("HMAC", key, data);
283
+ return new Uint8Array(sig);
284
+ }
285
+ const hash = await subtle.digest("SHA-1", data);
286
+ return new Uint8Array(hash);
287
+ }
288
+ const sha1 = new Sha1Js(this.secret);
289
+ sha1.update(data);
290
+ return sha1.digest();
291
+ }
292
+ reset() {
293
+ this.pending = [];
294
+ this.pendingBytes = 0;
295
+ this.fallback = undefined;
296
+ this.finished = false;
297
+ }
298
+ switchToFallback() {
299
+ const sha1Js = new Sha1Js(this.secret);
300
+ for (const chunk of this.pending) {
301
+ sha1Js.update(chunk);
302
+ }
303
+ this.fallback = sha1Js;
304
+ this.pending = [];
305
+ this.pendingBytes = 0;
306
+ }
307
+ }
308
+
309
+ exports.Sha1 = Sha1Node;
310
+ exports.Sha1Js = Sha1Js;
311
+ exports.Sha1Node = Sha1Node;
312
+ exports.Sha1WebCrypto = Sha1WebCrypto;
@@ -0,0 +1,2 @@
1
+ export { Crc64Nvme, Crc64NvmeJs, crc64NvmeCrtContainer } from "@aws-sdk/checksums/crc";
2
+ export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, getFlexibleChecksumsPlugin, resolveFlexibleChecksumsConfig, } from "@aws-sdk/checksums/flexible-checksums";
@@ -0,0 +1,31 @@
1
+ const T = new Uint32Array(256);
2
+ for (let i = 0; i < 256; ++i) {
3
+ let c = i;
4
+ for (let j = 0; j < 8; ++j) {
5
+ c = c & 1 ? 0x82f63b78 ^ (c >>> 1) : c >>> 1;
6
+ }
7
+ T[i] = c >>> 0;
8
+ }
9
+ export class Crc32cJs {
10
+ digestLength = 4;
11
+ crc = 0xffff_ffff;
12
+ update(data) {
13
+ let crc = this.crc;
14
+ for (let i = 0; i < data.length; ++i) {
15
+ crc = (crc >>> 8) ^ T[(crc ^ data[i]) & 0xff];
16
+ }
17
+ this.crc = crc;
18
+ }
19
+ async digest() {
20
+ const value = (this.crc ^ 0xffff_ffff) >>> 0;
21
+ const out = new Uint8Array(4);
22
+ out[0] = value >>> 24;
23
+ out[1] = (value >>> 16) & 0xff;
24
+ out[2] = (value >>> 8) & 0xff;
25
+ out[3] = value & 0xff;
26
+ return out;
27
+ }
28
+ reset() {
29
+ this.crc = 0xffff_ffff;
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ import { Crc32cJs } from "./Crc32cJs";
2
+ export const Crc32cNode = Crc32cJs;
@@ -0,0 +1,18 @@
1
+ import { crc64NvmeCrtContainer } from "./crc64-nvme-crt-container";
2
+ import { Crc64NvmeJs } from "./Crc64NvmeJs";
3
+ export class Crc64Nvme {
4
+ impl;
5
+ constructor() {
6
+ const Crt = crc64NvmeCrtContainer.CrtCrc64Nvme;
7
+ this.impl = Crt ? new Crt() : new Crc64NvmeJs();
8
+ }
9
+ update(data) {
10
+ this.impl.update(data);
11
+ }
12
+ async digest() {
13
+ return this.impl.digest();
14
+ }
15
+ reset() {
16
+ this.impl.reset();
17
+ }
18
+ }
@@ -0,0 +1,92 @@
1
+ const generateCRC64NVMETable = () => {
2
+ const sliceLength = 8;
3
+ const tables = new Array(sliceLength);
4
+ for (let slice = 0; slice < sliceLength; slice++) {
5
+ const table = new Array(512);
6
+ for (let i = 0; i < 256; i++) {
7
+ let crc = BigInt(i);
8
+ for (let j = 0; j < 8 * (slice + 1); j++) {
9
+ if (crc & 1n) {
10
+ crc = (crc >> 1n) ^ 0x9a6c9329ac4bc9b5n;
11
+ }
12
+ else {
13
+ crc = crc >> 1n;
14
+ }
15
+ }
16
+ table[i * 2] = Number((crc >> 32n) & 0xffffffffn);
17
+ table[i * 2 + 1] = Number(crc & 0xffffffffn);
18
+ }
19
+ tables[slice] = new Uint32Array(table);
20
+ }
21
+ return tables;
22
+ };
23
+ let CRC64_NVME_REVERSED_TABLE;
24
+ let t0, t1, t2, t3;
25
+ let t4, t5, t6, t7;
26
+ const ensureTablesInitialized = () => {
27
+ if (!CRC64_NVME_REVERSED_TABLE) {
28
+ CRC64_NVME_REVERSED_TABLE = generateCRC64NVMETable();
29
+ [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE;
30
+ }
31
+ };
32
+ export class Crc64NvmeJs {
33
+ c1 = 0;
34
+ c2 = 0;
35
+ constructor() {
36
+ ensureTablesInitialized();
37
+ this.reset();
38
+ }
39
+ update(data) {
40
+ const len = data.length;
41
+ let i = 0;
42
+ let crc1 = this.c1;
43
+ let crc2 = this.c2;
44
+ while (i + 8 <= len) {
45
+ const idx0 = ((crc2 ^ data[i++]) & 255) << 1;
46
+ const idx1 = (((crc2 >>> 8) ^ data[i++]) & 255) << 1;
47
+ const idx2 = (((crc2 >>> 16) ^ data[i++]) & 255) << 1;
48
+ const idx3 = (((crc2 >>> 24) ^ data[i++]) & 255) << 1;
49
+ const idx4 = ((crc1 ^ data[i++]) & 255) << 1;
50
+ const idx5 = (((crc1 >>> 8) ^ data[i++]) & 255) << 1;
51
+ const idx6 = (((crc1 >>> 16) ^ data[i++]) & 255) << 1;
52
+ const idx7 = (((crc1 >>> 24) ^ data[i++]) & 255) << 1;
53
+ crc1 = t7[idx0] ^ t6[idx1] ^ t5[idx2] ^ t4[idx3] ^ t3[idx4] ^ t2[idx5] ^ t1[idx6] ^ t0[idx7];
54
+ crc2 =
55
+ t7[idx0 + 1] ^
56
+ t6[idx1 + 1] ^
57
+ t5[idx2 + 1] ^
58
+ t4[idx3 + 1] ^
59
+ t3[idx4 + 1] ^
60
+ t2[idx5 + 1] ^
61
+ t1[idx6 + 1] ^
62
+ t0[idx7 + 1];
63
+ }
64
+ while (i < len) {
65
+ const idx = ((crc2 ^ data[i]) & 255) << 1;
66
+ crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0;
67
+ crc1 = (crc1 >>> 8) ^ t0[idx];
68
+ crc2 ^= t0[idx + 1];
69
+ ++i;
70
+ }
71
+ this.c1 = crc1;
72
+ this.c2 = crc2;
73
+ }
74
+ async digest() {
75
+ const c1 = this.c1 ^ 4294967295;
76
+ const c2 = this.c2 ^ 4294967295;
77
+ return new Uint8Array([
78
+ c1 >>> 24,
79
+ (c1 >>> 16) & 255,
80
+ (c1 >>> 8) & 255,
81
+ c1 & 255,
82
+ c2 >>> 24,
83
+ (c2 >>> 16) & 255,
84
+ (c2 >>> 8) & 255,
85
+ c2 & 255,
86
+ ]);
87
+ }
88
+ reset() {
89
+ this.c1 = 4294967295;
90
+ this.c2 = 4294967295;
91
+ }
92
+ }
@@ -0,0 +1,3 @@
1
+ export const crc64NvmeCrtContainer = {
2
+ CrtCrc64Nvme: null,
3
+ };
@@ -0,0 +1,6 @@
1
+ const no = Symbol.for("node-only");
2
+ export { Crc32cJs, Crc32cJs as Crc32c } from "./crc32c/Crc32cJs";
3
+ export const Crc32cNode = no;
4
+ export { Crc64NvmeJs, Crc64NvmeJs as Crc64Nvme } from "./crc64-nvme/Crc64NvmeJs";
5
+ export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container";
6
+ export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum";
@@ -0,0 +1,6 @@
1
+ export { Crc32cJs } from "./crc32c/Crc32cJs";
2
+ export { Crc32cNode, Crc32cNode as Crc32c } from "./crc32c/Crc32cNode";
3
+ export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme";
4
+ export { Crc64NvmeJs } from "./crc64-nvme/Crc64NvmeJs";
5
+ export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container";
6
+ export { Crc32, Crc32Js, Crc32Node } from "@smithy/core/checksum";
@@ -0,0 +1,9 @@
1
+ import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation } from "./constants";
2
+ import { SelectorType, stringUnionSelector } from "./stringUnionSelector";
3
+ export const ENV_REQUEST_CHECKSUM_CALCULATION = "AWS_REQUEST_CHECKSUM_CALCULATION";
4
+ export const CONFIG_REQUEST_CHECKSUM_CALCULATION = "request_checksum_calculation";
5
+ export const NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS = {
6
+ environmentVariableSelector: (env) => stringUnionSelector(env, ENV_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.ENV),
7
+ configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_REQUEST_CHECKSUM_CALCULATION, RequestChecksumCalculation, SelectorType.CONFIG),
8
+ default: DEFAULT_REQUEST_CHECKSUM_CALCULATION,
9
+ };
@@ -0,0 +1,9 @@
1
+ import { DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation } from "./constants";
2
+ import { SelectorType, stringUnionSelector } from "./stringUnionSelector";
3
+ export const ENV_RESPONSE_CHECKSUM_VALIDATION = "AWS_RESPONSE_CHECKSUM_VALIDATION";
4
+ export const CONFIG_RESPONSE_CHECKSUM_VALIDATION = "response_checksum_validation";
5
+ export const NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS = {
6
+ environmentVariableSelector: (env) => stringUnionSelector(env, ENV_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.ENV),
7
+ configFileSelector: (profile) => stringUnionSelector(profile, CONFIG_RESPONSE_CHECKSUM_VALIDATION, ResponseChecksumValidation, SelectorType.CONFIG),
8
+ default: DEFAULT_RESPONSE_CHECKSUM_VALIDATION,
9
+ };
@@ -0,0 +1,25 @@
1
+ export const RequestChecksumCalculation = {
2
+ WHEN_SUPPORTED: "WHEN_SUPPORTED",
3
+ WHEN_REQUIRED: "WHEN_REQUIRED",
4
+ };
5
+ export const DEFAULT_REQUEST_CHECKSUM_CALCULATION = RequestChecksumCalculation.WHEN_SUPPORTED;
6
+ export const ResponseChecksumValidation = {
7
+ WHEN_SUPPORTED: "WHEN_SUPPORTED",
8
+ WHEN_REQUIRED: "WHEN_REQUIRED",
9
+ };
10
+ export const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.WHEN_SUPPORTED;
11
+ export var ChecksumAlgorithm;
12
+ (function (ChecksumAlgorithm) {
13
+ ChecksumAlgorithm["MD5"] = "MD5";
14
+ ChecksumAlgorithm["CRC32"] = "CRC32";
15
+ ChecksumAlgorithm["CRC32C"] = "CRC32C";
16
+ ChecksumAlgorithm["CRC64NVME"] = "CRC64NVME";
17
+ ChecksumAlgorithm["SHA1"] = "SHA1";
18
+ ChecksumAlgorithm["SHA256"] = "SHA256";
19
+ })(ChecksumAlgorithm || (ChecksumAlgorithm = {}));
20
+ export var ChecksumLocation;
21
+ (function (ChecksumLocation) {
22
+ ChecksumLocation["HEADER"] = "header";
23
+ ChecksumLocation["TRAILER"] = "trailer";
24
+ })(ChecksumLocation || (ChecksumLocation = {}));
25
+ export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32;
@@ -0,0 +1,37 @@
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
+ };