Skip to main content

is_hash_algorithm_downgrade

Function is_hash_algorithm_downgrade 

Source
pub fn is_hash_algorithm_downgrade(
    old_hashes: &BTreeMap<String, String>,
    new_hashes: &BTreeMap<String, String>,
) -> bool
Expand description

detects whether the hash algorithms in a component were downgraded.

compares the strongest known algorithm in old_hashes against the strongest known algorithm in new_hashes. Returns true if the new set’s strongest algorithm is weaker than the old set’s strongest.

returns false when:

  • Either hash set is empty (use missing-hashes for that)
  • Neither set contains a recognized algorithm
  • The new set is at least as strong as the old set

§Example

use sbom_model::is_hash_algorithm_downgrade;
use std::collections::BTreeMap;

let old: BTreeMap<String, String> = [("sha-256".into(), "abc".into())].into();
let new: BTreeMap<String, String> = [("md5".into(), "def".into())].into();
assert!(is_hash_algorithm_downgrade(&old, &new));

let new_strong: BTreeMap<String, String> = [("sha-512".into(), "ghi".into())].into();
assert!(!is_hash_algorithm_downgrade(&old, &new_strong));