Skip to main content

substrate/tree/
mod.rs

1//! Tree hashing for spores.
2
3use anyhow::{anyhow, Result};
4
5pub mod blob_tree_blake3_nfc;
6pub mod walk;
7
8pub use blob_tree_blake3_nfc::{compute_hash_from_entries, TreeEntry};
9pub use walk::{flatten_entries, max_mtime, should_exclude, walk_dir, DirEntry, DirReader};
10
11pub fn compute_tree_hash_from_entries(
12    entries: &[TreeEntry],
13    tree: &crate::model::SporeTree,
14) -> Result<String> {
15    match tree.algorithm.as_str() {
16        blob_tree_blake3_nfc::ALGORITHM => {
17            blob_tree_blake3_nfc::compute_hash_from_entries(entries, &tree.exclude_names)
18        }
19        other => Err(anyhow!("Unsupported tree algorithm: '{}'", other)),
20    }
21}
22
23/// Compute tree hash and total uncompressed source size in bytes.
24pub fn compute_tree_hash_and_size_from_entries(
25    entries: &[TreeEntry],
26    tree: &crate::model::SporeTree,
27) -> Result<(String, u64)> {
28    match tree.algorithm.as_str() {
29        blob_tree_blake3_nfc::ALGORITHM => {
30            blob_tree_blake3_nfc::compute_hash_and_size_from_entries(entries, &tree.exclude_names)
31        }
32        other => Err(anyhow!("Unsupported tree algorithm: '{}'", other)),
33    }
34}