Skip to content

Commit

Permalink
Remove retry counter
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Feb 1, 2018
1 parent be2b886 commit 88c4a53
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,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
Expand All @@ -1007,7 +1007,6 @@ impl Rng for ThreadRng {
#[derive(Debug)]
pub struct EntropyRng {
rng: EntropySource,
counter: u32,
}

#[cfg(feature="std")]
Expand All @@ -1026,7 +1025,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 }
}
}

Expand Down Expand Up @@ -1087,22 +1086,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(())
}
Expand Down

0 comments on commit 88c4a53

Please sign in to comment.