Skip to content

Commit

Permalink
Merge pull request #706 from erickt/master
Browse files Browse the repository at this point in the history
Switch rand_os to use fuchsia-cprng crate in rand-0.6
  • Loading branch information
dhardy committed Jan 25, 2019
2 parents 6f3875f + c963f9d commit c864540
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rand_os/Cargo.toml
Expand Up @@ -28,7 +28,7 @@ winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "winnt"] }
cloudabi = "0.0.3"

[target.'cfg(target_os = "fuchsia")'.dependencies]
fuchsia-zircon = "0.3.2"
fuchsia-cprng = "0.1.0"

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.12", optional = true }
Expand Down
21 changes: 3 additions & 18 deletions rand_os/src/fuchsia.rs
Expand Up @@ -8,9 +8,9 @@

//! Implementation for Fuchsia Zircon

extern crate fuchsia_zircon;
extern crate fuchsia_cprng;

use rand_core::{Error, ErrorKind};
use rand_core::Error;
use super::OsRngImpl;

#[derive(Clone, Debug)]
Expand All @@ -20,24 +20,9 @@ impl OsRngImpl for OsRng {
fn new() -> Result<OsRng, Error> { Ok(OsRng) }

fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> {
let mut read = 0;
while read < dest.len() {
match fuchsia_zircon::cprng_draw(&mut dest[read..]) {
Ok(actual) => read += actual,
Err(e) => {
return Err(Error::with_cause(
ErrorKind::Unavailable,
"cprng_draw failed",
e.into_io_error()));
}
};
}
fuchsia_cprng::cprng_draw(dest);
Ok(())
}

fn max_chunk_size(&self) -> usize {
fuchsia_zircon::sys::ZX_CPRNG_DRAW_MAX_LEN
}

fn method_str(&self) -> &'static str { "cprng_draw" }
}

0 comments on commit c864540

Please sign in to comment.