Skip to content

Commit

Permalink
Add bindings for SecKeychainCopyDomainDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeville authored and kornelski committed Mar 12, 2021
1 parent c289742 commit d0fea7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions security-framework-sys/src/keychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,22 @@ pub enum SecAuthenticationType {
Any = 0,
}

#[repr(i32)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum SecPreferencesDomain {
User = 0,
System = 1,
Common = 2,
Dynamic = 3,
}

extern "C" {
pub fn SecKeychainGetTypeID() -> CFTypeID;
pub fn SecKeychainCopyDefault(keychain: *mut SecKeychainRef) -> OSStatus;
pub fn SecKeychainCopyDomainDefault(
domain: SecPreferencesDomain,
keychain: *mut SecKeychainRef,
) -> OSStatus;
pub fn SecKeychainCreate(
pathName: *const c_char,
passwordLength: c_uint,
Expand Down
10 changes: 10 additions & 0 deletions security-framework/src/os/macos/keychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ impl SecKeychain {
}
}

/// Creates a `SecKeychain` object corresponding to the user's default
/// keychain for the given domain.
pub fn default_for_domain(domain: SecPreferencesDomain) -> Result<Self> {
unsafe {
let mut keychain = ptr::null_mut();
cvt(SecKeychainCopyDomainDefault(domain, &mut keychain))?;
Ok(Self::wrap_under_create_rule(keychain))
}
}

/// Opens a keychain from a file.
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
let path_name = path.as_ref().as_os_str().as_bytes();
Expand Down

0 comments on commit d0fea7e

Please sign in to comment.