Skip to main content

hash_with_encoding

Function hash_with_encoding 

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

The digest of a value with chosen options, algorithm and encoding.

This is the full form; the shorter functions fix the encoding to hexadecimal, which is the reference’s default. Encoding::Raw returns the digest bytes interpreted as one character each, so a caller that wants the bytes should use raw_hash_with instead.

§Example

use object_hash::{hash_with_encoding, Algorithm, Encoding, Value};

let value = Value::Number(1.0);
let hex = hash_with_encoding(&value, Algorithm::Sha256, Encoding::Hex);
assert_eq!(hex.len(), 64);
// Base64 of the same digest is shorter.
let b64 = hash_with_encoding(&value, Algorithm::Sha256, Encoding::Base64);
assert!(b64.len() < hex.len());