merkle_hash

Finds the blake3 hash of files or entire directories using a multithreaded merkle tree algorithm.

Documentation

docs.rs/merkle_hash

Usage

To use this crate, add merkle_hash as a dependency to your project's Cargo.toml:

toml [dependencies] merkle_hash = "2"

Example: Get the hashes of all files and directories descendants of a provided path as a traversable merkle tree

The following code demonstrates how to create a merkle tree of paths and hashes and then traverse it, executing a closure for each path and hash:

```rust,norun use merklehash::merkle_tree::MerkleTree;

let merkletree=MerkleTree::new("/provided/path").unwrap(); let traverseresult=merkletree.traverse(&|path,hash|{ println!("{}: {}",path.absolutepath,hash); Ok(()) }); ```

Example: Get the hashes of all files and directories descendants of a provided path as a BTreeSet or as a HashSet

The following code demonstrates how to create a merkle tree of paths and hashes and then collapse it into a BTreeSet or a HashSet which can then be traversed linearly:

```rust,norun use merklehash::merkle_tree::MerkleTree;

let merkletree=MerkleTree::new("/provided/path").unwrap(); let converttobtreeset=true; if converttobtreeset{ let btreeset=merkletree.collapseintotreeset(); }else{ let hashset=merkletree.collapseintohash_set(); } ```

Example: Get the hash of a collection of blake3 hashes

The following code demonstrates how to use the merkle hash function to get a single merkle hash from a few blake3 hashes:

```rust,norun use blake3::hash; use merklehash::merkleutils::computemerkle_hash;

let firsthash = hash(b"foo"); let secondhash = hash(b"bar"); let thirdhash = hash(b"baz"); let fourthhash = hash(b"cow"); let hashes = vec![firsthash, secondhash, thirdhash, fourthhash];

let merklehash = computemerkle_hash(&hashes); ```