From 0908c0ece5f009a1fa6fab5d6fb4b1bf362a7f65 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 1 Sep 2024 13:43:16 +0100 Subject: [PATCH] Avoid exposing CFDictionary --- security-framework/src/key.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/security-framework/src/key.rs b/security-framework/src/key.rs index a244de8c..5b7fa372 100644 --- a/security-framework/src/key.rs +++ b/security-framework/src/key.rs @@ -131,10 +131,18 @@ unsafe impl Sync for SecKey {} unsafe impl Send for SecKey {} impl SecKey { + /// Translates to `SecKeyCreateRandomKey` + #[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))] + #[allow(deprecated)] + #[doc(alias = "SecKeyCreateRandomKey")] + pub fn new(options: &GenerateKeyOptions) -> Result { + Self::generate(options.to_dictionary()) + } + #[cfg(any(feature = "OSX_10_12", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos"))] /// Translates to `SecKeyCreateRandomKey` - /// `GenerateKeyOptions` provides a helper to create an attribute - /// `CFDictionary`. + /// `GenerateKeyOptions` provides a helper to create an attribute `CFDictionary`. + #[deprecated(note = "Use SecKey::new")] pub fn generate(attributes: CFDictionary) -> Result { let mut error: CFErrorRef = ::std::ptr::null_mut(); let sec_key = unsafe { SecKeyCreateRandomKey(attributes.as_concrete_TypeRef(), &mut error)}; @@ -307,6 +315,7 @@ impl GenerateKeyOptions { } /// Collect options into a `CFDictioanry` + #[deprecated(note = "Pass the options to SecKey::new")] pub fn to_dictionary(&self) -> CFDictionary { #[cfg(target_os = "macos")] use security_framework_sys::item::kSecUseKeychain;