Skip to content
Merged
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
32 changes: 32 additions & 0 deletions security-framework/src/passwords_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ use core_foundation::string::{CFString, CFStringRef};
use security_framework_sys::access_control::*;
use security_framework_sys::item::{
kSecAttrAccessControl, kSecAttrAccessGroup, kSecAttrAccount, kSecAttrAuthenticationType,
kSecAttrComment, kSecAttrDescription, kSecAttrLabel,
kSecAttrPath, kSecAttrPort, kSecAttrProtocol, kSecAttrSecurityDomain, kSecAttrServer,
kSecAttrService, kSecClass, kSecClassGenericPassword, kSecClassInternetPassword,
};
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
use security_framework_sys::item::kSecAttrSynchronizable;
#[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
use security_framework_sys::item::kSecAttrSynchronizableAny;
#[cfg(any(feature = "OSX_10_15", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
use security_framework_sys::item::kSecUseDataProtectionKeychain;
use security_framework_sys::keychain::{SecAuthenticationType, SecProtocolType};

/// `PasswordOptions` constructor
Expand Down Expand Up @@ -171,6 +174,35 @@ impl PasswordOptions {
}
}

/// Set the comment on the password
pub fn set_comment(&mut self, comment: &str) {
unsafe {
self.push_query(kSecAttrComment, CFString::from(comment));
}
}

/// Add a description to the password
pub fn set_description(&mut self, description: &str) {
unsafe {
self.push_query(kSecAttrDescription, CFString::from(description));
}
}

/// Add a label to the password
pub fn set_label(&mut self, label: &str) {
unsafe {
self.push_query(kSecAttrLabel, CFString::from(label));
}
}

#[cfg(any(feature = "OSX_10_15", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))]
/// Use the data protection keychain (always true except on macOS)
pub fn use_protected_keychain(&mut self) {
unsafe {
self.push_query(kSecUseDataProtectionKeychain, CFBoolean::from(true));
}
}

/// The key must be a `kSec*` constant.
/// Value is any owned ObjC object, like `CFString`.
pub(crate) unsafe fn push_query(&mut self, static_key_constant: CFStringRef, value: impl TCFType) {
Expand Down
Loading