Skip to content

Commit

Permalink
Add logging to EntropyRng
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Feb 1, 2018
1 parent 88c4a53 commit 69eee53
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,26 +1067,41 @@ impl Rng for EntropyRng {
switch_rng = Some(EntropySource::Os(os_rng));
}
Err(os_rng_error) => {
if let Ok(jitter_rng) = try_jitter_new(dest) {
switch_rng = Some(EntropySource::Jitter(jitter_rng));
} else {
return Err(os_rng_error);
warn!("EntropyRng: OsRng failed [falling back to JitterRng]: {}",
os_rng_error);
match try_jitter_new(dest) {
Ok(jitter_rng) => {
switch_rng = Some(EntropySource::Jitter(jitter_rng));
}
Err(jitter_error) => {
warn!("EntropyRng: JitterRng failed: {}",
jitter_error);
return Err(os_rng_error);
}
}
}
}
}
EntropySource::Os(ref mut rng) => {
let os_rng_result = rng.try_fill_bytes(dest);
if os_rng_result.is_err() {
if let Ok(jitter_rng) = try_jitter_new(dest) {
switch_rng = Some(EntropySource::Jitter(jitter_rng));
} else {
return os_rng_result;
if let Err(os_rng_error) = os_rng_result {
warn!("EntropyRng: OsRng failed [falling back to JitterRng]: {}",
os_rng_error);
match try_jitter_new(dest) {
Ok(jitter_rng) => {
switch_rng = Some(EntropySource::Jitter(jitter_rng));
}
Err(jitter_error) => {
warn!("EntropyRng: JitterRng failed: {}",
jitter_error);
return Err(os_rng_error);
}
}
}
}
EntropySource::Jitter(ref mut rng) => {
if let Ok(os_rng) = try_os_new(dest) {
info!("EntropyRng: OsRng available [switching back from JitterRng]");
switch_rng = Some(EntropySource::Os(os_rng));
} else {
return rng.try_fill_bytes(dest); // use JitterRng
Expand Down

0 comments on commit 69eee53

Please sign in to comment.