apiculture/checksum

CRC32 checksum implementation for data integrity verification.

This module is a thin wrapper around the crc32 package that adapts its Int return type to the BitArray expected by apiculture’s key API.

This is NOT cryptographic authentication - CRC32 is designed to detect accidental data corruption only, not malicious tampering.

For authenticated checksums suitable for security-sensitive applications, consider using HMAC-based approaches with a cryptographic hash.

Types

A checksum algorithm that can produce output in various formats.

pub type Checksum {
  Checksum(compute: fn(BitArray) -> BitArray, name: String)
}

Constructors

  • Checksum(compute: fn(BitArray) -> BitArray, name: String)

    Arguments

    compute

    Compute the raw checksum bytes (4 bytes for CRC32)

    name

    Human-readable name

Values

pub fn crc32(bytes: BitArray) -> BitArray

Compute a CRC32 checksum and return it as a 4-byte BitArray. This is a convenience function for direct checksum computation.

pub fn crc32_checksum() -> Checksum

CRC32 checksum algorithm using CRC-32/ISO-HDLC variant. This matches the standard CRC-32 used by ZIP, gzip, PNG, and Ethernet.

pub fn format(
  checksum: Checksum,
  bytes: BitArray,
  format_with: fn(BitArray) -> String,
) -> String

Format the checksum output through an encoding or alphabet.

pub fn verify(
  checksum: Checksum,
  bytes: BitArray,
  expected: BitArray,
) -> Bool

Verify that data matches an expected checksum.

Search Document