@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
@@ -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;
package/dist-es/index.js CHANGED
@@ -1,8 +1,2 @@
1
- export { Crc64Nvme } from "./crc64-nvme/Crc64Nvme";
2
- export { crc64NvmeCrtContainer } from "./crc64-nvme/crc64-nvme-crt-container";
3
- export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS";
4
- export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./flexible-checksums/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS";
5
- export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./flexible-checksums/constants";
6
- export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware, } from "./flexible-checksums/flexibleChecksumsMiddleware";
7
- export { getFlexibleChecksumsPlugin } from "./flexible-checksums/getFlexibleChecksumsPlugin";
8
- export { resolveFlexibleChecksumsConfig } from "./flexible-checksums/resolveFlexibleChecksumsConfig";
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
+ }
@@ -29,7 +29,7 @@ const ensureTablesInitialized = () => {
29
29
  [t0, t1, t2, t3, t4, t5, t6, t7] = CRC64_NVME_REVERSED_TABLE;
30
30
  }
31
31
  };
32
- export class Crc64Nvme {
32
+ export class Crc64NvmeJs {
33
33
  c1 = 0;
34
34
  c2 = 0;
35
35
  constructor() {
@@ -66,7 +66,7 @@ export class Crc64Nvme {
66
66
  crc2 = ((crc2 >>> 8) | ((crc1 & 255) << 24)) >>> 0;
67
67
  crc1 = (crc1 >>> 8) ^ t0[idx];
68
68
  crc2 ^= t0[idx + 1];
69
- i++;
69
+ ++i;
70
70
  }
71
71
  this.c1 = crc1;
72
72
  this.c2 = crc2;
@@ -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,6 @@
1
+ export { ENV_REQUEST_CHECKSUM_CALCULATION, CONFIG_REQUEST_CHECKSUM_CALCULATION, NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, } from "./NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS";
2
+ export { ENV_RESPONSE_CHECKSUM_VALIDATION, CONFIG_RESPONSE_CHECKSUM_VALIDATION, NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, } from "./NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS";
3
+ export { RequestChecksumCalculation, DEFAULT_REQUEST_CHECKSUM_CALCULATION, ResponseChecksumValidation, DEFAULT_RESPONSE_CHECKSUM_VALIDATION, ChecksumAlgorithm, ChecksumLocation, DEFAULT_CHECKSUM_ALGORITHM, } from "./constants";
4
+ export { flexibleChecksumsMiddlewareOptions, flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware";
5
+ export { getFlexibleChecksumsPlugin } from "./getFlexibleChecksumsPlugin";
6
+ export { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig";
@@ -1,8 +1,5 @@
1
- import { AwsCrc32c } from "@aws-crypto/crc32c";
2
- import { crc64NvmeCrtContainer } from "../crc64-nvme/crc64-nvme-crt-container";
3
- import { Crc64Nvme } from "../crc64-nvme/Crc64Nvme";
1
+ import { Crc32, Crc32c, Crc64Nvme } from "@aws-sdk/checksums/crc";
4
2
  import { ChecksumAlgorithm } from "./constants";
5
- import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
6
3
  import { CLIENT_SUPPORTED_ALGORITHMS } from "./types";
7
4
  export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
8
5
  const { checksumAlgorithms = {} } = config;
@@ -10,14 +7,11 @@ export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
10
7
  case ChecksumAlgorithm.MD5:
11
8
  return checksumAlgorithms?.MD5 ?? config.md5;
12
9
  case ChecksumAlgorithm.CRC32:
13
- return checksumAlgorithms?.CRC32 ?? getCrc32ChecksumAlgorithmFunction();
10
+ return checksumAlgorithms?.CRC32 ?? Crc32;
14
11
  case ChecksumAlgorithm.CRC32C:
15
- return checksumAlgorithms?.CRC32C ?? AwsCrc32c;
12
+ return checksumAlgorithms?.CRC32C ?? Crc32c;
16
13
  case ChecksumAlgorithm.CRC64NVME:
17
- if (typeof crc64NvmeCrtContainer.CrtCrc64Nvme !== "function") {
18
- return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme;
19
- }
20
- return checksumAlgorithms?.CRC64NVME ?? crc64NvmeCrtContainer.CrtCrc64Nvme;
14
+ return checksumAlgorithms?.CRC64NVME ?? Crc64Nvme;
21
15
  case ChecksumAlgorithm.SHA1:
22
16
  return checksumAlgorithms?.SHA1 ?? config.sha1;
23
17
  case ChecksumAlgorithm.SHA256:
@@ -0,0 +1 @@
1
+ export { Md5, Md5Js, Md5Node } from "@smithy/core/checksum";
@@ -0,0 +1,4 @@
1
+ const no = Symbol.for("node-only");
2
+ export { Sha1Js, Sha1Js as Sha1 } from "./sha1/Sha1Js";
3
+ export const Sha1Node = no;
4
+ export { Sha256, Sha256Js, Sha256Node, Sha256WebCrypto } from "@smithy/core/checksum";
@@ -0,0 +1,4 @@
1
+ export { Sha1Js } from "./sha1/Sha1Js";
2
+ export { Sha1Node, Sha1Node as Sha1 } from "./sha1/Sha1Node";
3
+ export { Sha1WebCrypto } from "./sha1/Sha1WebCrypto";
4
+ export { Sha256, Sha256Js, Sha256Node } from "@smithy/core/checksum";
@@ -0,0 +1,173 @@
1
+ import { toUint8Array } from "@smithy/core/serde";
2
+ const BLOCK = 64;
3
+ const DIGEST_LENGTH = 20;
4
+ const INIT = new Int32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
5
+ const K = new Int32Array([0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]);
6
+ export class Sha1Js {
7
+ digestLength = DIGEST_LENGTH;
8
+ state = Int32Array.from(INIT);
9
+ w;
10
+ buffer = new Uint8Array(BLOCK);
11
+ bufferLength = 0;
12
+ bytesHashed = 0;
13
+ finished = false;
14
+ inner;
15
+ outer;
16
+ constructor(secret) {
17
+ if (secret) {
18
+ const key = Sha1Js.normalizeKey(secret);
19
+ this.inner = new Sha1Js();
20
+ this.outer = new Sha1Js();
21
+ const pad = new Uint8Array(BLOCK * 2);
22
+ for (let i = 0; i < BLOCK; ++i) {
23
+ pad[i] = 0x36 ^ key[i];
24
+ pad[i + BLOCK] = 0x5c ^ key[i];
25
+ }
26
+ this.inner.update(pad.subarray(0, BLOCK));
27
+ this.outer.update(pad.subarray(BLOCK));
28
+ }
29
+ }
30
+ update(data) {
31
+ if (this.finished) {
32
+ throw new Error("Attempted to update an already finished HMAC.");
33
+ }
34
+ if (this.inner) {
35
+ this.inner.update(data);
36
+ return;
37
+ }
38
+ let pos = 0;
39
+ let { length } = data;
40
+ this.bytesHashed += length;
41
+ if (this.bufferLength > 0) {
42
+ while (length > 0 && this.bufferLength < BLOCK) {
43
+ this.buffer[this.bufferLength++] = data[pos++];
44
+ --length;
45
+ }
46
+ if (this.bufferLength === BLOCK) {
47
+ this.hashBuffer(this.buffer, 0);
48
+ this.bufferLength = 0;
49
+ }
50
+ }
51
+ while (length >= BLOCK) {
52
+ this.hashBuffer(data, pos);
53
+ pos += BLOCK;
54
+ length -= BLOCK;
55
+ }
56
+ while (length > 0) {
57
+ this.buffer[this.bufferLength++] = data[pos++];
58
+ --length;
59
+ }
60
+ }
61
+ async digest() {
62
+ if (this.inner && this.outer) {
63
+ if (this.finished) {
64
+ throw new Error("Attempted to digest an already finished HMAC.");
65
+ }
66
+ this.finished = true;
67
+ const innerDigest = this.inner.digestSync();
68
+ this.outer.update(innerDigest);
69
+ return this.outer.digestSync();
70
+ }
71
+ return this.digestSync();
72
+ }
73
+ reset() {
74
+ this.state = Int32Array.from(INIT);
75
+ this.buffer = new Uint8Array(BLOCK);
76
+ this.bufferLength = 0;
77
+ this.bytesHashed = 0;
78
+ }
79
+ digestSync() {
80
+ const state = this.state.slice();
81
+ const buffer = this.buffer.slice();
82
+ let bufferLength = this.bufferLength;
83
+ const bitsHi = (this.bytesHashed / 0x20000000) | 0;
84
+ const bitsLo = this.bytesHashed << 3;
85
+ buffer[bufferLength++] = 0x80;
86
+ if (bufferLength > BLOCK - 8) {
87
+ for (let i = bufferLength; i < BLOCK; ++i) {
88
+ buffer[i] = 0;
89
+ }
90
+ this.hashBufferWith(state, buffer, 0);
91
+ bufferLength = 0;
92
+ }
93
+ for (let i = bufferLength; i < BLOCK - 8; ++i) {
94
+ buffer[i] = 0;
95
+ }
96
+ const v = new DataView(buffer.buffer, buffer.byteOffset, BLOCK);
97
+ v.setUint32(BLOCK - 8, bitsHi, false);
98
+ v.setUint32(BLOCK - 4, bitsLo, false);
99
+ this.hashBufferWith(state, buffer, 0);
100
+ const out = new Uint8Array(DIGEST_LENGTH);
101
+ out[0] = (state[0] >>> 24) & 0xff;
102
+ out[1] = (state[0] >>> 16) & 0xff;
103
+ out[2] = (state[0] >>> 8) & 0xff;
104
+ out[3] = state[0] & 0xff;
105
+ out[4] = (state[1] >>> 24) & 0xff;
106
+ out[5] = (state[1] >>> 16) & 0xff;
107
+ out[6] = (state[1] >>> 8) & 0xff;
108
+ out[7] = state[1] & 0xff;
109
+ out[8] = (state[2] >>> 24) & 0xff;
110
+ out[9] = (state[2] >>> 16) & 0xff;
111
+ out[10] = (state[2] >>> 8) & 0xff;
112
+ out[11] = state[2] & 0xff;
113
+ out[12] = (state[3] >>> 24) & 0xff;
114
+ out[13] = (state[3] >>> 16) & 0xff;
115
+ out[14] = (state[3] >>> 8) & 0xff;
116
+ out[15] = state[3] & 0xff;
117
+ out[16] = (state[4] >>> 24) & 0xff;
118
+ out[17] = (state[4] >>> 16) & 0xff;
119
+ out[18] = (state[4] >>> 8) & 0xff;
120
+ out[19] = state[4] & 0xff;
121
+ return out;
122
+ }
123
+ static normalizeKey(secret) {
124
+ const key = toUint8Array(secret);
125
+ if (key.byteLength > BLOCK) {
126
+ const h = new Sha1Js();
127
+ h.update(key);
128
+ const digest = h.digestSync();
129
+ const padded = new Uint8Array(BLOCK);
130
+ padded.set(digest);
131
+ return padded;
132
+ }
133
+ const padded = new Uint8Array(BLOCK);
134
+ padded.set(key);
135
+ return padded;
136
+ }
137
+ hashBuffer(data, offset) {
138
+ this.hashBufferWith(this.state, data, offset);
139
+ }
140
+ hashBufferWith(state, data, offset) {
141
+ const w = (this.w ??= new Int32Array(80));
142
+ let s0 = state[0], s1 = state[1], s2 = state[2], s3 = state[3], s4 = state[4];
143
+ for (let t = 0; t < 16; ++t) {
144
+ w[t] =
145
+ ((data[offset + t * 4] & 0xff) << 24) |
146
+ ((data[offset + t * 4 + 1] & 0xff) << 16) |
147
+ ((data[offset + t * 4 + 2] & 0xff) << 8) |
148
+ (data[offset + t * 4 + 3] & 0xff);
149
+ }
150
+ for (let t = 16; t < 80; ++t) {
151
+ const x = w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16];
152
+ w[t] = (x << 1) | (x >>> 31);
153
+ }
154
+ for (let t = 0; t < 80; ++t) {
155
+ const r = t < 20 ? 0 : t < 40 ? 1 : t < 60 ? 2 : 3;
156
+ const temp = (((((s0 << 5) | (s0 >>> 27)) +
157
+ (r === 0 ? (s1 & s2) ^ (~s1 & s3) : r === 2 ? (s1 & s2) ^ (s1 & s3) ^ (s2 & s3) : s1 ^ s2 ^ s3)) |
158
+ 0) +
159
+ ((s4 + ((K[r] + w[t]) | 0)) | 0)) |
160
+ 0;
161
+ s4 = s3;
162
+ s3 = s2;
163
+ s2 = (s1 << 30) | (s1 >>> 2);
164
+ s1 = s0;
165
+ s0 = temp;
166
+ }
167
+ state[0] = (state[0] + s0) | 0;
168
+ state[1] = (state[1] + s1) | 0;
169
+ state[2] = (state[2] + s2) | 0;
170
+ state[3] = (state[3] + s3) | 0;
171
+ state[4] = (state[4] + s4) | 0;
172
+ }
173
+ }