Function ssdeep::hash_file

source ·
pub fn hash_file<P: AsRef<Path>>(
    path: P
) -> Result<RawFuzzyHash, GeneratorOrIOError>
Available on crate features std and easy-functions only.
Expand description

Generates a fuzzy hash from a given file.

Example

use std::error::Error;

fn main() -> Result<(), ssdeep::GeneratorOrIOError> {
    let fuzzy_hash = ssdeep::hash_file("data/examples/hello.txt")?;
    let fuzzy_hash_str = fuzzy_hash.to_string();
    assert_eq!(fuzzy_hash_str, "3:aaX8v:aV");
    Ok(())
}

Note

This function expects that the file size does not change while generating. On normal use cases, you hash a fixed file to generate a fuzzy hash to interchange information about the file with others. So, this assumption should be safe for most users.

Also, failing to meet this requirement only causes this function to return an error (incorrect result will not be produced). So, this function is always safe.

If the file size could change while generating a fuzzy hash, use hash_stream() instead.