|
| 1 | +/** |
| 2 | + * An object that provides a checksum of data provided in chunks to `update`. |
| 3 | + * The checksum may be performed incrementally as chunks are received or all |
| 4 | + * at once when the checksum is finalized, depending on the underlying |
| 5 | + * implementation. |
| 6 | + * |
| 7 | + * It's recommended to compute checksum incrementally to avoid reading the |
| 8 | + * entire payload in memory. |
| 9 | + * |
| 10 | + * A class that implements this interface may accept an optional secret key in its |
| 11 | + * constructor while computing checksum value, when using HMAC. If provided, |
| 12 | + * this secret key would be used when computing checksum. |
| 13 | + */ |
| 14 | +export interface Checksum { |
| 15 | + /** |
| 16 | + * Constant length of the digest created by the algorithm in bytes. |
| 17 | + */ |
| 18 | + digestLength?: number; |
| 19 | + |
| 20 | + /** |
| 21 | + * Creates a new checksum object that contains a deep copy of the internal |
| 22 | + * state of the current `Checksum` object. |
| 23 | + */ |
| 24 | + copy?(): Checksum; |
| 25 | + |
| 26 | + /** |
| 27 | + * Returns the digest of all of the data passed. |
| 28 | + */ |
| 29 | + digest(): Promise<Uint8Array>; |
| 30 | + |
| 31 | + /** |
| 32 | + * Allows marking a checksum for checksums that support the ability |
| 33 | + * to mark and reset. |
| 34 | + * |
| 35 | + * @param {number} readLimit - The maximum limit of bytes that can be read |
| 36 | + * before the mark position becomes invalid. |
| 37 | + */ |
| 38 | + mark?(readLimit: number): void; |
| 39 | + |
| 40 | + /** |
| 41 | + * Resets the checksum to its initial value. |
| 42 | + */ |
| 43 | + reset(): void; |
| 44 | + |
| 45 | + /** |
| 46 | + * Adds a chunk of data for which checksum needs to be computed. |
| 47 | + * This can be called many times with new data as it is streamed. |
| 48 | + * |
| 49 | + * Implementations may override this method which passes second param |
| 50 | + * which makes Checksum object stateless. |
| 51 | + * |
| 52 | + * @param {Uint8Array} chunk - The buffer to update checksum with. |
| 53 | + */ |
| 54 | + update(chunk: Uint8Array): void; |
| 55 | +} |
0 commit comments