twizzler_rt_abi/
random.rs

1//! Functions for collecting randomness.
2use core::mem::MaybeUninit;
3
4bitflags::bitflags! {
5    /// Possible flags to get random.
6    pub struct GetRandomFlags: crate::bindings::get_random_flags {
7        /// Do not block. If the operation would block, return fewer than requested bytes.
8        const NON_BLOCKING = crate::bindings::GET_RANDOM_NON_BLOCKING;
9    }
10}
11
12/// Fill up to buf.len() bytes of randomness into the buffer.
13pub fn twz_rt_get_random(buf: &mut [MaybeUninit<u8>], flags: GetRandomFlags) -> usize {
14    unsafe { crate::bindings::twz_rt_get_random(buf.as_mut_ptr().cast(), buf.len(), flags.bits()) }
15}