-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types): add checksum interface (#4216)
- Loading branch information
1 parent
a27adec
commit 89598b6
Showing
3 changed files
with
60 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* An object that provides a checksum of data provided in chunks to `update`. | ||
* The checksum may be performed incrementally as chunks are received or all | ||
* at once when the checksum is finalized, depending on the underlying | ||
* implementation. | ||
* | ||
* It's recommended to compute checksum incrementally to avoid reading the | ||
* entire payload in memory. | ||
* | ||
* A class that implements this interface may accept an optional secret key in its | ||
* constructor while computing checksum value, when using HMAC. If provided, | ||
* this secret key would be used when computing checksum. | ||
*/ | ||
export interface Checksum { | ||
/** | ||
* Constant length of the digest created by the algorithm in bytes. | ||
*/ | ||
digestLength?: number; | ||
|
||
/** | ||
* Creates a new checksum object that contains a deep copy of the internal | ||
* state of the current `Checksum` object. | ||
*/ | ||
copy?(): Checksum; | ||
|
||
/** | ||
* Returns the digest of all of the data passed. | ||
*/ | ||
digest(): Promise<Uint8Array>; | ||
|
||
/** | ||
* Allows marking a checksum for checksums that support the ability | ||
* to mark and reset. | ||
* | ||
* @param {number} readLimit - The maximum limit of bytes that can be read | ||
* before the mark position becomes invalid. | ||
*/ | ||
mark?(readLimit: number): void; | ||
|
||
/** | ||
* Resets the checksum to its initial value. | ||
*/ | ||
reset(): void; | ||
|
||
/** | ||
* Adds a chunk of data for which checksum needs to be computed. | ||
* This can be called many times with new data as it is streamed. | ||
* | ||
* Implementations may override this method which passes second param | ||
* which makes Checksum object stateless. | ||
* | ||
* @param {Uint8Array} chunk - The buffer to update checksum with. | ||
*/ | ||
update(chunk: Uint8Array): void; | ||
} |
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