-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: Support access control options (#178)
- Loading branch information
Showing
11 changed files
with
237 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use core_foundation_sys::base::{CFAllocatorRef, CFTypeRef, CFTypeID}; | ||
use core_foundation_sys::error::CFErrorRef; | ||
use core_foundation_sys::base::CFOptionFlags; | ||
|
||
use crate::base::SecAccessControlRef; | ||
|
||
mod access_control_flags { | ||
use super::CFOptionFlags; | ||
|
||
pub const kSecAccessControlUserPresence: CFOptionFlags = 1 << 0; | ||
pub const kSecAccessControlBiometryAny: CFOptionFlags = 1 << 1; | ||
pub const kSecAccessControlBiometryCurrentSet: CFOptionFlags = 1 << 3; | ||
pub const kSecAccessControlDevicePasscode: CFOptionFlags = 1 << 4; | ||
pub const kSecAccessControlWatch: CFOptionFlags = 1 << 5; | ||
pub const kSecAccessControlOr: CFOptionFlags = 1 << 14; | ||
pub const kSecAccessControlAnd: CFOptionFlags = 1 << 15; | ||
pub const kSecAccessControlPrivateKeyUsage: CFOptionFlags = 1 << 30; | ||
pub const kSecAccessControlApplicationPassword: CFOptionFlags = 1 << 31; | ||
} | ||
|
||
pub use access_control_flags::*; | ||
|
||
extern "C" { | ||
pub fn SecAccessControlGetTypeID() -> CFTypeID; | ||
|
||
pub fn SecAccessControlCreateWithFlags( | ||
allocator: CFAllocatorRef, | ||
protection: CFTypeRef, | ||
flags: CFOptionFlags, | ||
error: *mut CFErrorRef | ||
) -> SecAccessControlRef; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! Access Control support. | ||
|
||
use std::ptr::{self, null}; | ||
|
||
use core_foundation::base::{TCFType, CFOptionFlags, kCFAllocatorDefault}; | ||
use security_framework_sys::access_control::{SecAccessControlGetTypeID, SecAccessControlCreateWithFlags}; | ||
use security_framework_sys::base::{SecAccessControlRef, errSecParam}; | ||
use crate::base::{Error, Result}; | ||
|
||
declare_TCFType! { | ||
/// A type representing sec access control settings. | ||
SecAccessControl, SecAccessControlRef | ||
} | ||
impl_TCFType!(SecAccessControl, SecAccessControlRef, SecAccessControlGetTypeID); | ||
|
||
unsafe impl Sync for SecAccessControl {} | ||
unsafe impl Send for SecAccessControl {} | ||
|
||
|
||
impl SecAccessControl { | ||
|
||
/// Create `AccessControl` object from flags | ||
pub fn create_with_flags(flags: CFOptionFlags) -> Result<Self> { | ||
unsafe { | ||
let access_control = SecAccessControlCreateWithFlags(kCFAllocatorDefault, null(), flags, ptr::null_mut()); | ||
if access_control.is_null() { | ||
Err(Error::from_code(errSecParam)) | ||
} else { | ||
Ok(Self::wrap_under_create_rule(access_control)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.