diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml index 2f9224a082c..af97081f830 100644 --- a/rand_os/Cargo.toml +++ b/rand_os/Cargo.toml @@ -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 } diff --git a/rand_os/src/fuchsia.rs b/rand_os/src/fuchsia.rs index 7063ff6d511..ada36776129 100644 --- a/rand_os/src/fuchsia.rs +++ b/rand_os/src/fuchsia.rs @@ -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)] @@ -20,24 +20,9 @@ impl OsRngImpl for OsRng { fn new() -> Result { 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" } }