Skip to content

Commit b6339f5

Browse files
committed
Remove retry counter
1 parent ae6dcb9 commit b6339f5

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ impl Rng for ThreadRng {
989989
///
990990
/// `EntropyRng` uses the interface for random numbers provided by the operating
991991
/// system ([`OsRng`]). If that returns an error, it will fall back to the
992-
/// [`JitterRng`] entropy collector. Occasionally it will then check if `OsRng`
992+
/// [`JitterRng`] entropy collector. Every time it will then check if `OsRng`
993993
/// is still not available, and switch back if possible.
994994
///
995995
/// [`OsRng`]: os/struct.OsRng.html
@@ -998,7 +998,6 @@ impl Rng for ThreadRng {
998998
#[derive(Debug)]
999999
pub struct EntropyRng {
10001000
rng: EntropySource,
1001-
counter: u32,
10021001
}
10031002

10041003
#[cfg(feature="std")]
@@ -1017,7 +1016,7 @@ impl EntropyRng {
10171016
/// those are done on first use. This is done to make `new` infallible,
10181017
/// and `try_fill_bytes` the only place to report errors.
10191018
pub fn new() -> Self {
1020-
EntropyRng { rng: EntropySource::None, counter: 0u32 }
1019+
EntropyRng { rng: EntropySource::None }
10211020
}
10221021
}
10231022

@@ -1078,22 +1077,15 @@ impl Rng for EntropyRng {
10781077
}
10791078
}
10801079
EntropySource::Jitter(ref mut rng) => {
1081-
if self.counter >= 8 {
1082-
if let Ok(os_rng) = try_os_new(dest) {
1083-
switch_rng = Some(EntropySource::Os(os_rng));
1084-
} else {
1085-
self.counter = (self.counter + 1) % 8;
1086-
return rng.try_fill_bytes(dest); // use JitterRng
1087-
}
1080+
if let Ok(os_rng) = try_os_new(dest) {
1081+
switch_rng = Some(EntropySource::Os(os_rng));
10881082
} else {
1089-
self.counter = (self.counter + 1) % 8;
10901083
return rng.try_fill_bytes(dest); // use JitterRng
10911084
}
10921085
}
10931086
}
10941087
if let Some(rng) = switch_rng {
10951088
self.rng = rng;
1096-
self.counter = 0;
10971089
}
10981090
Ok(())
10991091
}

0 commit comments

Comments
 (0)