getrandom/fuchsia.rs
1// Copyright 2018 Developers of the Rand project.
2//
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.
8
9//! Implementation for Fuchsia Zircon
10use crate::Error;
11use core::mem::MaybeUninit;
12
13#[link(name = "zircon")]
14extern "C" {
15 fn zx_cprng_draw(buffer: *mut u8, length: usize);
16}
17
18pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
19 unsafe { zx_cprng_draw(dest.as_mut_ptr() as *mut u8, dest.len()) }
20 Ok(())
21}