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
Hashertrait implementation - Extensibility: Built on
digest::Digestfor 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
Hashertrait 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§
- Digest
Hasher - Generic hasher wrapper for any
digest::Digestimplementation. Provides the primary way to use standard hashing algorithms. Enables composability with external crates likesha2,sha3,blake3. - Verification
Receipt - Verified
Reader - Streaming reader that hashes data as it passes through.
Wraps any
Readsource for zero-copy verification.
Enums§
- Verify
Error - 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.
- Sha256
Hasher - Built-in hashers as type aliases and constructors for convenience.