Skip to content

Commit

Permalink
ItemSearchOptions: Allow searching for certificates by serial number
Browse files Browse the repository at this point in the history
  • Loading branch information
olvrlrnz committed Nov 15, 2024
1 parent 68fee25 commit 55fe4fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions security-framework-sys/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern "C" {
pub static kSecAttrLabel: CFStringRef;
pub static kSecAttrIsPermanent: CFStringRef;
pub static kSecAttrPublicKeyHash: CFStringRef;
pub static kSecAttrSerialNumber: CFStringRef;
pub static kSecPrivateKeyAttrs: CFStringRef;
pub static kSecPublicKeyAttrs: CFStringRef;

Expand Down
17 changes: 17 additions & 0 deletions security-framework/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub struct ItemSearchOptions {
account: Option<CFString>,
access_group: Option<CFString>,
pub_key_hash: Option<CFData>,
serial_number: Option<CFData>,
app_label: Option<CFData>,
}

Expand Down Expand Up @@ -272,6 +273,15 @@ impl ItemSearchOptions {
self
}

/// Search for a certificate with the given serial number.
///
/// This is only compatible with [`ItemClass::certificate`].
#[inline(always)]
pub fn serial_number(&mut self, serial_number: &[u8]) -> &mut Self {
self.serial_number = Some(CFData::from_buffer(serial_number));
self
}

/// Search for a key with the given public key hash.
///
/// This is only compatible with [`ItemClass::key`], to search for a
Expand Down Expand Up @@ -399,6 +409,13 @@ impl ItemSearchOptions {
);
}

if let Some(ref serial_number) = self.serial_number {
params.add(
&kSecAttrSerialNumber.to_void(),
&serial_number.to_void(),
);
}

if let Some(ref app_label) = self.app_label {
params.add(
&kSecAttrApplicationLabel.to_void(),
Expand Down

0 comments on commit 55fe4fe

Please sign in to comment.