apple_security_framework/
access_control.rs

1//! Access Control support.
2
3use std::ptr::{
4    null, {self},
5};
6
7use core_foundation::base::{kCFAllocatorDefault, CFOptionFlags, TCFType};
8use security_framework_sys::{
9    access_control::{SecAccessControlCreateWithFlags, SecAccessControlGetTypeID},
10    base::{errSecParam, SecAccessControlRef},
11};
12
13use crate::base::{Error, Result};
14
15declare_TCFType! {
16    /// A type representing sec access control settings.
17    SecAccessControl, SecAccessControlRef
18}
19impl_TCFType!(
20    SecAccessControl,
21    SecAccessControlRef,
22    SecAccessControlGetTypeID
23);
24
25unsafe impl Sync for SecAccessControl {}
26unsafe impl Send for SecAccessControl {}
27
28impl SecAccessControl {
29    /// Create `AccessControl` object from flags
30    pub fn create_with_flags(flags: CFOptionFlags) -> Result<Self> {
31        unsafe {
32            let access_control = SecAccessControlCreateWithFlags(
33                kCFAllocatorDefault,
34                null(),
35                flags,
36                ptr::null_mut(),
37            );
38            if access_control.is_null() {
39                Err(Error::from_code(errSecParam))
40            } else {
41                Ok(Self::wrap_under_create_rule(access_control))
42            }
43        }
44    }
45}