]> git.proxmox.com Git - rustc.git/blame - vendor/getrandom-0.1.16/src/ios.rs
Update unsuspicious file list
[rustc.git] / vendor / getrandom-0.1.16 / src / ios.rs
CommitLineData
416331ca
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 iOS
10use crate::{error::SEC_RANDOM_FAILED, Error};
11
12// TODO: Make extern once extern_types feature is stabilized. See:
13// https://github.com/rust-lang/rust/issues/43467
14#[repr(C)]
15struct SecRandom([u8; 0]);
16
17#[link(name = "Security", kind = "framework")]
18extern "C" {
19 static kSecRandomDefault: *const SecRandom;
20
21 fn SecRandomCopyBytes(rnd: *const SecRandom, count: usize, bytes: *mut u8) -> i32;
22}
23
24pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
25 let ret = unsafe { SecRandomCopyBytes(kSecRandomDefault, dest.len(), dest.as_mut_ptr()) };
26 if ret == -1 {
27 Err(SEC_RANDOM_FAILED)
28 } else {
29 Ok(())
30 }
31}