test: the six mandatory tests, pinned KAT vectors, fuzz target and cargo-deny config (written before the code)

This commit is contained in:
2026-11-25 07:28:48 +01:00
parent ed9b8a3b17
commit c7d050ed65
21 changed files with 3726 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
//! Helpers shared by the integration tests. Test fixtures only: no real keys, no network.
#![allow(dead_code)]
use chacha20::ChaCha20Rng;
use rand_core::SeedableRng;
use sha2::{Digest, Sha256};
/// A deterministic RNG for tests. Never used outside tests.
pub fn rng(label: u8) -> ChaCha20Rng {
ChaCha20Rng::from_seed([label; 32])
}
pub fn hex(s: &str) -> Vec<u8> {
hex::decode(s).expect("vector hex")
}
pub fn arr<const N: usize>(s: &str) -> [u8; N] {
hex(s).try_into().expect("vector length")
}
/// Fail loudly if a pinned vector file is not the one recorded in tests/vectors/SOURCES.md.
pub fn assert_sha256(bytes: &[u8], expected_hex: &str, name: &str) {
let got = hex::encode(Sha256::digest(bytes));
assert_eq!(got, expected_hex, "{name} is not the pinned file (see tests/vectors/SOURCES.md)");
}