tor_llcrypto/util/
rng.rs
1#[cfg_attr(feature = "rng-compat", visibility::make(pub))]
12pub struct RngCompat<R>(R);
13
14impl<R> RngCompat<R> {
15 #[cfg_attr(feature = "rng-compat", visibility::make(pub))]
17 pub(crate) fn new(rng: R) -> Self {
18 Self(rng)
19 }
20}
21
22impl<R: rand_core::RngCore> rand_core_06::RngCore for RngCompat<R> {
23 fn next_u32(&mut self) -> u32 {
24 self.0.next_u32()
25 }
26
27 fn next_u64(&mut self) -> u64 {
28 self.0.next_u64()
29 }
30
31 fn fill_bytes(&mut self, dest: &mut [u8]) {
32 self.0.fill_bytes(dest);
33 }
34
35 fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core_06::Error> {
36 self.0.fill_bytes(dest);
37 Ok(())
38 }
39}
40impl<R: rand_core::CryptoRng> rand_core_06::CryptoRng for RngCompat<R> {}
41
42impl<R: rand_core_06::RngCore> rand_core::RngCore for RngCompat<R> {
43 fn next_u32(&mut self) -> u32 {
44 self.0.next_u32()
45 }
46
47 fn next_u64(&mut self) -> u64 {
48 self.0.next_u64()
49 }
50
51 fn fill_bytes(&mut self, dest: &mut [u8]) {
52 self.0.fill_bytes(dest);
53 }
54}
55
56impl<R: rand_core_06::CryptoRng + rand_core_06::RngCore> rand_core::CryptoRng for RngCompat<R> {}