Skip to main content

capsule_library/utils/
mod.rs

1pub mod paths;
2
3use std::io;
4use std::path::Path;
5
6use capsule_core::crypto::hash::{Hash32, hash_reader};
7
8/// SHA-256 of a file's contents, streamed in fixed blocks.
9///
10/// Opens `path` and feeds it through [`hash_reader`] rather than reading the whole file
11/// into memory, so arbitrarily large originals hash with bounded memory. The digest itself is
12/// `capsule-core`'s; only the file handle is the library's.
13pub fn hash_file(path: &Path) -> io::Result<Hash32> {
14    let file = std::fs::File::open(path)?;
15    hash_reader(io::BufReader::new(file))
16}
17
18#[cfg(test)]
19mod tests;