mod degenerate;
mod group;
mod rfc9383;
mod vectors;
use std::vec::Vec;
use crate::rand_core::{Infallible, TryCryptoRng, TryRng};
fn unhex(hex: &str) -> Vec<u8> {
assert_eq!(hex.len() % 2, 0, "an odd number of hex digits");
(0..hex.len())
.step_by(2)
.map(|at| u8::from_str_radix(&hex[at..at + 2], 16).unwrap())
.collect()
}
struct Replay(Vec<u8>);
impl Replay {
fn scalar(hex: &str) -> Self {
let scalar = unhex(hex);
let mut bytes = std::vec![0; 64 - scalar.len()];
bytes.extend_from_slice(&scalar);
Self(bytes)
}
}
impl TryRng for Replay {
type Error = Infallible;
fn try_next_u32(&mut self) -> Result<u32, Infallible> {
let mut bytes = [0; 4];
self.try_fill_bytes(&mut bytes)?;
Ok(u32::from_le_bytes(bytes))
}
fn try_next_u64(&mut self) -> Result<u64, Infallible> {
let mut bytes = [0; 8];
self.try_fill_bytes(&mut bytes)?;
Ok(u64::from_le_bytes(bytes))
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Infallible> {
assert!(dst.len() <= self.0.len(), "the replayed bytes ran out");
dst.copy_from_slice(&self.0[..dst.len()]);
self.0.drain(..dst.len());
Ok(())
}
}
impl TryCryptoRng for Replay {}