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

filesystem-hashing

通过包含指定目录中文件及其对应哈希签名的 HashMap 的快照跟踪文件系统完整性

10 个版本

0.3.4 2024 年 4 月 21 日
0.3.3 2024 年 4 月 21 日
0.2.9 2024 年 4 月 15 日

#668 in 文件系统


用于 2 crates

MIT 许可证

34KB
829

filesystem-hashing

通过快照跟踪文件系统完整性

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

快照结构


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,
}

快照比较结果结构

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

用法

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)?;
}

在以下项目(们)中使用

sys-compare

注释

~ 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/.

开发和协作

请随意发起一个 pull request,请在提交之前运行以下命令!

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

依赖关系

~6–15MB
~170K SLoC