Debian Codegraph @

.cargo/vendor/getrandom/src/backends/apple_other.rs

raw
1 //! Implementation for iOS, tvOS, and watchOS where `getentropy` is unavailable.
2 use crate::Error;
3 use core::{ffi::c_void, mem::MaybeUninit};
4
5 pub use crate::util::{inner_u32, inner_u64};
6
7 #[inline]
8 pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
9 let dst_ptr = dest.as_mut_ptr().cast::<c_void>();
10 let ret = unsafe { libc::CCRandomGenerateBytes(dst_ptr, dest.len()) };
11 if ret == libc::kCCSuccess {
12 Ok(())
13 } else {
14 Err(Error::IOS_RANDOM_GEN)
15 }
16 }
17
18 impl Error {
19 /// Call to `CCRandomGenerateBytes` failed.
20 pub(crate) const IOS_RANDOM_GEN: Error = Self::new_internal(10);
21 }