Skip to main content

Module integrity

Module integrity 

Source
Expand description

Whole-file content hash + canonical-encoding integrity gates (P0.3).

The .10d container has two integrity layers:

  1. Per-section CRC-32C (P0.2, in super::section) — each section descriptor carries a CRC-32C over its payload; a flipped payload bit is caught at section read.
  2. Whole-file content hash (P0.3, here) — a CRC-32C over the entire file (header + section table + payloads + padding), stored in the header’s header_crc32c field. This catches header corruption and table corruption that the per-section CRC cannot (e.g. a flipped byte_offset in a descriptor that still points somewhere valid).

The whole-file hash is computed with header_crc32c zeroed during computation (the standard self-referential CRC technique): on encode, the field is written zero, the CRC is computed over the full buffer, then the CRC is written into the field; on verify, the stored value is saved, the field is zeroed in-place, the CRC is recomputed, and the two are compared.

Determinism / canonical bytes. Because super::section::encode_container produces byte-identical output for identical input (canonical section order, zeroed padding), the whole-file hash is stable across encodes and changes on any payload-byte change. This is the P0.3 “whole-file hash is stable across encodes and changes on any payload-byte change, zero-alloc over the caller buffer” gate.

Enums§

IntegrityError
Integrity verification error.

Functions§

compute_whole_file_crc32c
Compute the whole-file CRC-32C over data, treating the header_crc32c field (bytes 52..56) as zero. Zero-heap: operates directly over the caller buffer. Does not modify data.
seal_whole_file_crc32c
Write the whole-file CRC-32C into the header’s header_crc32c field in-place within data. Called by the encoder after the full file is written. Zero-heap.
verify_whole_file_crc32c
Verify the whole-file CRC-32C stored in the header against a recomputed value. Returns Ok(()) if they match, or an error naming both values. Zero-heap: saves the stored CRC, zeroes the field in-place, recomputes, restores the field.