@aws-sdk/sha256-tree-hash
Advanced tools
Comparing version 3.178.0 to 3.183.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
**Note:** Version bump only for package @aws-sdk/sha256-tree-hash | ||
# [3.178.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.177.0...v3.178.0) (2022-09-23) | ||
@@ -8,0 +16,0 @@ |
@@ -1,5 +0,4 @@ | ||
import { __awaiter, __generator, __read } from "tslib"; | ||
var MiB = 1048576; | ||
var TreeHash = (function () { | ||
function TreeHash(Sha256, fromUtf8) { | ||
const MiB = 1048576; | ||
export class TreeHash { | ||
constructor(Sha256, fromUtf8) { | ||
this.Sha256 = Sha256; | ||
@@ -9,9 +8,9 @@ this.fromUtf8 = fromUtf8; | ||
} | ||
TreeHash.prototype.hashBuffer = function () { | ||
hashBuffer() { | ||
if (!this.buffer) { | ||
return; | ||
} | ||
var remainingSize = this.buffer.byteLength; | ||
let remainingSize = this.buffer.byteLength; | ||
while (remainingSize >= MiB) { | ||
var hash = new this.Sha256(); | ||
const hash = new this.Sha256(); | ||
hash.update(this.buffer.subarray(0, MiB)); | ||
@@ -22,5 +21,5 @@ this.collectedHashDigests.push(hash.digest()); | ||
} | ||
}; | ||
TreeHash.prototype.update = function (data) { | ||
var chunk = this.convertToBuffer(data); | ||
} | ||
update(data) { | ||
const chunk = this.convertToBuffer(data); | ||
if (!this.buffer) { | ||
@@ -30,4 +29,4 @@ this.buffer = chunk; | ||
else { | ||
var totalSize = this.buffer.byteLength + chunk.byteLength; | ||
var tempBuffer = new Uint8Array(totalSize); | ||
const totalSize = this.buffer.byteLength + chunk.byteLength; | ||
const tempBuffer = new Uint8Array(totalSize); | ||
tempBuffer.set(this.buffer); | ||
@@ -38,51 +37,33 @@ tempBuffer.set(chunk, this.buffer.byteLength); | ||
this.hashBuffer(); | ||
}; | ||
TreeHash.prototype.digest = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var collectedHashDigests, smallHash, higherLevelHashDigests, i, _a, digest1, digest2, chunk, hash; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
collectedHashDigests = this.collectedHashDigests; | ||
this.collectedHashDigests = []; | ||
if (this.buffer && this.buffer.byteLength > 0) { | ||
smallHash = new this.Sha256(); | ||
smallHash.update(this.buffer); | ||
collectedHashDigests.push(smallHash.digest()); | ||
this.buffer = void 0; | ||
} | ||
_b.label = 1; | ||
case 1: | ||
if (!(collectedHashDigests.length > 1)) return [3, 7]; | ||
higherLevelHashDigests = []; | ||
i = 0; | ||
_b.label = 2; | ||
case 2: | ||
if (!(i < collectedHashDigests.length)) return [3, 6]; | ||
if (!(i + 1 < collectedHashDigests.length)) return [3, 4]; | ||
return [4, Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]])]; | ||
case 3: | ||
_a = __read.apply(void 0, [_b.sent(), 2]), digest1 = _a[0], digest2 = _a[1]; | ||
chunk = new Uint8Array(digest1.byteLength + digest2.byteLength); | ||
chunk.set(digest1); | ||
chunk.set(digest2, digest1.byteLength); | ||
hash = new this.Sha256(); | ||
hash.update(chunk); | ||
higherLevelHashDigests.push(hash.digest()); | ||
return [3, 5]; | ||
case 4: | ||
higherLevelHashDigests.push(collectedHashDigests[i]); | ||
_b.label = 5; | ||
case 5: | ||
i += 2; | ||
return [3, 2]; | ||
case 6: | ||
collectedHashDigests = higherLevelHashDigests; | ||
return [3, 1]; | ||
case 7: return [2, collectedHashDigests[0]]; | ||
} | ||
async digest() { | ||
let collectedHashDigests = this.collectedHashDigests; | ||
this.collectedHashDigests = []; | ||
if (this.buffer && this.buffer.byteLength > 0) { | ||
const smallHash = new this.Sha256(); | ||
smallHash.update(this.buffer); | ||
collectedHashDigests.push(smallHash.digest()); | ||
this.buffer = void 0; | ||
} | ||
while (collectedHashDigests.length > 1) { | ||
const higherLevelHashDigests = []; | ||
for (let i = 0; i < collectedHashDigests.length; i += 2) { | ||
if (i + 1 < collectedHashDigests.length) { | ||
const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]); | ||
const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength); | ||
chunk.set(digest1); | ||
chunk.set(digest2, digest1.byteLength); | ||
const hash = new this.Sha256(); | ||
hash.update(chunk); | ||
higherLevelHashDigests.push(hash.digest()); | ||
} | ||
}); | ||
}); | ||
}; | ||
TreeHash.prototype.convertToBuffer = function (data) { | ||
else { | ||
higherLevelHashDigests.push(collectedHashDigests[i]); | ||
} | ||
} | ||
collectedHashDigests = higherLevelHashDigests; | ||
} | ||
return collectedHashDigests[0]; | ||
} | ||
convertToBuffer(data) { | ||
if (typeof data === "string") { | ||
@@ -95,5 +76,3 @@ return this.fromUtf8(data); | ||
return new Uint8Array(data); | ||
}; | ||
return TreeHash; | ||
}()); | ||
export { TreeHash }; | ||
} | ||
} |
{ | ||
"name": "@aws-sdk/sha256-tree-hash", | ||
"version": "3.178.0", | ||
"version": "3.183.0", | ||
"scripts": { | ||
@@ -23,3 +23,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"dependencies": { | ||
"@aws-sdk/types": "3.178.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"tslib": "^2.3.1" | ||
@@ -29,4 +29,4 @@ }, | ||
"@aws-crypto/sha256-js": "2.0.0", | ||
"@aws-sdk/util-hex-encoding": "3.170.0", | ||
"@aws-sdk/util-utf8-node": "3.170.0", | ||
"@aws-sdk/util-hex-encoding": "3.183.0", | ||
"@aws-sdk/util-utf8-node": "3.183.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -33,0 +33,0 @@ "concurrently": "7.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54194
198
+ Added@aws-sdk/types@3.183.0(transitive)
- Removed@aws-sdk/types@3.178.0(transitive)
Updated@aws-sdk/types@3.183.0