#hash #hashing #file #directory #tree

merkle_hash

Finds the hashes of all files and directories in a directory tree

7 stable releases

Uses new Rust 2021

new 3.0.1 Nov 20, 2022
3.0.0 Nov 18, 2022
2.1.0 Oct 20, 2022
2.0.0 Jun 26, 2022
1.1.1 Mar 31, 2022

#276 in Cryptography

Download history 1/week @ 2022-08-10 1/week @ 2022-08-17 20/week @ 2022-08-24 8/week @ 2022-08-31 4/week @ 2022-09-07 64/week @ 2022-09-14 20/week @ 2022-09-21 16/week @ 2022-09-28 3/week @ 2022-10-05 1/week @ 2022-10-12 26/week @ 2022-10-19 3/week @ 2022-10-26 6/week @ 2022-11-02 18/week @ 2022-11-09 81/week @ 2022-11-16

110 downloads per month

MIT license

18KB
324 lines

merkle_hash

Finds the hashes of all files and directories in a directory tree.

Usage

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

[dependencies]
merkle_hash = "3"

Features

  • Finds the master hash of a directory tree with ease.
  • Uses a merkle tree algorithm to compute the hashes of directories.
  • External iteration over the paths and hashes of each file and directory.
  • Ability to specify whether names should be included in the hashes of files and directories.

Examples

Get the master hash of a directory tree:

use merkle_hash::MerkleTree;

let tree = MerkleTree::new("/path/to/directory", true).unwrap();
let master_hash = tree.main_node.item.hash;

Iterate over a directory tree, getting the hash of each file and directory:

use merkle_hash::MerkleTree;

let tree = MerkleTree::new("/path/to/directory", true).unwrap();
for item in tree {
    println!("{}: {}", item.path.relative, item.hash);
}

Collapse the tree into any linear collection:

use std::collections::BTreeSet;
use merkle_hash::MerkleTree;
use merkle_hash::MerkleItem;

let tree = MerkleTree::new("/path/to/directory", true).unwrap();
let btree_set: BTreeSet<MerkleItem> = tree.into_iter().collect();

Used technologies

  • rayon for multithreaded directory reading and hashing.
  • blake3 for the hashing of file contents.
  • camino to ensure that paths are always utf-8.
  • anyhow to ease-out the handling of errors.

License

Licensed under MIT license.

Dependencies

~3MB
~69K SLoC