1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
use rand_core::RngCore; // Clients need a proper random number generator to generate a mask key // However, server websockets do not require this and the payload is not masked // EmptyRng is used for servers. In theory, you can use it for clients but you may run into // proxy server caching issues so it is advisable to use a proper random number generator. // Note that data masking does not require a cryptographically strong random number because // the key is sent with the payload anyway #[derive(Default)] pub struct EmptyRng {} impl EmptyRng { pub fn new() -> EmptyRng { EmptyRng {} } } impl RngCore for EmptyRng { fn next_u32(&mut self) -> u32 { 0 } fn next_u64(&mut self) -> u64 { 0 } fn fill_bytes(&mut self, _dest: &mut [u8]) {} fn try_fill_bytes(&mut self, _dest: &mut [u8]) -> core::result::Result<(), rand_core::Error> { Ok(()) } }