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 iOS
10 use crate::{error::SEC_RANDOM_FAILED, Error}
;
12 // TODO: Make extern once extern_types feature is stabilized. See:
13 // https://github.com/rust-lang/rust/issues/43467
15 struct SecRandom([u8; 0]);
17 #[link(name = "Security", kind = "framework")]
19 static kSecRandomDefault
: *const SecRandom
;
21 fn SecRandomCopyBytes(rnd
: *const SecRandom
, count
: usize, bytes
: *mut u8) -> i32;
24 pub fn getrandom_inner(dest
: &mut [u8]) -> Result
<(), Error
> {
25 let ret
= unsafe { SecRandomCopyBytes(kSecRandomDefault, dest.len(), dest.as_mut_ptr()) }
;
27 Err(SEC_RANDOM_FAILED
)