SHA-256 cryptographic hash function implementation for TypeScript and JavaScript
91
Build a hash processor that efficiently computes SHA-256 hashes from data stored in fixed-size buffers, processing only the valid portion of each buffer.
In high-performance systems, data often arrives in fixed-size buffers where only a portion contains valid data. You need to implement a utility that processes these buffers and computes their SHA-256 hash, handling only the valid bytes in each buffer.
Implement a BufferHashProcessor class with the following behavior:
The processor should handle multiple data chunks efficiently, processing only the specified number of valid bytes from each buffer.
/**
* Processes data from fixed-size buffers and computes SHA-256 hash.
*/
export class BufferHashProcessor {
/**
* Creates a new processor with specified maximum buffer size.
* @param maxBufferSize - Maximum size of buffers that will be processed
*/
constructor(maxBufferSize: number);
/**
* Adds a data chunk to be hashed.
* @param buffer - The buffer containing data (may be larger than actual data)
* @param actualLength - The number of valid bytes in the buffer to process
*/
addChunk(buffer: Uint8Array, actualLength: number): void;
/**
* Finalizes processing and returns the SHA-256 hash.
* @returns Hexadecimal string representation of the hash
*/
finalize(): string;
/**
* Resets the processor to process a new sequence of buffers.
*/
reset(): void;
}@generates
Provides SHA-256 cryptographic hash function implementation.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-stablelib--sha256docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10