1
use std::convert::Infallible;
2

            
3
pub(crate) struct FakePRNG<'a> {
4
    bytes: &'a [u8],
5
}
6
impl<'a> FakePRNG<'a> {
7
10
    pub(crate) fn new(bytes: &'a [u8]) -> Self {
8
10
        Self { bytes }
9
10
    }
10
}
11
impl<'a> rand_core::TryRng for FakePRNG<'a> {
12
    type Error = Infallible;
13

            
14
    fn try_next_u32(&mut self) -> Result<u32, Infallible> {
15
        rand_core::utils::next_word_via_fill(self)
16
    }
17
    fn try_next_u64(&mut self) -> Result<u64, Infallible> {
18
        rand_core::utils::next_word_via_fill(self)
19
    }
20
10
    fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Infallible> {
21
10
        assert!(dest.len() <= self.bytes.len());
22

            
23
10
        dest.copy_from_slice(&self.bytes[0..dest.len()]);
24
10
        self.bytes = &self.bytes[dest.len()..];
25

            
26
10
        Ok(())
27
10
    }
28
}
29
impl rand_core::TryCryptoRng for FakePRNG<'_> {}