Skip to content

Commit 878034e

Browse files
tmpfskornelski
authored andcommitted
Support custom password options attributes.
1 parent b2189b2 commit 878034e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

security-framework/src/passwords.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ pub fn set_generic_password(service: &str, account: &str, password: &[u8]) -> Re
2727
set_password_internal(&mut options, password)
2828
}
2929

30+
/// Set a generic password using the given password options.
31+
/// Creates or updates a keychain entry.
32+
pub fn set_generic_password_options(
33+
password: &[u8],
34+
mut options: PasswordOptions) -> Result<()> {
35+
set_password_internal(&mut options, password)
36+
}
37+
3038
/// Get the generic password for the given service and account. If no matching
3139
/// keychain entry exists, fails with error code `errSecItemNotFound`.
3240
pub fn get_generic_password(service: &str, account: &str) -> Result<Vec<u8>> {

security-framework/src/passwords_options.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Support for password options, to be used with the passwords module
22
33
use core_foundation::{string::CFString, base::{CFType, TCFType, CFOptionFlags}, number::CFNumber};
4-
use security_framework_sys::{keychain::{SecProtocolType, SecAuthenticationType}, access_control::*};
4+
use security_framework_sys::{access_control::*, item::kSecAttrAccessGroup, keychain::{SecAuthenticationType, SecProtocolType}};
55
use security_framework_sys::item::{
66
kSecAttrAccessControl, kSecAttrAccount, kSecAttrAuthenticationType, kSecAttrPath, kSecAttrPort, kSecAttrProtocol,
77
kSecAttrSecurityDomain, kSecAttrServer, kSecAttrService, kSecClass, kSecClassGenericPassword,
@@ -127,4 +127,12 @@ impl PasswordOptions {
127127
.into_CFType(),
128128
));
129129
}
130+
131+
/// Add access group to the password
132+
pub fn set_access_group(&mut self, group: &str) {
133+
self.query.push((
134+
unsafe { CFString::wrap_under_get_rule(kSecAttrAccessGroup) },
135+
CFString::from(group).into_CFType(),
136+
));
137+
}
130138
}

0 commit comments

Comments
 (0)