]> git.proxmox.com Git - rustc.git/blame - vendor/getrandom/src/wasi.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / vendor / getrandom / src / wasi.rs
CommitLineData
f20569fa
XL
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 WASI
10use crate::Error;
11use core::num::NonZeroU32;
12use wasi::random_get;
13
14pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
15 unsafe { random_get(dest.as_mut_ptr(), dest.len()) }.map_err(|e: wasi::Error| {
16 // convert wasi's Error into getrandom's NonZeroU32 error
17 NonZeroU32::new(e.raw_error() as u32).unwrap().into()
18 })
19}