Skip to content

Add ItemSearchOptions support for skipping authenticated items. #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion security-framework-sys/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ extern "C" {
pub static kSecAttrTokenIDSecureEnclave: CFStringRef;
#[cfg(any(feature = "OSX_10_13", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub static kSecUseAuthenticationContext: CFStringRef;
#[cfg(any(feature = "OSX_10_13", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
#[cfg(any(feature = "OSX_10_11", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub static kSecUseAuthenticationUI: CFStringRef;
#[cfg(any(feature = "OSX_10_11", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub static kSecUseAuthenticationUISkip: CFStringRef;
#[cfg(any(feature = "OSX_10_9", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub static kSecAttrSynchronizable: CFStringRef;
#[cfg(any(feature = "OSX_10_9", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub static kSecAttrSynchronizableAny: CFStringRef;

pub static kSecAttrKeySizeInBits: CFStringRef;

Expand Down
15 changes: 15 additions & 0 deletions security-framework/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub struct ItemSearchOptions {
app_label: Option<CFData>,
#[cfg(any(feature = "OSX_10_13", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
authentication_context: Option<CFType>,
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
skip_authenticated_items: bool,
}

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -309,6 +311,14 @@ impl ItemSearchOptions {
self
}

/// Whether to skip items in the search that require authentication (default false)
#[inline(always)]
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
pub fn skip_authenticated_items(&mut self, do_skip: bool) -> &mut Self {
self.skip_authenticated_items = do_skip;
self
}

/// Populates a `CFDictionary` to be passed to `update_item` or `delete_item`.
// CFDictionary should not be exposed in public Rust APIs.
#[inline]
Expand Down Expand Up @@ -407,6 +417,11 @@ impl ItemSearchOptions {
params.add(&kSecUseAuthenticationContext.to_void(), &authentication_context.to_void());
}

#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
if self.skip_authenticated_items {
params.add(&kSecUseAuthenticationUI.to_void(), &kSecUseAuthenticationUISkip.to_void());
}

params.to_immutable()
}
}
Expand Down
Loading