parse_algorithm

Function parse_algorithm 

Source
pub fn parse_algorithm(s: &str) -> Result<HashAlgorithm>
Expand description

Parse algorithm from string

Converts a string algorithm name to a HashAlgorithm enum value.

§Arguments

  • s - Algorithm name (case-sensitive: “sha256”, “sha384”, or “sha512”)

§Returns

  • Ok(HashAlgorithm) - The parsed algorithm
  • Err(Error) - If the algorithm name is not recognized

§Examples

use atlas_cli::hash::parse_algorithm;
use atlas_c2pa_lib::cose::HashAlgorithm;

let algo = parse_algorithm("sha384").unwrap();
assert!(matches!(algo, HashAlgorithm::Sha384));

// Invalid algorithm names return an error
assert!(parse_algorithm("sha1").is_err());
assert!(parse_algorithm("SHA256").is_err()); // case sensitive