Skip to main content

hash_with

Function hash_with 

Source
pub fn hash_with(value: &Value, algorithm: Algorithm) -> String
Expand description

The digest of a value with a chosen algorithm, as lowercase hexadecimal.

The canonical bytes are the same whatever the algorithm, so two algorithms agree on which values are equal and differ only in the text they produce.

ยงExample

use object_hash::{Algorithm, Value, hash_with};

let value = Value::string("cipansor");
assert_eq!(hash_with(&value, Algorithm::Sha1).len(), 40);
assert_eq!(hash_with(&value, Algorithm::Sha256).len(), 64);
assert_eq!(hash_with(&value, Algorithm::Md5).len(), 32);