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. Algorithm::Passthrough is the exception to the text form: it returns the canonical string itself, which is what the reference does.

ยงExample

use object_hash::{Algorithm, Value, canonical, 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::Sha224).len(), 56);
assert_eq!(hash_with(&value, Algorithm::Md5).len(), 32);
// Passthrough is the canonical form, not a digest of it.
assert_eq!(hash_with(&value, Algorithm::Passthrough), canonical(&value));