test: the six mandatory tests, pinned KAT vectors, fuzz target and cargo-deny config (written before the code)
This commit is contained in:
@@ -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)");
|
||||
}
|
||||
Reference in New Issue
Block a user