CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-stablelib--sha256

SHA-256 cryptographic hash function implementation for TypeScript and JavaScript

91

0.98x
Overview
Eval results
Files

task.mdevals/scenario-4/

Hash Validator

Build a utility that validates hash digests and properly sizes buffers for hash operations.

Requirements

Implement a module that provides functions to:

  1. Validate whether a given buffer is the correct size for a hash digest
  2. Allocate a properly-sized buffer for storing hash output
  3. Check if data is properly aligned to the algorithm's processing block size
  4. Calculate how many complete blocks can be processed from given data

The module should handle validation and buffer management correctly for cryptographic hash operations.

Test Cases

  • Given a 32-byte buffer, validation confirms it is correct digest size @test
  • Given a 16-byte buffer, validation indicates it is incorrect digest size @test
  • Allocating a buffer returns exactly 32 bytes @test
  • Given 128 bytes of data, calculates 2 complete blocks @test
  • Given 100 bytes of data, calculates 1 complete block @test

Implementation

@generates

API

/**
 * Checks if a buffer is the correct size for a hash digest
 * @param buffer - The buffer to validate
 * @returns true if buffer is correct size, false otherwise
 */
export function isValidDigestSize(buffer: Uint8Array): boolean;

/**
 * Allocates a new buffer with the correct size for a hash digest
 * @returns A new Uint8Array with the correct size
 */
export function allocateDigestBuffer(): Uint8Array;

/**
 * Checks if data length is aligned to the block size boundary
 * @param dataLength - Length of data in bytes
 * @returns true if data is block-aligned, false otherwise
 */
export function isBlockAligned(dataLength: number): boolean;

/**
 * Calculates how many complete blocks can be processed from the data
 * @param dataLength - Length of data in bytes
 * @returns Number of complete blocks
 */
export function calculateCompleteBlocks(dataLength: number): number;

Dependencies { .dependencies }

@stablelib/sha256 { .dependency }

Provides cryptographic hashing with standard algorithm constants.

Install with Tessl CLI

npx tessl i tessl/npm-stablelib--sha256

tile.json