pub fn hash_preference(
    hashes: &HashMap<HashAlgorithm, HashValue>
) -> Result<(&'static HashAlgorithm, &HashValue)>
Expand description

Given a map of hash algorithms and their values, get the prefered algorithm and the hash calculated by it. Returns an Err if there is no match.

use std::collections::HashMap;
use in_toto::crypto::{hash_preference, HashValue, HashAlgorithm};

let mut map = HashMap::new();
assert!(hash_preference(&map).is_err());

let _ = map.insert(HashAlgorithm::Sha512, HashValue::new(vec![0x00, 0x01]));
assert_eq!(hash_preference(&map).unwrap().0, &HashAlgorithm::Sha512);

let _ = map.insert(HashAlgorithm::Sha256, HashValue::new(vec![0x02, 0x03]));
assert_eq!(hash_preference(&map).unwrap().0, &HashAlgorithm::Sha512);