use super::case::{Case, Cases};
pub fn run_committed_kats<F>(toml_contents: &str, mut run_case: F) -> Result<(), String>
where
F: FnMut(&Case) -> Result<(), String>,
{
let cases: Cases = toml::from_str(toml_contents)
.map_err(|error| format!("Fix: keep fixture TOML valid: {error}"))?;
for case in cases.case {
run_case(&case)?;
}
Ok(())
}
pub fn hex_to_bytes(hex: &str) -> Result<Vec<u8>, String> {
if hex.len() % 2 != 0 {
return Err(format!(
"Fix: fixture hex strings must contain an even number of digits, got {}",
hex.len()
));
}
(0..hex.len())
.step_by(2)
.map(|idx| {
u8::from_str_radix(&hex[idx..idx + 2], 16).map_err(|error| {
format!("Fix: fixture hex byte at offset {idx} must be valid hexadecimal: {error}")
})
})
.collect()
}