1 // Copyright 2018 Developers of the Rand project.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 //! Implementation for CloudABI
11 extern crate cloudabi
;
14 use rand_core
::{Error, ErrorKind}
;
17 #[derive(Clone, Debug)]
20 impl OsRngImpl
for OsRng
{
21 fn new() -> Result
<OsRng
, Error
> { Ok(OsRng) }
23 fn fill_chunk(&mut self, dest
: &mut [u8]) -> Result
<(), Error
> {
24 let errno
= unsafe { cloudabi::random_get(dest) }
;
25 if errno
== cloudabi
::errno
::SUCCESS
{
28 // Cloudlibc provides its own `strerror` implementation so we
29 // can use `from_raw_os_error` here.
30 Err(Error
::with_cause(
31 ErrorKind
::Unavailable
,
32 "random_get() system call failed",
33 io
::Error
::from_raw_os_error(errno
as i32),
38 fn method_str(&self) -> &'
static str { "cloudabi::random_get" }