Skip to content

Commit 0e35828

Browse files
brotskydotcomkornelski
authored andcommitted
Add a default protection mode to SecAccessControl::create_with_protection.
Fixes #228.
1 parent 4461675 commit 0e35828

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

security-framework/src/access_control.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use security_framework_sys::access_control::{
1212
};
1313
use security_framework_sys::base::{errSecParam, SecAccessControlRef};
1414
use std::fmt;
15-
use std::ptr::{self, null};
15+
use std::ptr;
1616

1717
declare_TCFType! {
1818
/// A type representing sec access control settings.
@@ -62,11 +62,13 @@ impl SecAccessControl {
6262
ProtectionMode::AccessibleAfterFirstUnlockThisDeviceOnly => unsafe { CFString::wrap_under_get_rule(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly) },
6363
ProtectionMode::AccessibleAfterFirstUnlock => unsafe { CFString::wrap_under_get_rule(kSecAttrAccessibleAfterFirstUnlock) },
6464
}
65+
}).unwrap_or_else(|| {
66+
unsafe { CFString::wrap_under_get_rule(kSecAttrAccessibleWhenUnlocked) }
6567
});
6668
unsafe {
6769
let access_control = SecAccessControlCreateWithFlags(
6870
kCFAllocatorDefault,
69-
protection_val.map(|v| v.as_CFTypeRef()).unwrap_or(null()),
71+
protection_val.as_CFTypeRef(),
7072
flags,
7173
ptr::null_mut(),
7274
);

0 commit comments

Comments
 (0)