objc2_security/generated/SecKey.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7use objc2_core_foundation::*;
8
9use crate::*;
10
11/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyclass?language=objc)
12#[deprecated = "No longer supported"]
13pub const kSecKeyKeyClass: c_int = 0;
14/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyprintname?language=objc)
15#[deprecated = "No longer supported"]
16pub const kSecKeyPrintName: c_int = 1;
17/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalias?language=objc)
18#[deprecated = "No longer supported"]
19pub const kSecKeyAlias: c_int = 2;
20/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeypermanent?language=objc)
21#[deprecated = "No longer supported"]
22pub const kSecKeyPermanent: c_int = 3;
23/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyprivate?language=objc)
24#[deprecated = "No longer supported"]
25pub const kSecKeyPrivate: c_int = 4;
26/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeymodifiable?language=objc)
27#[deprecated = "No longer supported"]
28pub const kSecKeyModifiable: c_int = 5;
29/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeylabel?language=objc)
30#[deprecated = "No longer supported"]
31pub const kSecKeyLabel: c_int = 6;
32/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyapplicationtag?language=objc)
33#[deprecated = "No longer supported"]
34pub const kSecKeyApplicationTag: c_int = 7;
35/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeycreator?language=objc)
36#[deprecated = "No longer supported"]
37pub const kSecKeyKeyCreator: c_int = 8;
38/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeytype?language=objc)
39#[deprecated = "No longer supported"]
40pub const kSecKeyKeyType: c_int = 9;
41/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeysizeinbits?language=objc)
42#[deprecated = "No longer supported"]
43pub const kSecKeyKeySizeInBits: c_int = 10;
44/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyeffectivekeysize?language=objc)
45#[deprecated = "No longer supported"]
46pub const kSecKeyEffectiveKeySize: c_int = 11;
47/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeystartdate?language=objc)
48#[deprecated = "No longer supported"]
49pub const kSecKeyStartDate: c_int = 12;
50/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyenddate?language=objc)
51#[deprecated = "No longer supported"]
52pub const kSecKeyEndDate: c_int = 13;
53/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysensitive?language=objc)
54#[deprecated = "No longer supported"]
55pub const kSecKeySensitive: c_int = 14;
56/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalwayssensitive?language=objc)
57#[deprecated = "No longer supported"]
58pub const kSecKeyAlwaysSensitive: c_int = 15;
59/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyextractable?language=objc)
60#[deprecated = "No longer supported"]
61pub const kSecKeyExtractable: c_int = 16;
62/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyneverextractable?language=objc)
63#[deprecated = "No longer supported"]
64pub const kSecKeyNeverExtractable: c_int = 17;
65/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyencrypt?language=objc)
66#[deprecated = "No longer supported"]
67pub const kSecKeyEncrypt: c_int = 18;
68/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeydecrypt?language=objc)
69#[deprecated = "No longer supported"]
70pub const kSecKeyDecrypt: c_int = 19;
71/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyderive?language=objc)
72#[deprecated = "No longer supported"]
73pub const kSecKeyDerive: c_int = 20;
74/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysign?language=objc)
75#[deprecated = "No longer supported"]
76pub const kSecKeySign: c_int = 21;
77/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyverify?language=objc)
78#[deprecated = "No longer supported"]
79pub const kSecKeyVerify: c_int = 22;
80/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeysignrecover?language=objc)
81#[deprecated = "No longer supported"]
82pub const kSecKeySignRecover: c_int = 23;
83/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyverifyrecover?language=objc)
84#[deprecated = "No longer supported"]
85pub const kSecKeyVerifyRecover: c_int = 24;
86/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeywrap?language=objc)
87#[deprecated = "No longer supported"]
88pub const kSecKeyWrap: c_int = 25;
89/// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyunwrap?language=objc)
90#[deprecated = "No longer supported"]
91pub const kSecKeyUnwrap: c_int = 26;
92
93/// Determines the type of credential returned by SecKeyGetCredentials.
94///
95/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seccredentialtype?language=objc)
96// NS_ENUM
97#[cfg(feature = "cssmconfig")]
98#[deprecated = "No longer supported"]
99#[repr(transparent)]
100#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
101pub struct SecCredentialType(pub uint32);
102#[cfg(feature = "cssmconfig")]
103impl SecCredentialType {
104 #[doc(alias = "kSecCredentialTypeDefault")]
105 #[deprecated = "No longer supported"]
106 pub const Default: Self = Self(0);
107 #[doc(alias = "kSecCredentialTypeWithUI")]
108 #[deprecated = "No longer supported"]
109 pub const WithUI: Self = Self(1);
110 #[doc(alias = "kSecCredentialTypeNoUI")]
111 #[deprecated = "No longer supported"]
112 pub const NoUI: Self = Self(2);
113}
114
115#[cfg(all(feature = "cssmconfig", feature = "objc2"))]
116unsafe impl Encode for SecCredentialType {
117 const ENCODING: Encoding = uint32::ENCODING;
118}
119
120#[cfg(all(feature = "cssmconfig", feature = "objc2"))]
121unsafe impl RefEncode for SecCredentialType {
122 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
123}
124
125/// Supported padding types.
126///
127/// See also [Apple's documentation](https://developer.apple.com/documentation/security/secpadding?language=objc)
128// NS_OPTIONS
129#[deprecated = "Replaced with SecKeyAlgorithm"]
130#[repr(transparent)]
131#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
132pub struct SecPadding(pub u32);
133bitflags::bitflags! {
134 impl SecPadding: u32 {
135 #[doc(alias = "kSecPaddingNone")]
136#[deprecated = "Replaced with SecKeyAlgorithm"]
137 const None = 0;
138 #[doc(alias = "kSecPaddingPKCS1")]
139#[deprecated = "Replaced with SecKeyAlgorithm"]
140 const PKCS1 = 1;
141 #[doc(alias = "kSecPaddingOAEP")]
142#[deprecated = "Replaced with SecKeyAlgorithm"]
143 const OAEP = 2;
144 #[doc(alias = "kSecPaddingSigRaw")]
145#[deprecated = "Replaced with SecKeyAlgorithm"]
146 const SigRaw = 0x4000;
147 #[doc(alias = "kSecPaddingPKCS1MD2")]
148#[deprecated = "Replaced with SecKeyAlgorithm"]
149 const PKCS1MD2 = 0x8000;
150 #[doc(alias = "kSecPaddingPKCS1MD5")]
151#[deprecated = "Replaced with SecKeyAlgorithm"]
152 const PKCS1MD5 = 0x8001;
153 #[doc(alias = "kSecPaddingPKCS1SHA1")]
154#[deprecated = "Replaced with SecKeyAlgorithm"]
155 const PKCS1SHA1 = 0x8002;
156 #[doc(alias = "kSecPaddingPKCS1SHA224")]
157#[deprecated = "Replaced with SecKeyAlgorithm"]
158 const PKCS1SHA224 = 0x8003;
159 #[doc(alias = "kSecPaddingPKCS1SHA256")]
160#[deprecated = "Replaced with SecKeyAlgorithm"]
161 const PKCS1SHA256 = 0x8004;
162 #[doc(alias = "kSecPaddingPKCS1SHA384")]
163#[deprecated = "Replaced with SecKeyAlgorithm"]
164 const PKCS1SHA384 = 0x8005;
165 #[doc(alias = "kSecPaddingPKCS1SHA512")]
166#[deprecated = "Replaced with SecKeyAlgorithm"]
167 const PKCS1SHA512 = 0x8006;
168 }
169}
170
171#[cfg(feature = "objc2")]
172unsafe impl Encode for SecPadding {
173 const ENCODING: Encoding = u32::ENCODING;
174}
175
176#[cfg(feature = "objc2")]
177unsafe impl RefEncode for SecPadding {
178 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
179}
180
181/// Supported key lengths.
182///
183/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeysizes?language=objc)
184// NS_ENUM
185#[deprecated = "No longer supported"]
186#[repr(transparent)]
187#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
188pub struct SecKeySizes(pub u32);
189impl SecKeySizes {
190 #[doc(alias = "kSecDefaultKeySize")]
191 #[deprecated = "No longer supported"]
192 pub const SecDefaultKeySize: Self = Self(0);
193 #[doc(alias = "kSec3DES192")]
194 #[deprecated = "No longer supported"]
195 pub const Sec3DES192: Self = Self(192);
196 #[doc(alias = "kSecAES128")]
197 #[deprecated = "No longer supported"]
198 pub const SecAES128: Self = Self(128);
199 #[doc(alias = "kSecAES192")]
200 #[deprecated = "No longer supported"]
201 pub const SecAES192: Self = Self(192);
202 #[doc(alias = "kSecAES256")]
203 #[deprecated = "No longer supported"]
204 pub const SecAES256: Self = Self(256);
205 #[doc(alias = "kSecp192r1")]
206 #[deprecated = "No longer supported"]
207 pub const Secp192r1: Self = Self(192);
208 #[doc(alias = "kSecp256r1")]
209 #[deprecated = "No longer supported"]
210 pub const Secp256r1: Self = Self(256);
211 #[doc(alias = "kSecp384r1")]
212 #[deprecated = "No longer supported"]
213 pub const Secp384r1: Self = Self(384);
214 #[doc(alias = "kSecp521r1")]
215 #[deprecated = "No longer supported"]
216 pub const Secp521r1: Self = Self(521);
217 #[doc(alias = "kSecRSAMin")]
218 #[deprecated = "No longer supported"]
219 pub const SecRSAMin: Self = Self(1024);
220 #[doc(alias = "kSecRSAMax")]
221 #[deprecated = "No longer supported"]
222 pub const SecRSAMax: Self = Self(4096);
223}
224
225#[cfg(feature = "objc2")]
226unsafe impl Encode for SecKeySizes {
227 const ENCODING: Encoding = u32::ENCODING;
228}
229
230#[cfg(feature = "objc2")]
231unsafe impl RefEncode for SecKeySizes {
232 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
233}
234
235extern "C" {
236 /// Predefined key constants used to get or set values in a dictionary.
237 /// These are used to provide explicit parameters to key generation functions
238 /// when non-default values are desired. See the description of the
239 /// SecKeyGeneratePair API for usage information.
240 ///
241 /// containing attributes specific for the private key to be generated.
242 ///
243 /// containing attributes specific for the public key to be generated.
244 ///
245 /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecprivatekeyattrs?language=objc)
246 pub static kSecPrivateKeyAttrs: &'static CFString;
247}
248
249extern "C" {
250 /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpublickeyattrs?language=objc)
251 pub static kSecPublicKeyAttrs: &'static CFString;
252}
253
254#[cfg(feature = "SecBase")]
255unsafe impl ConcreteType for SecKey {
256 /// Returns the type identifier of SecKey instances.
257 ///
258 /// Returns: The CFTypeID of SecKey instances.
259 #[doc(alias = "SecKeyGetTypeID")]
260 #[inline]
261 fn type_id() -> CFTypeID {
262 extern "C-unwind" {
263 fn SecKeyGetTypeID() -> CFTypeID;
264 }
265 unsafe { SecKeyGetTypeID() }
266 }
267}
268
269#[cfg(feature = "SecBase")]
270impl SecKey {
271 /// Creates an asymmetric key pair and stores it in a specified keychain.
272 ///
273 /// Parameter `keychainRef`: A reference to the keychain in which to store the private and public key items. Specify NULL for the default keychain.
274 ///
275 /// Parameter `algorithm`: An algorithm for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
276 ///
277 /// Parameter `keySizeInBits`: A key size for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
278 ///
279 /// Parameter `contextHandle`: (optional) A CSSM_CC_HANDLE, or 0. If this argument is supplied, the algorithm and keySizeInBits parameters are ignored. If extra parameters are needed to generate a key (some algorithms require this), you should create a context using CSSM_CSP_CreateKeyGenContext, using the CSPHandle obtained by calling SecKeychainGetCSPHandle. Then use CSSM_UpdateContextAttributes to add parameters, and dispose of the context using CSSM_DeleteContext after calling this function.
280 ///
281 /// Parameter `publicKeyUsage`: A bit mask indicating all permitted uses for the new public key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
282 ///
283 /// Parameter `publicKeyAttr`: A bit mask defining attribute values for the new public key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
284 ///
285 /// Parameter `privateKeyUsage`: A bit mask indicating all permitted uses for the new private key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
286 ///
287 /// Parameter `privateKeyAttr`: A bit mask defining attribute values for the new private key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
288 ///
289 /// Parameter `initialAccess`: (optional) A SecAccess object that determines the initial access rights to the private key. The public key is given "any/any" access rights by default.
290 ///
291 /// Parameter `publicKey`: (optional) On return, the keychain item reference of the generated public key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned. Pass NULL if a reference to this key is not required.
292 ///
293 /// Parameter `privateKey`: (optional) On return, the keychain item reference of the generated private key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned. Pass NULL if a reference to this key is not required.
294 ///
295 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
296 ///
297 /// This API is deprecated for 10.7. Please use the SecKeyGeneratePair API instead.
298 ///
299 /// # Safety
300 ///
301 /// - `public_key` must be a valid pointer or null.
302 /// - `private_key` must be a valid pointer or null.
303 #[doc(alias = "SecKeyCreatePair")]
304 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
305 #[deprecated = "CSSM is not supported"]
306 #[inline]
307 pub unsafe fn create_pair(
308 keychain_ref: Option<&SecKeychain>,
309 algorithm: CSSM_ALGORITHMS,
310 key_size_in_bits: uint32,
311 context_handle: CSSM_CC_HANDLE,
312 public_key_usage: CSSM_KEYUSE,
313 public_key_attr: uint32,
314 private_key_usage: CSSM_KEYUSE,
315 private_key_attr: uint32,
316 initial_access: Option<&SecAccess>,
317 public_key: *mut *mut SecKey,
318 private_key: *mut *mut SecKey,
319 ) -> OSStatus {
320 extern "C-unwind" {
321 fn SecKeyCreatePair(
322 keychain_ref: Option<&SecKeychain>,
323 algorithm: CSSM_ALGORITHMS,
324 key_size_in_bits: uint32,
325 context_handle: CSSM_CC_HANDLE,
326 public_key_usage: CSSM_KEYUSE,
327 public_key_attr: uint32,
328 private_key_usage: CSSM_KEYUSE,
329 private_key_attr: uint32,
330 initial_access: Option<&SecAccess>,
331 public_key: *mut *mut SecKey,
332 private_key: *mut *mut SecKey,
333 ) -> OSStatus;
334 }
335 unsafe {
336 SecKeyCreatePair(
337 keychain_ref,
338 algorithm,
339 key_size_in_bits,
340 context_handle,
341 public_key_usage,
342 public_key_attr,
343 private_key_usage,
344 private_key_attr,
345 initial_access,
346 public_key,
347 private_key,
348 )
349 }
350 }
351
352 /// Creates a symmetric key and optionally stores it in a specified keychain.
353 ///
354 /// Parameter `keychainRef`: (optional) A reference to the keychain in which to store the generated key. Specify NULL to generate a transient key.
355 ///
356 /// Parameter `algorithm`: An algorithm for the symmetric key. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
357 ///
358 /// Parameter `keySizeInBits`: A key size for the key pair. This parameter is ignored if a valid (non-zero) contextHandle is supplied.
359 ///
360 /// Parameter `contextHandle`: (optional) A CSSM_CC_HANDLE, or 0. If this argument is supplied, the algorithm and keySizeInBits parameters are ignored. If extra parameters are needed to generate a key (some algorithms require this), you should create a context using CSSM_CSP_CreateKeyGenContext, using the CSPHandle obtained by calling SecKeychainGetCSPHandle. Then use CSSM_UpdateContextAttributes to add parameters, and dispose of the context using CSSM_DeleteContext after calling this function.
361 ///
362 /// Parameter `keyUsage`: A bit mask indicating all permitted uses for the new key. CSSM_KEYUSE bit mask values are defined in cssmtype.h.
363 ///
364 /// Parameter `keyAttr`: A bit mask defining attribute values for the new key. The bit mask values are equivalent to a CSSM_KEYATTR_FLAGS and are defined in cssmtype.h.
365 ///
366 /// Parameter `initialAccess`: (optional) A SecAccess object that determines the initial access rights for the key. This parameter is ignored if the keychainRef is NULL.
367 ///
368 /// Parameter `keyRef`: On return, a reference to the generated key. Use the SecKeyGetCSSMKey function to obtain the CSSM_KEY. The caller must call CFRelease on this value if it is returned.
369 ///
370 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
371 ///
372 /// This API is deprecated for 10.7. Please use the SecKeyGenerateSymmetric API instead.
373 ///
374 /// # Safety
375 ///
376 /// `key_ref` must be a valid pointer or null.
377 #[doc(alias = "SecKeyGenerate")]
378 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
379 #[deprecated = "CSSM is not supported"]
380 #[inline]
381 pub unsafe fn generate(
382 keychain_ref: Option<&SecKeychain>,
383 algorithm: CSSM_ALGORITHMS,
384 key_size_in_bits: uint32,
385 context_handle: CSSM_CC_HANDLE,
386 key_usage: CSSM_KEYUSE,
387 key_attr: uint32,
388 initial_access: Option<&SecAccess>,
389 key_ref: *mut *mut SecKey,
390 ) -> OSStatus {
391 extern "C-unwind" {
392 fn SecKeyGenerate(
393 keychain_ref: Option<&SecKeychain>,
394 algorithm: CSSM_ALGORITHMS,
395 key_size_in_bits: uint32,
396 context_handle: CSSM_CC_HANDLE,
397 key_usage: CSSM_KEYUSE,
398 key_attr: uint32,
399 initial_access: Option<&SecAccess>,
400 key_ref: *mut *mut SecKey,
401 ) -> OSStatus;
402 }
403 unsafe {
404 SecKeyGenerate(
405 keychain_ref,
406 algorithm,
407 key_size_in_bits,
408 context_handle,
409 key_usage,
410 key_attr,
411 initial_access,
412 key_ref,
413 )
414 }
415 }
416
417 /// Returns a pointer to the CSSM_KEY for the given key item reference.
418 ///
419 /// Parameter `key`: A keychain key item reference. The key item must be of class type kSecPublicKeyItemClass, kSecPrivateKeyItemClass, or kSecSymmetricKeyItemClass.
420 ///
421 /// Parameter `cssmKey`: On return, a pointer to a CSSM_KEY structure for the given key. This pointer remains valid until the key reference is released. The caller should not attempt to modify or free this data.
422 ///
423 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
424 ///
425 /// The CSSM_KEY is valid until the key item reference is released. This API is deprecated in 10.7. Its use should no longer be needed.
426 ///
427 /// # Safety
428 ///
429 /// `cssm_key` must be a valid pointer.
430 #[doc(alias = "SecKeyGetCSSMKey")]
431 #[cfg(all(
432 feature = "SecAsn1Types",
433 feature = "SecBase",
434 feature = "cssmconfig",
435 feature = "cssmtype"
436 ))]
437 #[deprecated]
438 #[inline]
439 pub unsafe fn cssm_key(&self, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus {
440 extern "C-unwind" {
441 fn SecKeyGetCSSMKey(key: &SecKey, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus;
442 }
443 unsafe { SecKeyGetCSSMKey(self, cssm_key) }
444 }
445
446 /// Returns the CSSM_CSP_HANDLE for the given key reference. The handle is valid until the key reference is released.
447 ///
448 /// Parameter `keyRef`: A key reference.
449 ///
450 /// Parameter `cspHandle`: On return, the CSSM_CSP_HANDLE for the given keychain.
451 ///
452 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
453 ///
454 /// This API is deprecated in 10.7. Its use should no longer be needed.
455 ///
456 /// # Safety
457 ///
458 /// `csp_handle` must be a valid pointer.
459 #[doc(alias = "SecKeyGetCSPHandle")]
460 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
461 #[deprecated]
462 #[inline]
463 pub unsafe fn csp_handle(&self, csp_handle: NonNull<CSSM_CSP_HANDLE>) -> OSStatus {
464 extern "C-unwind" {
465 fn SecKeyGetCSPHandle(
466 key_ref: &SecKey,
467 csp_handle: NonNull<CSSM_CSP_HANDLE>,
468 ) -> OSStatus;
469 }
470 unsafe { SecKeyGetCSPHandle(self, csp_handle) }
471 }
472
473 /// For a given key, return a pointer to a CSSM_ACCESS_CREDENTIALS structure which will allow the key to be used.
474 ///
475 /// Parameter `keyRef`: The key for which a credential is requested.
476 ///
477 /// Parameter `operation`: The type of operation to be performed with this key. See "Authorization tag type" for defined operations (cssmtype.h).
478 ///
479 /// Parameter `credentialType`: The type of credential requested.
480 ///
481 /// Parameter `outCredentials`: On return, a pointer to a CSSM_ACCESS_CREDENTIALS structure. This pointer remains valid until the key reference is released. The caller should not attempt to modify or free this data.
482 ///
483 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
484 ///
485 /// # Safety
486 ///
487 /// `out_credentials` must be a valid pointer.
488 #[doc(alias = "SecKeyGetCredentials")]
489 #[cfg(all(
490 feature = "SecAsn1Types",
491 feature = "SecBase",
492 feature = "cssmconfig",
493 feature = "cssmtype"
494 ))]
495 #[deprecated]
496 #[inline]
497 pub unsafe fn credentials(
498 &self,
499 operation: CSSM_ACL_AUTHORIZATION_TAG,
500 credential_type: SecCredentialType,
501 out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
502 ) -> OSStatus {
503 extern "C-unwind" {
504 fn SecKeyGetCredentials(
505 key_ref: &SecKey,
506 operation: CSSM_ACL_AUTHORIZATION_TAG,
507 credential_type: SecCredentialType,
508 out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
509 ) -> OSStatus;
510 }
511 unsafe { SecKeyGetCredentials(self, operation, credential_type, out_credentials) }
512 }
513
514 /// Generates a random symmetric key with the specified length
515 /// and algorithm type.
516 ///
517 ///
518 /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
519 /// See the discussion sections below for a complete overview of options.
520 ///
521 /// Parameter `error`: An optional pointer to a CFErrorRef. This value is set
522 /// if an error occurred. If not NULL, the caller is responsible for
523 /// releasing the CFErrorRef.
524 ///
525 /// Returns: On return, a SecKeyRef reference to the symmetric key, or
526 /// NULL if the key could not be created.
527 ///
528 ///
529 /// In order to generate a symmetric key, the parameters dictionary
530 /// must at least contain the following keys:
531 ///
532 /// kSecAttrKeyType with a value of kSecAttrKeyTypeAES or any other
533 /// kSecAttrKeyType defined in SecItem.h
534 /// kSecAttrKeySizeInBits with a value being a CFNumberRef containing
535 /// the requested key size in bits. Example sizes for AES keys are:
536 /// 128, 192, 256, 512.
537 ///
538 /// To store the generated symmetric key in a keychain, set these keys:
539 /// kSecUseKeychain (value is a SecKeychainRef)
540 /// kSecAttrLabel (a user-visible label whose value is a CFStringRef,
541 /// e.g. "My App's Encryption Key")
542 /// kSecAttrApplicationLabel (a label defined by your application, whose
543 /// value is a CFDataRef and which can be used to find this key in a
544 /// subsequent call to SecItemCopyMatching, e.g. "ID-1234567890-9876-0151")
545 ///
546 /// To specify the generated key's access control settings, set this key:
547 /// kSecAttrAccess (value is a SecAccessRef)
548 ///
549 /// The keys below may be optionally set in the parameters dictionary
550 /// (with a CFBooleanRef value) to override the default usage values:
551 ///
552 /// kSecAttrCanEncrypt (defaults to true if not explicitly specified)
553 /// kSecAttrCanDecrypt (defaults to true if not explicitly specified)
554 /// kSecAttrCanWrap (defaults to true if not explicitly specified)
555 /// kSecAttrCanUnwrap (defaults to true if not explicitly specified)
556 ///
557 /// # Safety
558 ///
559 /// - `parameters` generics must be of the correct type.
560 /// - `error` must be a valid pointer or null.
561 #[doc(alias = "SecKeyGenerateSymmetric")]
562 #[cfg(feature = "SecBase")]
563 #[deprecated = "No longer supported"]
564 #[inline]
565 pub unsafe fn generate_symmetric(
566 parameters: &CFDictionary,
567 error: *mut *mut CFError,
568 ) -> Option<CFRetained<SecKey>> {
569 extern "C-unwind" {
570 fn SecKeyGenerateSymmetric(
571 parameters: &CFDictionary,
572 error: *mut *mut CFError,
573 ) -> Option<NonNull<SecKey>>;
574 }
575 let ret = unsafe { SecKeyGenerateSymmetric(parameters, error) };
576 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
577 }
578
579 /// Creates a symmetric key with the given data and sets the
580 /// algorithm type specified.
581 ///
582 ///
583 /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
584 /// See the discussion sections below for a complete overview of options.
585 ///
586 /// Returns: On return, a SecKeyRef reference to the symmetric key.
587 ///
588 ///
589 /// In order to generate a symmetric key the parameters dictionary must
590 /// at least contain the following keys:
591 ///
592 /// kSecAttrKeyType with a value of kSecAttrKeyTypeAES or any other
593 /// kSecAttrKeyType defined in SecItem.h
594 ///
595 /// The keys below may be optionally set in the parameters dictionary
596 /// (with a CFBooleanRef value) to override the default usage values:
597 ///
598 /// kSecAttrCanEncrypt (defaults to true if not explicitly specified)
599 /// kSecAttrCanDecrypt (defaults to true if not explicitly specified)
600 /// kSecAttrCanWrap (defaults to true if not explicitly specified)
601 /// kSecAttrCanUnwrap (defaults to true if not explicitly specified)
602 ///
603 /// # Safety
604 ///
605 /// - `parameters` generics must be of the correct type.
606 /// - `error` must be a valid pointer or null.
607 #[doc(alias = "SecKeyCreateFromData")]
608 #[cfg(feature = "SecBase")]
609 #[deprecated = "No longer supported"]
610 #[inline]
611 pub unsafe fn from_data(
612 parameters: &CFDictionary,
613 key_data: &CFData,
614 error: *mut *mut CFError,
615 ) -> Option<CFRetained<SecKey>> {
616 extern "C-unwind" {
617 fn SecKeyCreateFromData(
618 parameters: &CFDictionary,
619 key_data: &CFData,
620 error: *mut *mut CFError,
621 ) -> Option<NonNull<SecKey>>;
622 }
623 let ret = unsafe { SecKeyCreateFromData(parameters, key_data, error) };
624 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
625 }
626}
627
628/// Delivers the result from an asynchronous key pair generation.
629///
630/// Parameter `publicKey`: - the public key generated. You must retain publicKey if you wish to use it after your block returns.
631///
632/// Parameter `privateKey`: - the private key generated. You must retain publicKey if you wish to use it after your block returns.
633///
634/// Parameter `error`: - Any errors returned. You must retain error if you wish to use it after your block returns.
635///
636/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeygeneratepairblock?language=objc)
637#[cfg(all(feature = "SecBase", feature = "block2"))]
638pub type SecKeyGeneratePairBlock =
639 *mut block2::DynBlock<dyn Fn(NonNull<SecKey>, NonNull<SecKey>, NonNull<CFError>)>;
640
641#[cfg(feature = "SecBase")]
642impl SecKey {
643 /// Derives a symmetric key from a password.
644 ///
645 ///
646 /// Parameter `password`: The password from which the keyis to be derived.
647 ///
648 /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
649 ///
650 /// Parameter `error`: If the call fails this will contain the error code.
651 ///
652 ///
653 /// In order to derive a key the parameters dictionary must contain at least contain the following keys:
654 /// kSecAttrSalt - a CFData for the salt value for mixing in the pseudo-random rounds.
655 /// kSecAttrPRF - the algorithm to use for the pseudo-random-function.
656 /// If 0, this defaults to kSecAttrPRFHmacAlgSHA1. Possible values are:
657 ///
658 /// kSecAttrPRFHmacAlgSHA1
659 /// kSecAttrPRFHmacAlgSHA224
660 /// kSecAttrPRFHmacAlgSHA256
661 /// kSecAttrPRFHmacAlgSHA384
662 /// kSecAttrPRFHmacAlgSHA512
663 ///
664 /// kSecAttrRounds - the number of rounds to call the pseudo random function.
665 /// If 0, a count will be computed to average 1/10 of a second.
666 /// kSecAttrKeySizeInBits with a value being a CFNumberRef
667 /// containing the requested key size in bits. Example sizes for RSA keys are:
668 /// 512, 768, 1024, 2048.
669 ///
670 ///
671 /// Returns: On success a SecKeyRef is returned. On failure this result is NULL and the
672 /// error parameter contains the reason.
673 ///
674 /// # Safety
675 ///
676 /// - `parameters` generics must be of the correct type.
677 /// - `error` must be a valid pointer or null.
678 #[doc(alias = "SecKeyDeriveFromPassword")]
679 #[cfg(feature = "SecBase")]
680 #[deprecated = "No longer supported"]
681 #[inline]
682 pub unsafe fn derive_from_password(
683 password: &CFString,
684 parameters: &CFDictionary,
685 error: *mut *mut CFError,
686 ) -> Option<CFRetained<SecKey>> {
687 extern "C-unwind" {
688 fn SecKeyDeriveFromPassword(
689 password: &CFString,
690 parameters: &CFDictionary,
691 error: *mut *mut CFError,
692 ) -> Option<NonNull<SecKey>>;
693 }
694 let ret = unsafe { SecKeyDeriveFromPassword(password, parameters, error) };
695 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
696 }
697
698 /// Wraps a symmetric key with a symmetric key.
699 ///
700 ///
701 /// Parameter `keyToWrap`: The key which is to be wrapped.
702 ///
703 /// Parameter `wrappingKey`: The key wrapping key.
704 ///
705 /// Parameter `parameters`: The parameter list to use for wrapping the key.
706 ///
707 /// Parameter `error`: If the call fails this will contain the error code.
708 ///
709 ///
710 /// Returns: On success a CFDataRef is returned. On failure this result is NULL and the
711 /// error parameter contains the reason.
712 ///
713 ///
714 /// In order to wrap a key the parameters dictionary may contain the following key:
715 /// kSecSalt - a CFData for the salt value for the encrypt.
716 ///
717 /// # Safety
718 ///
719 /// - `parameters` generics must be of the correct type.
720 /// - `error` must be a valid pointer or null.
721 #[doc(alias = "SecKeyWrapSymmetric")]
722 #[cfg(feature = "SecBase")]
723 #[deprecated = "No longer supported"]
724 #[inline]
725 pub unsafe fn wrap_symmetric(
726 &self,
727 wrapping_key: &SecKey,
728 parameters: &CFDictionary,
729 error: *mut *mut CFError,
730 ) -> Option<CFRetained<CFData>> {
731 extern "C-unwind" {
732 fn SecKeyWrapSymmetric(
733 key_to_wrap: &SecKey,
734 wrapping_key: &SecKey,
735 parameters: &CFDictionary,
736 error: *mut *mut CFError,
737 ) -> Option<NonNull<CFData>>;
738 }
739 let ret = unsafe { SecKeyWrapSymmetric(self, wrapping_key, parameters, error) };
740 ret.map(|ret| unsafe { CFRetained::retain(ret) })
741 }
742
743 /// Unwrap a wrapped symmetric key.
744 ///
745 ///
746 /// Parameter `keyToUnwrap`: The wrapped key to unwrap.
747 ///
748 /// Parameter `unwrappingKey`: The key unwrapping key.
749 ///
750 /// Parameter `parameters`: The parameter list to use for unwrapping the key.
751 ///
752 /// Parameter `error`: If the call fails this will contain the error code.
753 ///
754 ///
755 /// Returns: On success a SecKeyRef is returned. On failure this result is NULL and the
756 /// error parameter contains the reason.
757 ///
758 ///
759 /// In order to unwrap a key the parameters dictionary may contain the following key:
760 /// kSecSalt - a CFData for the salt value for the decrypt.
761 ///
762 /// # Safety
763 ///
764 /// - `key_to_unwrap` must be a valid pointer.
765 /// - `parameters` generics must be of the correct type.
766 /// - `error` must be a valid pointer or null.
767 #[doc(alias = "SecKeyUnwrapSymmetric")]
768 #[cfg(feature = "SecBase")]
769 #[deprecated = "No longer supported"]
770 #[inline]
771 pub unsafe fn unwrap_symmetric(
772 key_to_unwrap: NonNull<*const CFData>,
773 unwrapping_key: &SecKey,
774 parameters: &CFDictionary,
775 error: *mut *mut CFError,
776 ) -> Option<CFRetained<SecKey>> {
777 extern "C-unwind" {
778 fn SecKeyUnwrapSymmetric(
779 key_to_unwrap: NonNull<*const CFData>,
780 unwrapping_key: &SecKey,
781 parameters: &CFDictionary,
782 error: *mut *mut CFError,
783 ) -> Option<NonNull<SecKey>>;
784 }
785 let ret =
786 unsafe { SecKeyUnwrapSymmetric(key_to_unwrap, unwrapping_key, parameters, error) };
787 ret.map(|ret| unsafe { CFRetained::retain(ret) })
788 }
789
790 /// Generate a private/public keypair.
791 ///
792 /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
793 /// See the discussion sections below for a complete overview of options.
794 ///
795 /// Parameter `publicKey`: On return, a SecKeyRef reference to the public key.
796 ///
797 /// Parameter `privateKey`: On return, a SecKeyRef reference to the private key.
798 ///
799 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
800 ///
801 ///
802 /// In order to generate a keypair the parameters dictionary must
803 /// at least contain the following keys:
804 ///
805 /// kSecAttrKeyType with a value of kSecAttrKeyTypeRSA or any other
806 /// kSecAttrKeyType defined in SecItem.h
807 /// kSecAttrKeySizeInBits with a value being a CFNumberRef containing
808 /// the requested key size in bits. Example sizes for RSA keys are:
809 /// 512, 768, 1024, 2048.
810 ///
811 /// The values below may be set either in the top-level dictionary or in a
812 /// dictionary that is the value of the kSecPrivateKeyAttrs or
813 /// kSecPublicKeyAttrs key in the top-level dictionary. Setting these
814 /// attributes explicitly will override the defaults below. See SecItem.h
815 /// for detailed information on these attributes including the types of
816 /// the values.
817 ///
818 /// kSecAttrLabel default NULL
819 /// kSecUseKeychain default NULL, which specifies the default keychain
820 /// kSecAttrIsPermanent default false
821 /// if this key is present and has a Boolean value of true, the key or
822 /// key pair will be added to the keychain.
823 /// kSecAttrTokenID default NULL
824 /// The CFStringRef ID of the token to generate the key or keypair on. This
825 /// attribute can contain CFStringRef and can be present only in the top-level
826 /// parameters dictionary.
827 /// kSecAttrApplicationTag default NULL
828 /// kSecAttrEffectiveKeySize default NULL same as kSecAttrKeySizeInBits
829 /// kSecAttrCanEncrypt default false for private keys, true for public keys
830 /// kSecAttrCanDecrypt default true for private keys, false for public keys
831 /// kSecAttrCanDerive default true
832 /// kSecAttrCanSign default true for private keys, false for public keys
833 /// kSecAttrCanVerify default false for private keys, true for public keys
834 /// kSecAttrCanWrap default false for private keys, true for public keys
835 /// kSecAttrCanUnwrap default true for private keys, false for public keys
836 ///
837 /// NOTE: The function always saves keys in the keychain on macOS and as such attribute
838 /// kSecAttrIsPermanent is ignored. The function respects attribute kSecAttrIsPermanent
839 /// on iOS, tvOS and watchOS.
840 /// It is recommended to use SecKeyCreateRandomKey() which respects kSecAttrIsPermanent
841 /// on all platforms.
842 ///
843 /// # Safety
844 ///
845 /// - `parameters` generics must be of the correct type.
846 /// - `public_key` must be a valid pointer or null.
847 /// - `private_key` must be a valid pointer or null.
848 #[doc(alias = "SecKeyGeneratePair")]
849 #[cfg(feature = "SecBase")]
850 #[deprecated = "Use SecKeyCreateRandomKey"]
851 #[inline]
852 pub unsafe fn generate_pair(
853 parameters: &CFDictionary,
854 public_key: *mut *mut SecKey,
855 private_key: *mut *mut SecKey,
856 ) -> OSStatus {
857 extern "C-unwind" {
858 fn SecKeyGeneratePair(
859 parameters: &CFDictionary,
860 public_key: *mut *mut SecKey,
861 private_key: *mut *mut SecKey,
862 ) -> OSStatus;
863 }
864 unsafe { SecKeyGeneratePair(parameters, public_key, private_key) }
865 }
866
867 /// Generates a new public/private key pair.
868 ///
869 /// Parameter `parameters`: A dictionary containing one or more key-value pairs.
870 /// See the discussion sections below for a complete overview of options.
871 ///
872 /// Parameter `error`: On error, will be populated with an error object describing the failure.
873 /// See "Security Error Codes" (SecBase.h).
874 ///
875 /// Returns: Newly generated private key. To get associated public key, use SecKeyCopyPublicKey().
876 ///
877 /// In order to generate a keypair the parameters dictionary must
878 /// at least contain the following keys:
879 ///
880 /// kSecAttrKeyType with a value being kSecAttrKeyTypeRSA or any other
881 /// kSecAttrKeyType defined in SecItem.h
882 /// kSecAttrKeySizeInBits with a value being a CFNumberRef or CFStringRef
883 /// containing the requested key size in bits. Example sizes for RSA
884 /// keys are: 512, 768, 1024, 2048.
885 ///
886 /// The values below may be set either in the top-level dictionary or in a
887 /// dictionary that is the value of the kSecPrivateKeyAttrs or
888 /// kSecPublicKeyAttrs key in the top-level dictionary. Setting these
889 /// attributes explicitly will override the defaults below. See SecItem.h
890 /// for detailed information on these attributes including the types of
891 /// the values.
892 ///
893 /// kSecAttrLabel default NULL
894 /// kSecAttrIsPermanent if this key is present and has a Boolean value of true,
895 /// the key or key pair will be added to the default keychain.
896 /// kSecAttrTokenID if this key should be generated on specified token. This
897 /// attribute can contain CFStringRef and can be present only in the top-level
898 /// parameters dictionary.
899 /// kSecAttrApplicationTag default NULL
900 /// kSecAttrEffectiveKeySize default NULL same as kSecAttrKeySizeInBits
901 /// kSecAttrCanEncrypt default false for private keys, true for public keys
902 /// kSecAttrCanDecrypt default true for private keys, false for public keys
903 /// kSecAttrCanDerive default true
904 /// kSecAttrCanSign default true for private keys, false for public keys
905 /// kSecAttrCanVerify default false for private keys, true for public keys
906 /// kSecAttrCanWrap default false for private keys, true for public keys
907 /// kSecAttrCanUnwrap default true for private keys, false for public keys
908 ///
909 /// # Safety
910 ///
911 /// - `parameters` generics must be of the correct type.
912 /// - `error` must be a valid pointer or null.
913 #[doc(alias = "SecKeyCreateRandomKey")]
914 #[cfg(feature = "SecBase")]
915 #[inline]
916 pub unsafe fn new_random_key(
917 parameters: &CFDictionary,
918 error: *mut *mut CFError,
919 ) -> Option<CFRetained<SecKey>> {
920 extern "C-unwind" {
921 fn SecKeyCreateRandomKey(
922 parameters: &CFDictionary,
923 error: *mut *mut CFError,
924 ) -> Option<NonNull<SecKey>>;
925 }
926 let ret = unsafe { SecKeyCreateRandomKey(parameters, error) };
927 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
928 }
929
930 /// Create a SecKey from a well-defined external representation.
931 ///
932 /// Parameter `keyData`: CFData representing the key. The format of the data depends on the type of key being created.
933 ///
934 /// Parameter `attributes`: Dictionary containing attributes describing the key to be imported. The keys in this dictionary
935 /// are kSecAttr* constants from SecItem.h. Mandatory attributes are:
936 /// kSecAttrKeyType
937 /// kSecAttrKeyClass
938 ///
939 /// Parameter `error`: On error, will be populated with an error object describing the failure.
940 /// See "Security Error Codes" (SecBase.h).
941 ///
942 /// Returns: A SecKey object representing the key, or NULL on failure.
943 ///
944 /// This function does not add keys to any keychain, but the SecKey object it returns can be added
945 /// to keychain using the SecItemAdd function.
946 /// The requested data format depend on the type of key (kSecAttrKeyType) being created:
947 /// kSecAttrKeyTypeRSA PKCS#1 format, public key can be also in x509 public key format
948 /// kSecAttrKeyTypeECSECPrimeRandom ANSI X9.63 format (04 || X || Y [ || K])
949 ///
950 /// # Safety
951 ///
952 /// - `attributes` generics must be of the correct type.
953 /// - `error` must be a valid pointer or null.
954 #[doc(alias = "SecKeyCreateWithData")]
955 #[cfg(feature = "SecBase")]
956 #[inline]
957 pub unsafe fn with_data(
958 key_data: &CFData,
959 attributes: &CFDictionary,
960 error: *mut *mut CFError,
961 ) -> Option<CFRetained<SecKey>> {
962 extern "C-unwind" {
963 fn SecKeyCreateWithData(
964 key_data: &CFData,
965 attributes: &CFDictionary,
966 error: *mut *mut CFError,
967 ) -> Option<NonNull<SecKey>>;
968 }
969 let ret = unsafe { SecKeyCreateWithData(key_data, attributes, error) };
970 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
971 }
972
973 /// Returns block length of the key in bytes.
974 ///
975 /// Parameter `key`: The key for which the block length is requested.
976 ///
977 /// Returns: The block length of the key in bytes.
978 ///
979 /// If for example key is an RSA key the value returned by
980 /// this function is the size of the modulus.
981 #[doc(alias = "SecKeyGetBlockSize")]
982 #[cfg(feature = "SecBase")]
983 #[inline]
984 pub unsafe fn block_size(&self) -> usize {
985 extern "C-unwind" {
986 fn SecKeyGetBlockSize(key: &SecKey) -> usize;
987 }
988 unsafe { SecKeyGetBlockSize(self) }
989 }
990
991 /// Create an external representation for the given key suitable for the key's type.
992 ///
993 /// Parameter `key`: The key to be exported.
994 ///
995 /// Parameter `error`: On error, will be populated with an error object describing the failure.
996 /// See "Security Error Codes" (SecBase.h).
997 ///
998 /// Returns: A CFData representing the key in a format suitable for that key type.
999 ///
1000 /// This function may fail if the key is not exportable (e.g., bound to a smart card or Secure Enclave).
1001 /// The format in which the key will be exported depends on the type of key:
1002 /// kSecAttrKeyTypeRSA PKCS#1 format
1003 /// kSecAttrKeyTypeECSECPrimeRandom ANSI X9.63 format (04 || X || Y [ || K])
1004 ///
1005 /// # Safety
1006 ///
1007 /// `error` must be a valid pointer or null.
1008 #[doc(alias = "SecKeyCopyExternalRepresentation")]
1009 #[cfg(feature = "SecBase")]
1010 #[inline]
1011 pub unsafe fn external_representation(
1012 &self,
1013 error: *mut *mut CFError,
1014 ) -> Option<CFRetained<CFData>> {
1015 extern "C-unwind" {
1016 fn SecKeyCopyExternalRepresentation(
1017 key: &SecKey,
1018 error: *mut *mut CFError,
1019 ) -> Option<NonNull<CFData>>;
1020 }
1021 let ret = unsafe { SecKeyCopyExternalRepresentation(self, error) };
1022 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1023 }
1024
1025 /// Retrieve keychain attributes of a key.
1026 ///
1027 /// Parameter `key`: The key whose attributes are to be retrieved.
1028 ///
1029 /// Returns: Dictionary containing attributes of the key. The keys that populate this dictionary are defined
1030 /// and discussed in SecItem.h.
1031 ///
1032 /// The attributes provided by this function are:
1033 /// kSecAttrCanEncrypt
1034 /// kSecAttrCanDecrypt
1035 /// kSecAttrCanDerive
1036 /// kSecAttrCanSign
1037 /// kSecAttrCanVerify
1038 /// kSecAttrKeyClass
1039 /// kSecAttrKeyType
1040 /// kSecAttrKeySizeInBits
1041 /// kSecAttrTokenID
1042 /// kSecAttrApplicationLabel
1043 /// The set of values is not fixed. Future versions may return more values in this dictionary.
1044 #[doc(alias = "SecKeyCopyAttributes")]
1045 #[cfg(feature = "SecBase")]
1046 #[inline]
1047 pub unsafe fn attributes(&self) -> Option<CFRetained<CFDictionary>> {
1048 extern "C-unwind" {
1049 fn SecKeyCopyAttributes(key: &SecKey) -> Option<NonNull<CFDictionary>>;
1050 }
1051 let ret = unsafe { SecKeyCopyAttributes(self) };
1052 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1053 }
1054
1055 /// Retrieve the public key from a key pair or private key.
1056 ///
1057 /// Parameter `key`: The key from which to retrieve a public key.
1058 ///
1059 /// Returns: The public key or NULL if public key is not available for specified key.
1060 ///
1061 /// Fails if key does not contain a public key or no public key can be computed from it.
1062 #[doc(alias = "SecKeyCopyPublicKey")]
1063 #[cfg(feature = "SecBase")]
1064 #[inline]
1065 pub unsafe fn public_key(&self) -> Option<CFRetained<SecKey>> {
1066 extern "C-unwind" {
1067 fn SecKeyCopyPublicKey(key: &SecKey) -> Option<NonNull<SecKey>>;
1068 }
1069 let ret = unsafe { SecKeyCopyPublicKey(self) };
1070 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1071 }
1072}
1073
1074/// Available algorithms for performing cryptographic operations with SecKey object. String representation
1075/// of constant can be used for logging or debugging purposes, because they contain human readable names of the algorithm.
1076///
1077///
1078/// Raw RSA sign/verify operation, size of input data must be the same as value returned by SecKeyGetBlockSize().
1079///
1080///
1081/// RSA sign/verify operation, assumes that input data is digest and OID and digest algorithm as specified in PKCS# v1.5.
1082/// This algorithm is typically not used directly, instead use algorithm with specified digest, like
1083/// kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA256.
1084///
1085///
1086/// RSA signature with PKCS#1 padding, input data must be SHA-1 generated digest.
1087///
1088///
1089/// RSA signature with PKCS#1 padding, input data must be SHA-224 generated digest.
1090///
1091///
1092/// RSA signature with PKCS#1 padding, input data must be SHA-256 generated digest.
1093///
1094///
1095/// RSA signature with PKCS#1 padding, input data must be SHA-384 generated digest.
1096///
1097///
1098/// RSA signature with PKCS#1 padding, input data must be SHA-512 generated digest.
1099///
1100///
1101/// RSA signature with PKCS#1 padding, SHA-1 digest is generated by called function automatically from input data of any size.
1102///
1103///
1104/// RSA signature with PKCS#1 padding, SHA-224 digest is generated by called function automatically from input data of any size.
1105///
1106///
1107/// RSA signature with PKCS#1 padding, SHA-256 digest is generated by called function automatically from input data of any size.
1108///
1109///
1110/// RSA signature with PKCS#1 padding, SHA-384 digest is generated by called function automatically from input data of any size.
1111///
1112///
1113/// RSA signature with PKCS#1 padding, SHA-512 digest is generated by called function automatically from input data of any size.
1114///
1115///
1116/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-1 generated digest.
1117/// PSS padding is calculated using MGF1 with SHA1 and saltLength parameter is set to 20 (SHA-1 output size).
1118///
1119///
1120/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-224 generated digest.
1121/// PSS padding is calculated using MGF1 with SHA224 and saltLength parameter is set to 28 (SHA-224 output size).
1122///
1123///
1124/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-256 generated digest.
1125/// PSS padding is calculated using MGF1 with SHA256 and saltLength parameter is set to 32 (SHA-256 output size).
1126///
1127///
1128/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-384 generated digest.
1129/// PSS padding is calculated using MGF1 with SHA384 and saltLength parameter is set to 48 (SHA-384 output size).
1130///
1131///
1132/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, input data must be SHA-512 generated digest.
1133/// PSS padding is calculated using MGF1 with SHA512 and saltLength parameter is set to 64 (SHA-512 output size).
1134///
1135///
1136/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-1 digest is generated by called function automatically from input data of any size.
1137/// PSS padding is calculated using MGF1 with SHA1 and saltLength parameter is set to 20 (SHA-1 output size).
1138///
1139///
1140/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-224 digest is generated by called function automatically from input data of any size.
1141/// PSS padding is calculated using MGF1 with SHA224 and saltLength parameter is set to 28 (SHA-224 output size).
1142///
1143///
1144/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-256 digest is generated by called function automatically from input data of any size.
1145/// PSS padding is calculated using MGF1 with SHA256 and saltLength parameter is set to 32 (SHA-256 output size).
1146///
1147///
1148/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-384 digest is generated by called function automatically from input data of any size.
1149/// PSS padding is calculated using MGF1 with SHA384 and saltLength parameter is set to 48 (SHA-384 output size).
1150///
1151///
1152/// RSA signature with RSASSA-PSS padding according to PKCS#1 v2.1, SHA-512 digest is generated by called function automatically from input data of any size.
1153/// PSS padding is calculated using MGF1 with SHA512 and saltLength parameter is set to 64 (SHA-512 output size).
1154///
1155///
1156/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest generated by some hash functions.
1157///
1158///
1159/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA1 algorithm.
1160///
1161///
1162/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA224 algorithm.
1163///
1164///
1165/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA256 algorithm.
1166///
1167///
1168/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA384 algorithm.
1169///
1170///
1171/// ECDSA algorithm, signature is in DER x9.62 encoding, input data must be message digest created by SHA512 algorithm.
1172///
1173///
1174/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-1 digest is generated by called function automatically from input data of any size.
1175///
1176///
1177/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-224 digest is generated by called function automatically from input data of any size.
1178///
1179///
1180/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-256 digest is generated by called function automatically from input data of any size.
1181///
1182///
1183/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-384 digest is generated by called function automatically from input data of any size.
1184///
1185///
1186/// ECDSA algorithm, signature is in DER x9.62 encoding, SHA-512 digest is generated by called function automatically from input data of any size.
1187///
1188///
1189/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest generated by some hash functions.
1190///
1191///
1192/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA1 algorithm.
1193///
1194///
1195/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA224 algorithm.
1196///
1197///
1198/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA256 algorithm.
1199///
1200///
1201/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA384 algorithm.
1202///
1203///
1204/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest created by SHA512 algorithm.
1205///
1206///
1207/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-1 digest is generated by called function automatically from input data of any size.
1208///
1209///
1210/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-224 digest is generated by called function automatically from input data of any size.
1211///
1212///
1213/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-256 digest is generated by called function automatically from input data of any size.
1214///
1215///
1216/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-384 digest is generated by called function automatically from input data of any size.
1217///
1218///
1219/// ECDSA algorithm, signature is concatenated r and s, big endian, SHA-512 digest is generated by called function automatically from input data of any size.
1220///
1221///
1222/// ECDSA algorithm, signature is concatenated r and s, big endian, input data must be message digest generated by some hash function.
1223/// This is deprecated algorithm, replaced by kSecKeyAlgorithmECDSASignatureDigestRFC4754
1224///
1225///
1226/// Raw RSA encryption or decryption, size of data must match RSA key modulus size. Note that direct
1227/// use of this algorithm without padding is cryptographically very weak, it is important to always introduce
1228/// some kind of padding. Input data size must be less or equal to the key block size and returned block has always
1229/// the same size as block size, as returned by SecKeyGetBlockSize().
1230///
1231///
1232/// RSA encryption or decryption, data is padded using PKCS#1 padding scheme. This algorithm should be used only for
1233/// backward compatibility with existing protocols and data. New implementations should choose cryptographically
1234/// stronger algorithm instead (see kSecKeyAlgorithmRSAEncryptionOAEP). Input data must be at most
1235/// "key block size - 11" bytes long and returned block has always the same size as block size, as returned
1236/// by SecKeyGetBlockSize().
1237///
1238///
1239/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA1. Input data must be at most
1240/// "key block size - 42" bytes long and returned block has always the same size as block size, as returned
1241/// by SecKeyGetBlockSize(). Use kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM to be able to encrypt and decrypt arbitrary long data.
1242///
1243///
1244/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA224. Input data must be at most
1245/// "key block size - 58" bytes long and returned block has always the same size as block size, as returned
1246/// by SecKeyGetBlockSize(). Use kSecKeyAlgorithmRSAEncryptionOAEPSHA224AESGCM to be able to encrypt and decrypt arbitrary long data.
1247///
1248///
1249/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA256. Input data must be at most
1250/// "key block size - 66" bytes long and returned block has always the same size as block size, as returned
1251/// by SecKeyGetBlockSize(). Use kSecKeyAlgorithmRSAEncryptionOAEPSHA256AESGCM to be able to encrypt and decrypt arbitrary long data.
1252///
1253///
1254/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA384. Input data must be at most
1255/// "key block size - 98" bytes long and returned block has always the same size as block size, as returned
1256/// by SecKeyGetBlockSize(). Use kSecKeyAlgorithmRSAEncryptionOAEPSHA384AESGCM to be able to encrypt and decrypt arbitrary long data.
1257///
1258///
1259/// RSA encryption or decryption, data is padded using OAEP padding scheme internally using SHA512. Input data must be at most
1260/// "key block size - 130" bytes long and returned block has always the same size as block size, as returned
1261/// by SecKeyGetBlockSize(). Use kSecKeyAlgorithmRSAEncryptionOAEPSHA512AESGCM to be able to encrypt and decrypt arbitrary long data.
1262///
1263///
1264/// Randomly generated AES session key is encrypted by RSA with OAEP padding. User data are encrypted using session key in GCM
1265/// mode with all-zero 16 bytes long IV (initialization vector). Finally 16 byte AES-GCM tag is appended to ciphertext.
1266/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used. Raw public key data is used
1267/// as authentication data for AES-GCM encryption.
1268///
1269///
1270/// Randomly generated AES session key is encrypted by RSA with OAEP padding. User data are encrypted using session key in GCM
1271/// mode with all-zero 16 bytes long IV (initialization vector). Finally 16 byte AES-GCM tag is appended to ciphertext.
1272/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used. Raw public key data is used
1273/// as authentication data for AES-GCM encryption.
1274///
1275///
1276/// Randomly generated AES session key is encrypted by RSA with OAEP padding. User data are encrypted using session key in GCM
1277/// mode with all-zero 16 bytes long IV (initialization vector). Finally 16 byte AES-GCM tag is appended to ciphertext.
1278/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used. Raw public key data is used
1279/// as authentication data for AES-GCM encryption.
1280///
1281///
1282/// Randomly generated AES session key is encrypted by RSA with OAEP padding. User data are encrypted using session key in GCM
1283/// mode with all-zero 16 bytes long IV (initialization vector). Finally 16 byte AES-GCM tag is appended to ciphertext.
1284/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used. Raw public key data is used
1285/// as authentication data for AES-GCM encryption.
1286///
1287///
1288/// Randomly generated AES session key is encrypted by RSA with OAEP padding. User data are encrypted using session key in GCM
1289/// mode with all-zero 16 bytes long IV (initialization vector). Finally 16 byte AES-GCM tag is appended to ciphertext.
1290/// 256bit AES key is used if RSA key is 4096bit or bigger, otherwise 128bit AES key is used. Raw public key data is used
1291/// as authentication data for AES-GCM encryption.
1292///
1293///
1294/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM in new code.
1295/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA1. AES Key size
1296/// is 128bit for EC keys
1297/// <
1298/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1299/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1300///
1301///
1302/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM in new code.
1303/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224. AES Key size
1304/// is 128bit for EC keys
1305/// <
1306/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1307/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1308///
1309///
1310/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM in new code.
1311/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256. AES Key size
1312/// is 128bit for EC keys
1313/// <
1314/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1315/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1316///
1317///
1318/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM in new code.
1319/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384. AES Key size
1320/// is 128bit for EC keys
1321/// <
1322/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1323/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1324///
1325///
1326/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM in new code.
1327/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512. AES Key size
1328/// is 128bit for EC keys
1329/// <
1330/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1331/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1332///
1333///
1334/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM in new code.
1335/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA1. AES Key size
1336/// is 128bit for EC keys
1337/// <
1338/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1339/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1340///
1341///
1342/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA224AESGCM in new code.
1343/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224. AES Key size
1344/// is 128bit for EC keys
1345/// <
1346/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1347/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1348///
1349///
1350/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM in new code.
1351/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256. AES Key size
1352/// is 128bit for EC keys
1353/// <
1354/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1355/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1356///
1357///
1358/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA384AESGCM in new code.
1359/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384. AES Key size
1360/// is 128bit for EC keys
1361/// <
1362/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1363/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1364///
1365///
1366/// Legacy ECIES encryption or decryption, use kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA512AESGCM in new code.
1367/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512. AES Key size
1368/// is 128bit for EC keys
1369/// <
1370/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1371/// AES-GCM uses 16 bytes long TAG and all-zero 16 byte long IV (initialization vector).
1372///
1373///
1374/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1375/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224. AES Key size
1376/// is 128bit for EC keys
1377/// <
1378/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1379/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1380/// of KDF output.
1381///
1382///
1383/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1384/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256. AES Key size
1385/// is 128bit for EC keys
1386/// <
1387/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1388/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1389/// of KDF output.
1390///
1391///
1392/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1393/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384. AES Key size
1394/// is 128bit for EC keys
1395/// <
1396/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1397/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1398/// of KDF output.
1399///
1400///
1401/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1402/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512. AES Key size
1403/// is 128bit for EC keys
1404/// <
1405/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1406/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1407/// of KDF output.
1408///
1409///
1410/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1411/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224. AES Key size
1412/// is 128bit for EC keys
1413/// <
1414/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1415/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1416/// of KDF output.
1417///
1418///
1419/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1420/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256. AES Key size
1421/// is 128bit for EC keys
1422/// <
1423/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1424/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1425/// of KDF output.
1426///
1427///
1428/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1429/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384. AES Key size
1430/// is 128bit for EC keys
1431/// <
1432/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1433/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1434/// of KDF output.
1435///
1436///
1437/// ECIES encryption or decryption. This algorithm does not limit the size of the message to be encrypted or decrypted.
1438/// Encryption is done using AES-GCM with key negotiated by kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512. AES Key size
1439/// is 128bit for EC keys
1440/// <
1441/// =256bit and 256bit for bigger EC keys. Ephemeral public key data is used as sharedInfo for KDF.
1442/// AES-GCM uses 16 bytes long TAG, AES key is first half of KDF output and 16 byte long IV (initialization vector) is second half
1443/// of KDF output.
1444///
1445///
1446/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys.
1447/// This algorithm does not accept any parameters, length of output raw shared secret is given by the length of the key.
1448///
1449///
1450/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1451/// and apply ANSI X9.63 KDF with SHA1 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1452/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1453///
1454///
1455/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1456/// and apply ANSI X9.63 KDF with SHA224 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1457/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1458///
1459///
1460/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1461/// and apply ANSI X9.63 KDF with SHA256 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1462/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1463///
1464///
1465/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1466/// and apply ANSI X9.63 KDF with SHA384 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1467/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1468///
1469///
1470/// Compute shared secret using ECDH cofactor algorithm, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1471/// and apply ANSI X9.63 KDF with SHA512 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1472/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1473///
1474///
1475/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys.
1476/// This algorithm does not accept any parameters, length of output raw shared secret is given by the length of the key.
1477///
1478///
1479/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1480/// and apply ANSI X9.63 KDF with SHA1 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1481/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1482///
1483///
1484/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1485/// and apply ANSI X9.63 KDF with SHA224 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1486/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1487///
1488///
1489/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1490/// and apply ANSI X9.63 KDF with SHA256 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1491/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1492///
1493///
1494/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1495/// and apply ANSI X9.63 KDF with SHA384 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1496/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1497///
1498///
1499/// Compute shared secret using ECDH algorithm without cofactor, suitable only for kSecAttrKeyTypeECSECPrimeRandom keys
1500/// and apply ANSI X9.63 KDF with SHA512 as hashing function. Requires kSecKeyKeyExchangeParameterRequestedSize and allows
1501/// kSecKeyKeyExchangeParameterSharedInfo parameters to be used.
1502///
1503/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeyalgorithm?language=objc)
1504// NS_TYPED_ENUM
1505pub type SecKeyAlgorithm = CFString;
1506
1507extern "C" {
1508 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignatureraw?language=objc)
1509 pub static kSecKeyAlgorithmRSASignatureRaw: &'static SecKeyAlgorithm;
1510}
1511
1512extern "C" {
1513 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15raw?language=objc)
1514 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15Raw: &'static SecKeyAlgorithm;
1515}
1516
1517extern "C" {
1518 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha1?language=objc)
1519 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA1: &'static SecKeyAlgorithm;
1520}
1521
1522extern "C" {
1523 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha224?language=objc)
1524 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA224: &'static SecKeyAlgorithm;
1525}
1526
1527extern "C" {
1528 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha256?language=objc)
1529 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA256: &'static SecKeyAlgorithm;
1530}
1531
1532extern "C" {
1533 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha384?language=objc)
1534 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA384: &'static SecKeyAlgorithm;
1535}
1536
1537extern "C" {
1538 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpkcs1v15sha512?language=objc)
1539 pub static kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA512: &'static SecKeyAlgorithm;
1540}
1541
1542extern "C" {
1543 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha1?language=objc)
1544 pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA1: &'static SecKeyAlgorithm;
1545}
1546
1547extern "C" {
1548 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha224?language=objc)
1549 pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA224: &'static SecKeyAlgorithm;
1550}
1551
1552extern "C" {
1553 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha256?language=objc)
1554 pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA256: &'static SecKeyAlgorithm;
1555}
1556
1557extern "C" {
1558 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha384?language=objc)
1559 pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA384: &'static SecKeyAlgorithm;
1560}
1561
1562extern "C" {
1563 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepkcs1v15sha512?language=objc)
1564 pub static kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512: &'static SecKeyAlgorithm;
1565}
1566
1567extern "C" {
1568 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha1?language=objc)
1569 pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA1: &'static SecKeyAlgorithm;
1570}
1571
1572extern "C" {
1573 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha224?language=objc)
1574 pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA224: &'static SecKeyAlgorithm;
1575}
1576
1577extern "C" {
1578 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha256?language=objc)
1579 pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA256: &'static SecKeyAlgorithm;
1580}
1581
1582extern "C" {
1583 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha384?language=objc)
1584 pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA384: &'static SecKeyAlgorithm;
1585}
1586
1587extern "C" {
1588 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturedigestpsssha512?language=objc)
1589 pub static kSecKeyAlgorithmRSASignatureDigestPSSSHA512: &'static SecKeyAlgorithm;
1590}
1591
1592extern "C" {
1593 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha1?language=objc)
1594 pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA1: &'static SecKeyAlgorithm;
1595}
1596
1597extern "C" {
1598 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha224?language=objc)
1599 pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA224: &'static SecKeyAlgorithm;
1600}
1601
1602extern "C" {
1603 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha256?language=objc)
1604 pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA256: &'static SecKeyAlgorithm;
1605}
1606
1607extern "C" {
1608 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha384?language=objc)
1609 pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA384: &'static SecKeyAlgorithm;
1610}
1611
1612extern "C" {
1613 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsasignaturemessagepsssha512?language=objc)
1614 pub static kSecKeyAlgorithmRSASignatureMessagePSSSHA512: &'static SecKeyAlgorithm;
1615}
1616
1617extern "C" {
1618 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962?language=objc)
1619 pub static kSecKeyAlgorithmECDSASignatureDigestX962: &'static SecKeyAlgorithm;
1620}
1621
1622extern "C" {
1623 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha1?language=objc)
1624 pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA1: &'static SecKeyAlgorithm;
1625}
1626
1627extern "C" {
1628 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha224?language=objc)
1629 pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA224: &'static SecKeyAlgorithm;
1630}
1631
1632extern "C" {
1633 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha256?language=objc)
1634 pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA256: &'static SecKeyAlgorithm;
1635}
1636
1637extern "C" {
1638 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha384?language=objc)
1639 pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA384: &'static SecKeyAlgorithm;
1640}
1641
1642extern "C" {
1643 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestx962sha512?language=objc)
1644 pub static kSecKeyAlgorithmECDSASignatureDigestX962SHA512: &'static SecKeyAlgorithm;
1645}
1646
1647extern "C" {
1648 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha1?language=objc)
1649 pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA1: &'static SecKeyAlgorithm;
1650}
1651
1652extern "C" {
1653 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha224?language=objc)
1654 pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA224: &'static SecKeyAlgorithm;
1655}
1656
1657extern "C" {
1658 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha256?language=objc)
1659 pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA256: &'static SecKeyAlgorithm;
1660}
1661
1662extern "C" {
1663 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha384?language=objc)
1664 pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA384: &'static SecKeyAlgorithm;
1665}
1666
1667extern "C" {
1668 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagex962sha512?language=objc)
1669 pub static kSecKeyAlgorithmECDSASignatureMessageX962SHA512: &'static SecKeyAlgorithm;
1670}
1671
1672extern "C" {
1673 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754?language=objc)
1674 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754: &'static SecKeyAlgorithm;
1675}
1676
1677extern "C" {
1678 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha1?language=objc)
1679 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA1: &'static SecKeyAlgorithm;
1680}
1681
1682extern "C" {
1683 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha224?language=objc)
1684 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA224: &'static SecKeyAlgorithm;
1685}
1686
1687extern "C" {
1688 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha256?language=objc)
1689 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA256: &'static SecKeyAlgorithm;
1690}
1691
1692extern "C" {
1693 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha384?language=objc)
1694 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA384: &'static SecKeyAlgorithm;
1695}
1696
1697extern "C" {
1698 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturedigestrfc4754sha512?language=objc)
1699 pub static kSecKeyAlgorithmECDSASignatureDigestRFC4754SHA512: &'static SecKeyAlgorithm;
1700}
1701
1702extern "C" {
1703 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha1?language=objc)
1704 pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA1: &'static SecKeyAlgorithm;
1705}
1706
1707extern "C" {
1708 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha224?language=objc)
1709 pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA224: &'static SecKeyAlgorithm;
1710}
1711
1712extern "C" {
1713 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha256?language=objc)
1714 pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA256: &'static SecKeyAlgorithm;
1715}
1716
1717extern "C" {
1718 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha384?language=objc)
1719 pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA384: &'static SecKeyAlgorithm;
1720}
1721
1722extern "C" {
1723 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturemessagerfc4754sha512?language=objc)
1724 pub static kSecKeyAlgorithmECDSASignatureMessageRFC4754SHA512: &'static SecKeyAlgorithm;
1725}
1726
1727extern "C" {
1728 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdsasignaturerfc4754?language=objc)
1729 #[deprecated]
1730 pub static kSecKeyAlgorithmECDSASignatureRFC4754: &'static SecKeyAlgorithm;
1731}
1732
1733extern "C" {
1734 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionraw?language=objc)
1735 pub static kSecKeyAlgorithmRSAEncryptionRaw: &'static SecKeyAlgorithm;
1736}
1737
1738extern "C" {
1739 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionpkcs1?language=objc)
1740 pub static kSecKeyAlgorithmRSAEncryptionPKCS1: &'static SecKeyAlgorithm;
1741}
1742
1743extern "C" {
1744 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha1?language=objc)
1745 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA1: &'static SecKeyAlgorithm;
1746}
1747
1748extern "C" {
1749 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha224?language=objc)
1750 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA224: &'static SecKeyAlgorithm;
1751}
1752
1753extern "C" {
1754 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha256?language=objc)
1755 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA256: &'static SecKeyAlgorithm;
1756}
1757
1758extern "C" {
1759 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha384?language=objc)
1760 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA384: &'static SecKeyAlgorithm;
1761}
1762
1763extern "C" {
1764 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha512?language=objc)
1765 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA512: &'static SecKeyAlgorithm;
1766}
1767
1768extern "C" {
1769 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha1aesgcm?language=objc)
1770 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA1AESGCM: &'static SecKeyAlgorithm;
1771}
1772
1773extern "C" {
1774 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha224aesgcm?language=objc)
1775 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA224AESGCM: &'static SecKeyAlgorithm;
1776}
1777
1778extern "C" {
1779 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha256aesgcm?language=objc)
1780 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA256AESGCM: &'static SecKeyAlgorithm;
1781}
1782
1783extern "C" {
1784 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha384aesgcm?language=objc)
1785 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA384AESGCM: &'static SecKeyAlgorithm;
1786}
1787
1788extern "C" {
1789 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmrsaencryptionoaepsha512aesgcm?language=objc)
1790 pub static kSecKeyAlgorithmRSAEncryptionOAEPSHA512AESGCM: &'static SecKeyAlgorithm;
1791}
1792
1793extern "C" {
1794 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha1aesgcm?language=objc)
1795 pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA1AESGCM: &'static SecKeyAlgorithm;
1796}
1797
1798extern "C" {
1799 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha224aesgcm?language=objc)
1800 pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA224AESGCM: &'static SecKeyAlgorithm;
1801}
1802
1803extern "C" {
1804 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha256aesgcm?language=objc)
1805 pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA256AESGCM: &'static SecKeyAlgorithm;
1806}
1807
1808extern "C" {
1809 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha384aesgcm?language=objc)
1810 pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA384AESGCM: &'static SecKeyAlgorithm;
1811}
1812
1813extern "C" {
1814 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardx963sha512aesgcm?language=objc)
1815 pub static kSecKeyAlgorithmECIESEncryptionStandardX963SHA512AESGCM: &'static SecKeyAlgorithm;
1816}
1817
1818extern "C" {
1819 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha1aesgcm?language=objc)
1820 pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA1AESGCM: &'static SecKeyAlgorithm;
1821}
1822
1823extern "C" {
1824 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha224aesgcm?language=objc)
1825 pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA224AESGCM: &'static SecKeyAlgorithm;
1826}
1827
1828extern "C" {
1829 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha256aesgcm?language=objc)
1830 pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM: &'static SecKeyAlgorithm;
1831}
1832
1833extern "C" {
1834 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha384aesgcm?language=objc)
1835 pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA384AESGCM: &'static SecKeyAlgorithm;
1836}
1837
1838extern "C" {
1839 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorx963sha512aesgcm?language=objc)
1840 pub static kSecKeyAlgorithmECIESEncryptionCofactorX963SHA512AESGCM: &'static SecKeyAlgorithm;
1841}
1842
1843extern "C" {
1844 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha224aesgcm?language=objc)
1845 pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA224AESGCM:
1846 &'static SecKeyAlgorithm;
1847}
1848
1849extern "C" {
1850 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha256aesgcm?language=objc)
1851 pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA256AESGCM:
1852 &'static SecKeyAlgorithm;
1853}
1854
1855extern "C" {
1856 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha384aesgcm?language=objc)
1857 pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA384AESGCM:
1858 &'static SecKeyAlgorithm;
1859}
1860
1861extern "C" {
1862 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptionstandardvariableivx963sha512aesgcm?language=objc)
1863 pub static kSecKeyAlgorithmECIESEncryptionStandardVariableIVX963SHA512AESGCM:
1864 &'static SecKeyAlgorithm;
1865}
1866
1867extern "C" {
1868 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha224aesgcm?language=objc)
1869 pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA224AESGCM:
1870 &'static SecKeyAlgorithm;
1871}
1872
1873extern "C" {
1874 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha256aesgcm?language=objc)
1875 pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM:
1876 &'static SecKeyAlgorithm;
1877}
1878
1879extern "C" {
1880 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha384aesgcm?language=objc)
1881 pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA384AESGCM:
1882 &'static SecKeyAlgorithm;
1883}
1884
1885extern "C" {
1886 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmeciesencryptioncofactorvariableivx963sha512aesgcm?language=objc)
1887 pub static kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA512AESGCM:
1888 &'static SecKeyAlgorithm;
1889}
1890
1891extern "C" {
1892 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandard?language=objc)
1893 pub static kSecKeyAlgorithmECDHKeyExchangeStandard: &'static SecKeyAlgorithm;
1894}
1895
1896extern "C" {
1897 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha1?language=objc)
1898 pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA1: &'static SecKeyAlgorithm;
1899}
1900
1901extern "C" {
1902 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha224?language=objc)
1903 pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA224: &'static SecKeyAlgorithm;
1904}
1905
1906extern "C" {
1907 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha256?language=objc)
1908 pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA256: &'static SecKeyAlgorithm;
1909}
1910
1911extern "C" {
1912 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha384?language=objc)
1913 pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA384: &'static SecKeyAlgorithm;
1914}
1915
1916extern "C" {
1917 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangestandardx963sha512?language=objc)
1918 pub static kSecKeyAlgorithmECDHKeyExchangeStandardX963SHA512: &'static SecKeyAlgorithm;
1919}
1920
1921extern "C" {
1922 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactor?language=objc)
1923 pub static kSecKeyAlgorithmECDHKeyExchangeCofactor: &'static SecKeyAlgorithm;
1924}
1925
1926extern "C" {
1927 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha1?language=objc)
1928 pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA1: &'static SecKeyAlgorithm;
1929}
1930
1931extern "C" {
1932 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha224?language=objc)
1933 pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA224: &'static SecKeyAlgorithm;
1934}
1935
1936extern "C" {
1937 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha256?language=objc)
1938 pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA256: &'static SecKeyAlgorithm;
1939}
1940
1941extern "C" {
1942 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha384?language=objc)
1943 pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA384: &'static SecKeyAlgorithm;
1944}
1945
1946extern "C" {
1947 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeyalgorithmecdhkeyexchangecofactorx963sha512?language=objc)
1948 pub static kSecKeyAlgorithmECDHKeyExchangeCofactorX963SHA512: &'static SecKeyAlgorithm;
1949}
1950
1951#[cfg(feature = "SecBase")]
1952impl SecKey {
1953 /// Given a private key and data to sign, generate a digital signature.
1954 ///
1955 /// Parameter `key`: Private key with which to sign.
1956 ///
1957 /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to generate signature with this key.
1958 ///
1959 /// Parameter `dataToSign`: The data to be signed, typically the digest of the actual data.
1960 ///
1961 /// Parameter `error`: On error, will be populated with an error object describing the failure.
1962 /// See "Security Error Codes" (SecBase.h).
1963 ///
1964 /// Returns: The signature over dataToSign represented as a CFData, or NULL on failure.
1965 ///
1966 /// Computes digital signature using specified key over input data. The operation algorithm
1967 /// further defines the exact format of input data, operation to be performed and output signature.
1968 ///
1969 /// # Safety
1970 ///
1971 /// `error` must be a valid pointer or null.
1972 #[doc(alias = "SecKeyCreateSignature")]
1973 #[cfg(feature = "SecBase")]
1974 #[inline]
1975 pub unsafe fn signature(
1976 &self,
1977 algorithm: &SecKeyAlgorithm,
1978 data_to_sign: &CFData,
1979 error: *mut *mut CFError,
1980 ) -> Option<CFRetained<CFData>> {
1981 extern "C-unwind" {
1982 fn SecKeyCreateSignature(
1983 key: &SecKey,
1984 algorithm: &SecKeyAlgorithm,
1985 data_to_sign: &CFData,
1986 error: *mut *mut CFError,
1987 ) -> Option<NonNull<CFData>>;
1988 }
1989 let ret = unsafe { SecKeyCreateSignature(self, algorithm, data_to_sign, error) };
1990 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1991 }
1992
1993 /// Given a public key, data which has been signed, and a signature, verify the signature.
1994 ///
1995 /// Parameter `key`: Public key with which to verify the signature.
1996 ///
1997 /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to verify signature with this key.
1998 ///
1999 /// Parameter `signedData`: The data over which sig is being verified, typically the digest of the actual data.
2000 ///
2001 /// Parameter `signature`: The signature to verify.
2002 ///
2003 /// Parameter `error`: On error, will be populated with an error object describing the failure.
2004 /// See "Security Error Codes" (SecBase.h).
2005 ///
2006 /// Returns: True if the signature was valid, False otherwise.
2007 ///
2008 /// Verifies digital signature operation using specified key and signed data. The operation algorithm
2009 /// further defines the exact format of input data, signature and operation to be performed.
2010 ///
2011 /// # Safety
2012 ///
2013 /// `error` must be a valid pointer or null.
2014 #[doc(alias = "SecKeyVerifySignature")]
2015 #[cfg(feature = "SecBase")]
2016 #[inline]
2017 pub unsafe fn verify_signature(
2018 &self,
2019 algorithm: &SecKeyAlgorithm,
2020 signed_data: &CFData,
2021 signature: &CFData,
2022 error: *mut *mut CFError,
2023 ) -> bool {
2024 extern "C-unwind" {
2025 fn SecKeyVerifySignature(
2026 key: &SecKey,
2027 algorithm: &SecKeyAlgorithm,
2028 signed_data: &CFData,
2029 signature: &CFData,
2030 error: *mut *mut CFError,
2031 ) -> Boolean;
2032 }
2033 let ret = unsafe { SecKeyVerifySignature(self, algorithm, signed_data, signature, error) };
2034 ret != 0
2035 }
2036
2037 /// Encrypt a block of plaintext.
2038 ///
2039 /// Parameter `key`: Public key with which to encrypt the data.
2040 ///
2041 /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform encryption with this key.
2042 ///
2043 /// Parameter `plaintext`: The data to encrypt. The length and format of the data must conform to chosen algorithm,
2044 /// typically be less or equal to the value returned by SecKeyGetBlockSize().
2045 ///
2046 /// Parameter `error`: On error, will be populated with an error object describing the failure.
2047 /// See "Security Error Codes" (SecBase.h).
2048 ///
2049 /// Returns: The ciphertext represented as a CFData, or NULL on failure.
2050 ///
2051 /// Encrypts plaintext data using specified key. The exact type of the operation including the format
2052 /// of input and output data is specified by encryption algorithm.
2053 ///
2054 /// # Safety
2055 ///
2056 /// `error` must be a valid pointer or null.
2057 #[doc(alias = "SecKeyCreateEncryptedData")]
2058 #[cfg(feature = "SecBase")]
2059 #[inline]
2060 pub unsafe fn encrypted_data(
2061 &self,
2062 algorithm: &SecKeyAlgorithm,
2063 plaintext: &CFData,
2064 error: *mut *mut CFError,
2065 ) -> Option<CFRetained<CFData>> {
2066 extern "C-unwind" {
2067 fn SecKeyCreateEncryptedData(
2068 key: &SecKey,
2069 algorithm: &SecKeyAlgorithm,
2070 plaintext: &CFData,
2071 error: *mut *mut CFError,
2072 ) -> Option<NonNull<CFData>>;
2073 }
2074 let ret = unsafe { SecKeyCreateEncryptedData(self, algorithm, plaintext, error) };
2075 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2076 }
2077
2078 /// Decrypt a block of ciphertext.
2079 ///
2080 /// Parameter `key`: Private key with which to decrypt the data.
2081 ///
2082 /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform decryption with this key.
2083 ///
2084 /// Parameter `ciphertext`: The data to decrypt. The length and format of the data must conform to chosen algorithm,
2085 /// typically be less or equal to the value returned by SecKeyGetBlockSize().
2086 ///
2087 /// Parameter `error`: On error, will be populated with an error object describing the failure.
2088 /// See "Security Error Codes" (SecBase.h).
2089 ///
2090 /// Returns: The plaintext represented as a CFData, or NULL on failure.
2091 ///
2092 /// Decrypts ciphertext data using specified key. The exact type of the operation including the format
2093 /// of input and output data is specified by decryption algorithm.
2094 ///
2095 /// # Safety
2096 ///
2097 /// `error` must be a valid pointer or null.
2098 #[doc(alias = "SecKeyCreateDecryptedData")]
2099 #[cfg(feature = "SecBase")]
2100 #[inline]
2101 pub unsafe fn decrypted_data(
2102 &self,
2103 algorithm: &SecKeyAlgorithm,
2104 ciphertext: &CFData,
2105 error: *mut *mut CFError,
2106 ) -> Option<CFRetained<CFData>> {
2107 extern "C-unwind" {
2108 fn SecKeyCreateDecryptedData(
2109 key: &SecKey,
2110 algorithm: &SecKeyAlgorithm,
2111 ciphertext: &CFData,
2112 error: *mut *mut CFError,
2113 ) -> Option<NonNull<CFData>>;
2114 }
2115 let ret = unsafe { SecKeyCreateDecryptedData(self, algorithm, ciphertext, error) };
2116 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2117 }
2118}
2119
2120/// for KDF (key derivation function).
2121///
2122/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeykeyexchangeparameter?language=objc)
2123// NS_TYPED_ENUM
2124pub type SecKeyKeyExchangeParameter = CFString;
2125
2126extern "C" {
2127 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyexchangeparameterrequestedsize?language=objc)
2128 pub static kSecKeyKeyExchangeParameterRequestedSize: &'static SecKeyKeyExchangeParameter;
2129}
2130
2131extern "C" {
2132 /// [Apple's documentation](https://developer.apple.com/documentation/security/kseckeykeyexchangeparametersharedinfo?language=objc)
2133 pub static kSecKeyKeyExchangeParameterSharedInfo: &'static SecKeyKeyExchangeParameter;
2134}
2135
2136#[cfg(feature = "SecBase")]
2137impl SecKey {
2138 /// Perform Diffie-Hellman style of key exchange operation, optionally with additional key-derivation steps.
2139 ///
2140 /// Parameter `algorithm`: One of SecKeyAlgorithm constants suitable to perform this operation.
2141 ///
2142 /// Parameter `publicKey`: Remote party's public key.
2143 ///
2144 /// Parameter `parameters`: Dictionary with parameters, see SecKeyKeyExchangeParameter constants. Used algorithm
2145 /// determines the set of required and optional parameters to be used.
2146 ///
2147 /// Parameter `error`: Pointer to an error object on failure.
2148 /// See "Security Error Codes" (SecBase.h).
2149 ///
2150 /// Returns: Result of key exchange operation as a CFDataRef, or NULL on failure.
2151 ///
2152 /// # Safety
2153 ///
2154 /// - `parameters` generics must be of the correct type.
2155 /// - `error` must be a valid pointer or null.
2156 #[doc(alias = "SecKeyCopyKeyExchangeResult")]
2157 #[cfg(feature = "SecBase")]
2158 #[inline]
2159 pub unsafe fn key_exchange_result(
2160 &self,
2161 algorithm: &SecKeyAlgorithm,
2162 public_key: &SecKey,
2163 parameters: &CFDictionary,
2164 error: *mut *mut CFError,
2165 ) -> Option<CFRetained<CFData>> {
2166 extern "C-unwind" {
2167 fn SecKeyCopyKeyExchangeResult(
2168 private_key: &SecKey,
2169 algorithm: &SecKeyAlgorithm,
2170 public_key: &SecKey,
2171 parameters: &CFDictionary,
2172 error: *mut *mut CFError,
2173 ) -> Option<NonNull<CFData>>;
2174 }
2175 let ret =
2176 unsafe { SecKeyCopyKeyExchangeResult(self, algorithm, public_key, parameters, error) };
2177 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2178 }
2179}
2180
2181/// Defines types of cryptographic operations available with SecKey instance.
2182///
2183///
2184/// Represents SecKeyCreateSignature()
2185///
2186///
2187/// Represents SecKeyVerifySignature()
2188///
2189///
2190/// Represents SecKeyCreateEncryptedData()
2191///
2192///
2193/// Represents SecKeyCreateDecryptedData()
2194///
2195///
2196/// Represents SecKeyCopyKeyExchangeResult()
2197///
2198/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeyoperationtype?language=objc)
2199// NS_ENUM
2200#[repr(transparent)]
2201#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
2202pub struct SecKeyOperationType(pub CFIndex);
2203impl SecKeyOperationType {
2204 #[doc(alias = "kSecKeyOperationTypeSign")]
2205 pub const Sign: Self = Self(0);
2206 #[doc(alias = "kSecKeyOperationTypeVerify")]
2207 pub const Verify: Self = Self(1);
2208 #[doc(alias = "kSecKeyOperationTypeEncrypt")]
2209 pub const Encrypt: Self = Self(2);
2210 #[doc(alias = "kSecKeyOperationTypeDecrypt")]
2211 pub const Decrypt: Self = Self(3);
2212 #[doc(alias = "kSecKeyOperationTypeKeyExchange")]
2213 pub const KeyExchange: Self = Self(4);
2214}
2215
2216#[cfg(feature = "objc2")]
2217unsafe impl Encode for SecKeyOperationType {
2218 const ENCODING: Encoding = CFIndex::ENCODING;
2219}
2220
2221#[cfg(feature = "objc2")]
2222unsafe impl RefEncode for SecKeyOperationType {
2223 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
2224}
2225
2226#[cfg(feature = "SecBase")]
2227impl SecKey {
2228 /// Checks whether key supports specified algorithm for specified operation.
2229 ///
2230 /// Parameter `key`: Key to query
2231 ///
2232 /// Parameter `operation`: Operation type for which the key is queried
2233 ///
2234 /// Parameter `algorithm`: Algorithm which is queried
2235 ///
2236 /// Returns: True if key supports specified algorithm for specified operation, False otherwise.
2237 #[doc(alias = "SecKeyIsAlgorithmSupported")]
2238 #[cfg(feature = "SecBase")]
2239 #[inline]
2240 pub unsafe fn is_algorithm_supported(
2241 &self,
2242 operation: SecKeyOperationType,
2243 algorithm: &SecKeyAlgorithm,
2244 ) -> bool {
2245 extern "C-unwind" {
2246 fn SecKeyIsAlgorithmSupported(
2247 key: &SecKey,
2248 operation: SecKeyOperationType,
2249 algorithm: &SecKeyAlgorithm,
2250 ) -> Boolean;
2251 }
2252 let ret = unsafe { SecKeyIsAlgorithmSupported(self, operation, algorithm) };
2253 ret != 0
2254 }
2255}
2256
2257extern "C-unwind" {
2258 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
2259 #[deprecated = "renamed to `SecKey::create_pair`"]
2260 pub fn SecKeyCreatePair(
2261 keychain_ref: Option<&SecKeychain>,
2262 algorithm: CSSM_ALGORITHMS,
2263 key_size_in_bits: uint32,
2264 context_handle: CSSM_CC_HANDLE,
2265 public_key_usage: CSSM_KEYUSE,
2266 public_key_attr: uint32,
2267 private_key_usage: CSSM_KEYUSE,
2268 private_key_attr: uint32,
2269 initial_access: Option<&SecAccess>,
2270 public_key: *mut *mut SecKey,
2271 private_key: *mut *mut SecKey,
2272 ) -> OSStatus;
2273}
2274
2275extern "C-unwind" {
2276 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
2277 #[deprecated = "renamed to `SecKey::generate`"]
2278 pub fn SecKeyGenerate(
2279 keychain_ref: Option<&SecKeychain>,
2280 algorithm: CSSM_ALGORITHMS,
2281 key_size_in_bits: uint32,
2282 context_handle: CSSM_CC_HANDLE,
2283 key_usage: CSSM_KEYUSE,
2284 key_attr: uint32,
2285 initial_access: Option<&SecAccess>,
2286 key_ref: *mut *mut SecKey,
2287 ) -> OSStatus;
2288}
2289
2290extern "C-unwind" {
2291 #[cfg(all(
2292 feature = "SecAsn1Types",
2293 feature = "SecBase",
2294 feature = "cssmconfig",
2295 feature = "cssmtype"
2296 ))]
2297 #[deprecated = "renamed to `SecKey::cssm_key`"]
2298 pub fn SecKeyGetCSSMKey(key: &SecKey, cssm_key: NonNull<*const CSSM_KEY>) -> OSStatus;
2299}
2300
2301extern "C-unwind" {
2302 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
2303 #[deprecated = "renamed to `SecKey::csp_handle`"]
2304 pub fn SecKeyGetCSPHandle(key_ref: &SecKey, csp_handle: NonNull<CSSM_CSP_HANDLE>) -> OSStatus;
2305}
2306
2307extern "C-unwind" {
2308 #[cfg(all(
2309 feature = "SecAsn1Types",
2310 feature = "SecBase",
2311 feature = "cssmconfig",
2312 feature = "cssmtype"
2313 ))]
2314 #[deprecated = "renamed to `SecKey::credentials`"]
2315 pub fn SecKeyGetCredentials(
2316 key_ref: &SecKey,
2317 operation: CSSM_ACL_AUTHORIZATION_TAG,
2318 credential_type: SecCredentialType,
2319 out_credentials: NonNull<*const CSSM_ACCESS_CREDENTIALS>,
2320 ) -> OSStatus;
2321}
2322
2323#[cfg(feature = "SecBase")]
2324#[deprecated = "renamed to `SecKey::generate_symmetric`"]
2325#[inline]
2326pub unsafe extern "C-unwind" fn SecKeyGenerateSymmetric(
2327 parameters: &CFDictionary,
2328 error: *mut *mut CFError,
2329) -> Option<CFRetained<SecKey>> {
2330 extern "C-unwind" {
2331 fn SecKeyGenerateSymmetric(
2332 parameters: &CFDictionary,
2333 error: *mut *mut CFError,
2334 ) -> Option<NonNull<SecKey>>;
2335 }
2336 let ret = unsafe { SecKeyGenerateSymmetric(parameters, error) };
2337 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2338}
2339
2340#[cfg(feature = "SecBase")]
2341#[deprecated = "renamed to `SecKey::from_data`"]
2342#[inline]
2343pub unsafe extern "C-unwind" fn SecKeyCreateFromData(
2344 parameters: &CFDictionary,
2345 key_data: &CFData,
2346 error: *mut *mut CFError,
2347) -> Option<CFRetained<SecKey>> {
2348 extern "C-unwind" {
2349 fn SecKeyCreateFromData(
2350 parameters: &CFDictionary,
2351 key_data: &CFData,
2352 error: *mut *mut CFError,
2353 ) -> Option<NonNull<SecKey>>;
2354 }
2355 let ret = unsafe { SecKeyCreateFromData(parameters, key_data, error) };
2356 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2357}
2358
2359#[cfg(feature = "SecBase")]
2360#[deprecated = "renamed to `SecKey::derive_from_password`"]
2361#[inline]
2362pub unsafe extern "C-unwind" fn SecKeyDeriveFromPassword(
2363 password: &CFString,
2364 parameters: &CFDictionary,
2365 error: *mut *mut CFError,
2366) -> Option<CFRetained<SecKey>> {
2367 extern "C-unwind" {
2368 fn SecKeyDeriveFromPassword(
2369 password: &CFString,
2370 parameters: &CFDictionary,
2371 error: *mut *mut CFError,
2372 ) -> Option<NonNull<SecKey>>;
2373 }
2374 let ret = unsafe { SecKeyDeriveFromPassword(password, parameters, error) };
2375 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2376}
2377
2378#[cfg(feature = "SecBase")]
2379#[deprecated = "renamed to `SecKey::wrap_symmetric`"]
2380#[inline]
2381pub unsafe extern "C-unwind" fn SecKeyWrapSymmetric(
2382 key_to_wrap: &SecKey,
2383 wrapping_key: &SecKey,
2384 parameters: &CFDictionary,
2385 error: *mut *mut CFError,
2386) -> Option<CFRetained<CFData>> {
2387 extern "C-unwind" {
2388 fn SecKeyWrapSymmetric(
2389 key_to_wrap: &SecKey,
2390 wrapping_key: &SecKey,
2391 parameters: &CFDictionary,
2392 error: *mut *mut CFError,
2393 ) -> Option<NonNull<CFData>>;
2394 }
2395 let ret = unsafe { SecKeyWrapSymmetric(key_to_wrap, wrapping_key, parameters, error) };
2396 ret.map(|ret| unsafe { CFRetained::retain(ret) })
2397}
2398
2399#[cfg(feature = "SecBase")]
2400#[deprecated = "renamed to `SecKey::unwrap_symmetric`"]
2401#[inline]
2402pub unsafe extern "C-unwind" fn SecKeyUnwrapSymmetric(
2403 key_to_unwrap: NonNull<*const CFData>,
2404 unwrapping_key: &SecKey,
2405 parameters: &CFDictionary,
2406 error: *mut *mut CFError,
2407) -> Option<CFRetained<SecKey>> {
2408 extern "C-unwind" {
2409 fn SecKeyUnwrapSymmetric(
2410 key_to_unwrap: NonNull<*const CFData>,
2411 unwrapping_key: &SecKey,
2412 parameters: &CFDictionary,
2413 error: *mut *mut CFError,
2414 ) -> Option<NonNull<SecKey>>;
2415 }
2416 let ret = unsafe { SecKeyUnwrapSymmetric(key_to_unwrap, unwrapping_key, parameters, error) };
2417 ret.map(|ret| unsafe { CFRetained::retain(ret) })
2418}
2419
2420extern "C-unwind" {
2421 #[cfg(feature = "SecBase")]
2422 #[deprecated = "renamed to `SecKey::generate_pair`"]
2423 pub fn SecKeyGeneratePair(
2424 parameters: &CFDictionary,
2425 public_key: *mut *mut SecKey,
2426 private_key: *mut *mut SecKey,
2427 ) -> OSStatus;
2428}
2429
2430#[cfg(feature = "SecBase")]
2431#[deprecated = "renamed to `SecKey::new_random_key`"]
2432#[inline]
2433pub unsafe extern "C-unwind" fn SecKeyCreateRandomKey(
2434 parameters: &CFDictionary,
2435 error: *mut *mut CFError,
2436) -> Option<CFRetained<SecKey>> {
2437 extern "C-unwind" {
2438 fn SecKeyCreateRandomKey(
2439 parameters: &CFDictionary,
2440 error: *mut *mut CFError,
2441 ) -> Option<NonNull<SecKey>>;
2442 }
2443 let ret = unsafe { SecKeyCreateRandomKey(parameters, error) };
2444 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2445}
2446
2447#[cfg(feature = "SecBase")]
2448#[deprecated = "renamed to `SecKey::with_data`"]
2449#[inline]
2450pub unsafe extern "C-unwind" fn SecKeyCreateWithData(
2451 key_data: &CFData,
2452 attributes: &CFDictionary,
2453 error: *mut *mut CFError,
2454) -> Option<CFRetained<SecKey>> {
2455 extern "C-unwind" {
2456 fn SecKeyCreateWithData(
2457 key_data: &CFData,
2458 attributes: &CFDictionary,
2459 error: *mut *mut CFError,
2460 ) -> Option<NonNull<SecKey>>;
2461 }
2462 let ret = unsafe { SecKeyCreateWithData(key_data, attributes, error) };
2463 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2464}
2465
2466extern "C-unwind" {
2467 #[cfg(feature = "SecBase")]
2468 #[deprecated = "renamed to `SecKey::block_size`"]
2469 pub fn SecKeyGetBlockSize(key: &SecKey) -> usize;
2470}
2471
2472#[cfg(feature = "SecBase")]
2473#[deprecated = "renamed to `SecKey::external_representation`"]
2474#[inline]
2475pub unsafe extern "C-unwind" fn SecKeyCopyExternalRepresentation(
2476 key: &SecKey,
2477 error: *mut *mut CFError,
2478) -> Option<CFRetained<CFData>> {
2479 extern "C-unwind" {
2480 fn SecKeyCopyExternalRepresentation(
2481 key: &SecKey,
2482 error: *mut *mut CFError,
2483 ) -> Option<NonNull<CFData>>;
2484 }
2485 let ret = unsafe { SecKeyCopyExternalRepresentation(key, error) };
2486 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2487}
2488
2489#[cfg(feature = "SecBase")]
2490#[deprecated = "renamed to `SecKey::attributes`"]
2491#[inline]
2492pub unsafe extern "C-unwind" fn SecKeyCopyAttributes(
2493 key: &SecKey,
2494) -> Option<CFRetained<CFDictionary>> {
2495 extern "C-unwind" {
2496 fn SecKeyCopyAttributes(key: &SecKey) -> Option<NonNull<CFDictionary>>;
2497 }
2498 let ret = unsafe { SecKeyCopyAttributes(key) };
2499 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2500}
2501
2502#[cfg(feature = "SecBase")]
2503#[deprecated = "renamed to `SecKey::public_key`"]
2504#[inline]
2505pub unsafe extern "C-unwind" fn SecKeyCopyPublicKey(key: &SecKey) -> Option<CFRetained<SecKey>> {
2506 extern "C-unwind" {
2507 fn SecKeyCopyPublicKey(key: &SecKey) -> Option<NonNull<SecKey>>;
2508 }
2509 let ret = unsafe { SecKeyCopyPublicKey(key) };
2510 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2511}
2512
2513#[cfg(feature = "SecBase")]
2514#[deprecated = "renamed to `SecKey::signature`"]
2515#[inline]
2516pub unsafe extern "C-unwind" fn SecKeyCreateSignature(
2517 key: &SecKey,
2518 algorithm: &SecKeyAlgorithm,
2519 data_to_sign: &CFData,
2520 error: *mut *mut CFError,
2521) -> Option<CFRetained<CFData>> {
2522 extern "C-unwind" {
2523 fn SecKeyCreateSignature(
2524 key: &SecKey,
2525 algorithm: &SecKeyAlgorithm,
2526 data_to_sign: &CFData,
2527 error: *mut *mut CFError,
2528 ) -> Option<NonNull<CFData>>;
2529 }
2530 let ret = unsafe { SecKeyCreateSignature(key, algorithm, data_to_sign, error) };
2531 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2532}
2533
2534#[cfg(feature = "SecBase")]
2535#[deprecated = "renamed to `SecKey::verify_signature`"]
2536#[inline]
2537pub unsafe extern "C-unwind" fn SecKeyVerifySignature(
2538 key: &SecKey,
2539 algorithm: &SecKeyAlgorithm,
2540 signed_data: &CFData,
2541 signature: &CFData,
2542 error: *mut *mut CFError,
2543) -> bool {
2544 extern "C-unwind" {
2545 fn SecKeyVerifySignature(
2546 key: &SecKey,
2547 algorithm: &SecKeyAlgorithm,
2548 signed_data: &CFData,
2549 signature: &CFData,
2550 error: *mut *mut CFError,
2551 ) -> Boolean;
2552 }
2553 let ret = unsafe { SecKeyVerifySignature(key, algorithm, signed_data, signature, error) };
2554 ret != 0
2555}
2556
2557#[cfg(feature = "SecBase")]
2558#[deprecated = "renamed to `SecKey::encrypted_data`"]
2559#[inline]
2560pub unsafe extern "C-unwind" fn SecKeyCreateEncryptedData(
2561 key: &SecKey,
2562 algorithm: &SecKeyAlgorithm,
2563 plaintext: &CFData,
2564 error: *mut *mut CFError,
2565) -> Option<CFRetained<CFData>> {
2566 extern "C-unwind" {
2567 fn SecKeyCreateEncryptedData(
2568 key: &SecKey,
2569 algorithm: &SecKeyAlgorithm,
2570 plaintext: &CFData,
2571 error: *mut *mut CFError,
2572 ) -> Option<NonNull<CFData>>;
2573 }
2574 let ret = unsafe { SecKeyCreateEncryptedData(key, algorithm, plaintext, error) };
2575 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2576}
2577
2578#[cfg(feature = "SecBase")]
2579#[deprecated = "renamed to `SecKey::decrypted_data`"]
2580#[inline]
2581pub unsafe extern "C-unwind" fn SecKeyCreateDecryptedData(
2582 key: &SecKey,
2583 algorithm: &SecKeyAlgorithm,
2584 ciphertext: &CFData,
2585 error: *mut *mut CFError,
2586) -> Option<CFRetained<CFData>> {
2587 extern "C-unwind" {
2588 fn SecKeyCreateDecryptedData(
2589 key: &SecKey,
2590 algorithm: &SecKeyAlgorithm,
2591 ciphertext: &CFData,
2592 error: *mut *mut CFError,
2593 ) -> Option<NonNull<CFData>>;
2594 }
2595 let ret = unsafe { SecKeyCreateDecryptedData(key, algorithm, ciphertext, error) };
2596 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2597}
2598
2599#[cfg(feature = "SecBase")]
2600#[deprecated = "renamed to `SecKey::key_exchange_result`"]
2601#[inline]
2602pub unsafe extern "C-unwind" fn SecKeyCopyKeyExchangeResult(
2603 private_key: &SecKey,
2604 algorithm: &SecKeyAlgorithm,
2605 public_key: &SecKey,
2606 parameters: &CFDictionary,
2607 error: *mut *mut CFError,
2608) -> Option<CFRetained<CFData>> {
2609 extern "C-unwind" {
2610 fn SecKeyCopyKeyExchangeResult(
2611 private_key: &SecKey,
2612 algorithm: &SecKeyAlgorithm,
2613 public_key: &SecKey,
2614 parameters: &CFDictionary,
2615 error: *mut *mut CFError,
2616 ) -> Option<NonNull<CFData>>;
2617 }
2618 let ret = unsafe {
2619 SecKeyCopyKeyExchangeResult(private_key, algorithm, public_key, parameters, error)
2620 };
2621 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
2622}
2623
2624#[cfg(feature = "SecBase")]
2625#[deprecated = "renamed to `SecKey::is_algorithm_supported`"]
2626#[inline]
2627pub unsafe extern "C-unwind" fn SecKeyIsAlgorithmSupported(
2628 key: &SecKey,
2629 operation: SecKeyOperationType,
2630 algorithm: &SecKeyAlgorithm,
2631) -> bool {
2632 extern "C-unwind" {
2633 fn SecKeyIsAlgorithmSupported(
2634 key: &SecKey,
2635 operation: SecKeyOperationType,
2636 algorithm: &SecKeyAlgorithm,
2637 ) -> Boolean;
2638 }
2639 let ret = unsafe { SecKeyIsAlgorithmSupported(key, operation, algorithm) };
2640 ret != 0
2641}