-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an AwsCrc32C object that implements @aws-sdk/types::Hash
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters