Skip to content

Commit

Permalink
Add support for searching by access groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc authored and kornelski committed Apr 2, 2024
1 parent 588c313 commit 3a2b873
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion security-framework/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ impl ItemSearchOptions {
self
}

/// Search for an item with a specific access group.
pub fn access_group(&mut self, access_group: &str) -> &mut Self {
self.access_group = Some(CFString::new(access_group));
self
}

/// Sets `kSecAttrAccessGroup` to `kSecAttrAccessGroupToken`
#[inline(always)]
pub fn access_group_token(&mut self) -> &mut Self {
Expand Down Expand Up @@ -538,6 +544,8 @@ pub struct ItemAddOptions {
pub value: ItemAddValue,
/// Optional kSecAttrAccount attribute.
pub account_name: Option<String>,
/// Optional kSecAttrAccessGroup attribute.
pub access_group: Option<String>,
/// Optional kSecAttrComment attribute.
pub comment: Option<String>,
/// Optional kSecAttrDescription attribute.
Expand All @@ -553,13 +561,18 @@ pub struct ItemAddOptions {
impl ItemAddOptions {
/// Specifies the item to add.
#[must_use] pub fn new(value: ItemAddValue) -> Self {
Self{ value, label: None, location: None, service: None, account_name: None, comment: None, description: None }
Self{ value, label: None, location: None, service: None, account_name: None, comment: None, description: None, access_group: None }
}
/// Specifies the `kSecAttrAccount` attribute.
pub fn set_account_name(&mut self, account_name: impl Into<String>) -> &mut Self {
self.account_name = Some(account_name.into());
self
}
/// Specifies the `kSecAttrAccessGroup` attribute.
pub fn set_access_group(&mut self, access_group: impl Into<String>) -> &mut Self {
self.access_group = Some(access_group.into());
self
}
/// Specifies the `kSecAttrComment` attribute.
pub fn set_comment(&mut self, comment: impl Into<String>) -> &mut Self {
self.comment = Some(comment.into());
Expand Down Expand Up @@ -624,6 +637,10 @@ impl ItemAddOptions {
if let Some(account_name) = &account_name {
dict.add(&unsafe { kSecAttrAccount }.to_void(), &account_name.to_void());
}
let access_group = self.access_group.as_deref().map(CFString::from);
if let Some(access_group) = &access_group {
dict.add(&unsafe { kSecAttrAccessGroup }.to_void(), &access_group.to_void());
}
let comment = self.comment.as_deref().map(CFString::from);
if let Some(comment) = &comment {
dict.add(&unsafe { kSecAttrDescription }.to_void(), &comment.to_void());
Expand Down

0 comments on commit 3a2b873

Please sign in to comment.