Skip to main content

Crate pulith_verify

Crate pulith_verify 

Source
Expand description

Content verification primitives for downloaded artifacts.

Zero-copy streaming verification for downloaded artifacts, ensuring integrity without additional memory overhead.

§Design Principles

  • Zero-Copy Verification: CPU cache touches bytes only once (hashing + I/O)
  • Composability: Generic over any Hasher trait implementation
  • Extensibility: Built on digest::Digest for broad algorithm support
  • Error Handling: Concrete error types using thiserror

§Key Features

  • Zero-copy verification: CPU cache touches bytes only once (for both hashing and writing)
  • Incremental: Computes digests as data streams through
  • Extensible: Minimal Hasher trait allows custom implementations
  • Thread-safe: All public types implement Send + Sync

§Example

use pulith_verify::{VerifiedReader, Sha256Hasher, VerifyError};
use std::fs::File;
use std::io::{self, Read};

fn verify_artifact(path: &str, expected_hash_hex: &str) -> Result<(), VerifyError> {
    let expected = hex::decode(expected_hash_hex)?;
    let file = File::open(path)?;
    let hasher = Sha256Hasher::new();
    let mut reader = VerifiedReader::new(file, hasher);

    let mut buffer = vec![0; 8192];
    loop {
        match reader.read(&mut buffer) {
            Ok(0) => break,
            Ok(_) => {},
            Err(e) => return Err(VerifyError::Io(e)),
        }
    }

    reader.finish(&expected)?;
    Ok(())
}

Structs§

DigestHasher
Generic hasher wrapper for any digest::Digest implementation. Provides the primary way to use standard hashing algorithms. Enables composability with external crates like sha2, sha3, blake3.
VerificationReceipt
VerifiedReader
Streaming reader that hashes data as it passes through. Wraps any Read source for zero-copy verification.

Enums§

VerifyError
Error types for verification operations.

Traits§

Hasher
Minimal hasher interface for streaming verification. Implementations must be Send for cross-thread safety.

Functions§

verify_stream
Verifies an entire stream by reading it to EOF.

Type Aliases§

Result
Result type alias for verification operations.
Sha256Hasher
Built-in hashers as type aliases and constructors for convenience.