#file-integrity #hashing #folder-hashing #filesystem-integirty

filesystem-hashing

Track Filesystem Integrity via Snapshots which contain a HashMap of the files and their corresponding hash signature from a specified directory

10 releases

0.3.4 Apr 21, 2024
0.3.3 Apr 21, 2024
0.2.9 Apr 15, 2024

#764 in Filesystem

Download history 2/week @ 2024-07-27 2/week @ 2024-08-31 15/week @ 2024-09-14 19/week @ 2024-09-21 4/week @ 2024-09-28 6/week @ 2024-10-05 7/week @ 2024-10-12 27/week @ 2024-10-19 18/week @ 2024-10-26 24/week @ 2024-11-02

77 downloads per month
Used in 5 crates (3 directly)

MIT license

34KB
829 lines

filesystem-hashing

Track Filesystem Integrity via Snapshots

~ contain a HashMap of the files and their corresponding hash signature from a specified directory.
~ are exported as JSON files.

Snapshot structure


pub enum HashType {
    MD5,
    SHA3,
    BLAKE3,
}
pub struct Snapshot {
    pub file_hashes: Arc<Mutex<HashMap<String, FileMetadata>>>,
    pub black_list: Vec<String>,
    pub root_path: String,
    pub hash_type: HashType,
    pub uuid: String,
    pub date_created: i64,
}
pub struct FileMetadata {
    pub path: String,
    pub check_sum: Vec<u8>,
    pub size: u64,
    pub ino: u64,
    pub ctime: i64,
    pub mtime: i64,
}

Snapshot Comparison result structure

    pub enum SnapshotChangeType {
        None,
        Created,
        Deleted,
        Changed,
    }
    pub struct SnapshotCompareResult {
        pub created: Vec<String>,
        pub deleted: Vec<String>,
        pub changed: Vec<String>,
    }

Usage

fn main() {
    /// snapshot creation
    let snapshot = create_snapshot("/etc", BLAKE3, vec![])?;
    let snapshot2 = create_snapshot("/etc", BLAKE3, vec![])?;
    
    /// snapshot export
    export_snapshot(snapshot.clone(), "./".to_string(), true)?;
    
    /// compare snapshots
    let results: (SnapshotChangeType, SnapshotCompareResult) = compare_snapshots(snapshot(), snapshot2)?;
}

Utilized in the following project(s)

sys-compare

Notes

~ It is advised to **exclude** tmp directories, mail spools, log directories, proc filesystems,
user's home directories, web content directories, and psuedo-device files.
~ It is advised to **include** all system binaries, libraries, include files, system source files.
~ It is also advisable to include directories you don't often look in such as /dev, or /usr/man/.

Development and Collaboration

Feel free to open a pull request, please run the following prior to your submission please!

echo "Run clippy"; cargo clippy -- -D clippy::all
echo "Format source code"; cargo fmt -- --check

Dependencies

~6–14MB
~168K SLoC