1
pub(crate) struct FakePRNG<'a> {
2
    bytes: &'a [u8],
3
}
4
impl<'a> FakePRNG<'a> {
5
5
    pub(crate) fn new(bytes: &'a [u8]) -> Self {
6
5
        Self { bytes }
7
5
    }
8
}
9
impl<'a> rand_core::RngCore for FakePRNG<'a> {
10
    fn next_u32(&mut self) -> u32 {
11
        rand_core::impls::next_u32_via_fill(self)
12
    }
13
    fn next_u64(&mut self) -> u64 {
14
        rand_core::impls::next_u64_via_fill(self)
15
    }
16
    fn try_fill_bytes(&mut self, dest: &mut [u8]) -> std::result::Result<(), rand_core::Error> {
17
        self.fill_bytes(dest);
18
        Ok(())
19
    }
20
5
    fn fill_bytes(&mut self, dest: &mut [u8]) {
21
5
        assert!(dest.len() <= self.bytes.len());
22

            
23
5
        dest.copy_from_slice(&self.bytes[0..dest.len()]);
24
5
        self.bytes = &self.bytes[dest.len()..];
25
5
    }
26
}
27
impl rand_core::CryptoRng for FakePRNG<'_> {}