mod adversarial;
mod complexity;
mod edge_cases;
mod errors;
mod parallel;
mod roundtrip;
mod skip;
mod vectors;
use serde::Deserialize;
#[derive(Deserialize)]
pub(crate) struct Vector {
pub name: String,
pub input_hex: String,
pub output: String,
}
pub(crate) fn hex_decode(s: &str) -> Vec<u8> {
assert_eq!(s.len() % 2, 0, "hex string must have even length");
(0..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("valid hex byte"))
.collect()
}
pub(crate) const fn cases(full: usize) -> usize {
if cfg!(miri) {
if full > 32 { 32 } else { full }
} else {
full
}
}
pub(crate) fn read_vector_file(name: &str) -> String {
let root = env!("CARGO_MANIFEST_DIR");
let candidates = [
format!("{root}/../testvectors/{name}"),
format!("{root}/testvectors/{name}"),
];
for path in &candidates {
if let Ok(data) = std::fs::read_to_string(path) {
return data;
}
}
panic!("failed to read {name} from any of {candidates:?}");
}
pub(crate) fn load_vectors() -> Vec<Vector> {
serde_json::from_str(&read_vector_file("vectors.json")).expect("valid vectors.json")
}
#[test]
fn hex_decode_roundtrips() {
assert_eq!(hex_decode(""), Vec::<u8>::new());
assert_eq!(hex_decode("61626330"), b"abc0");
}