From b6339f556966ee88cc1d25c70d5cf256acbc7da1 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Mon, 22 Jan 2018 20:11:32 +0100 Subject: [PATCH] Remove retry counter --- src/lib.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2878d60769..6fe45bc018 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -989,7 +989,7 @@ impl Rng for ThreadRng { /// /// `EntropyRng` uses the interface for random numbers provided by the operating /// system ([`OsRng`]). If that returns an error, it will fall back to the -/// [`JitterRng`] entropy collector. Occasionally it will then check if `OsRng` +/// [`JitterRng`] entropy collector. Every time it will then check if `OsRng` /// is still not available, and switch back if possible. /// /// [`OsRng`]: os/struct.OsRng.html @@ -998,7 +998,6 @@ impl Rng for ThreadRng { #[derive(Debug)] pub struct EntropyRng { rng: EntropySource, - counter: u32, } #[cfg(feature="std")] @@ -1017,7 +1016,7 @@ impl EntropyRng { /// those are done on first use. This is done to make `new` infallible, /// and `try_fill_bytes` the only place to report errors. pub fn new() -> Self { - EntropyRng { rng: EntropySource::None, counter: 0u32 } + EntropyRng { rng: EntropySource::None } } } @@ -1078,22 +1077,15 @@ impl Rng for EntropyRng { } } EntropySource::Jitter(ref mut rng) => { - if self.counter >= 8 { - if let Ok(os_rng) = try_os_new(dest) { - switch_rng = Some(EntropySource::Os(os_rng)); - } else { - self.counter = (self.counter + 1) % 8; - return rng.try_fill_bytes(dest); // use JitterRng - } + if let Ok(os_rng) = try_os_new(dest) { + switch_rng = Some(EntropySource::Os(os_rng)); } else { - self.counter = (self.counter + 1) % 8; return rng.try_fill_bytes(dest); // use JitterRng } } } if let Some(rng) = switch_rng { self.rng = rng; - self.counter = 0; } Ok(()) }