verify_hash_with_algorithm

Function verify_hash_with_algorithm 

Source
pub fn verify_hash_with_algorithm(
    data: &[u8],
    expected_hash: &str,
    algorithm: &HashAlgorithm,
) -> bool
Expand description

Verify hash with an explicitly specified algorithm

Use this when you know which algorithm was used to create the hash.

§Arguments

  • data - The data to verify
  • expected_hash - The expected hash in hexadecimal format
  • algorithm - The hash algorithm that was used

§Returns

  • true if the data matches the hash
  • false if the data doesn’t match

§Examples

use atlas_cli::hash::{calculate_hash_with_algorithm, verify_hash_with_algorithm};
use atlas_c2pa_lib::cose::HashAlgorithm;

let data = b"test data";
let hash = calculate_hash_with_algorithm(data, &HashAlgorithm::Sha384);

// Verification with correct algorithm succeeds
assert!(verify_hash_with_algorithm(data, &hash, &HashAlgorithm::Sha384));

// Verification with wrong algorithm fails
assert!(!verify_hash_with_algorithm(data, &hash, &HashAlgorithm::Sha256));