Skip to content

Commit

Permalink
feat: Add AwsCrc32C Hash
Browse files Browse the repository at this point in the history
Add an AwsCrc32C object that implements
@aws-sdk/types::Hash
  • Loading branch information
seebees committed Sep 16, 2021
1 parent aa0edcb commit 4840c83
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/crc32c/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
},
"license": "Apache-2.0",
"dependencies": {
"tslib": "^1.11.1"
"tslib": "^1.11.1",
"@aws-sdk/types": "^3.1.0",
"@aws-crypto/util": "file:../util"
},
"publishConfig": {
"access": "public"
Expand Down
20 changes: 20 additions & 0 deletions packages/crc32c/src/aws_crc32c.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Hash, SourceData } from "@aws-sdk/types";
import { convertToBuffer, isEmptyData, numToUint8 } from "@aws-crypto/util";
import { Crc32c } from "./index";

export class AwsCrc32c implements Hash {
private readonly crc32c = new Crc32c();

update(toHash: SourceData) {
if (isEmptyData(toHash)) return;

this.crc32c.update(convertToBuffer(toHash));
}

async digest(): Promise<Uint8Array> {
return numToUint8(this.crc32c.digest());
}
}
2 changes: 2 additions & 0 deletions packages/crc32c/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ const lookupTable = Uint32Array.from([
0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351,
]);

export { AwsCrc32c } from "./aws_crc32c";

0 comments on commit 4840c83

Please sign in to comment.