objc2_security/generated/SecIdentity.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2_core_foundation::*;
5
6use crate::*;
7
8#[cfg(feature = "SecBase")]
9unsafe impl ConcreteType for SecIdentity {
10 /// Returns the type identifier of SecIdentity instances.
11 ///
12 /// Returns: The CFTypeID of SecIdentity instances.
13 #[doc(alias = "SecIdentityGetTypeID")]
14 #[inline]
15 fn type_id() -> CFTypeID {
16 extern "C-unwind" {
17 fn SecIdentityGetTypeID() -> CFTypeID;
18 }
19 unsafe { SecIdentityGetTypeID() }
20 }
21}
22
23#[cfg(feature = "SecBase")]
24impl SecIdentity {
25 /// create a new identity object from the provided certificate and its associated private key.
26 ///
27 /// Parameter `allocator`: CFAllocator to allocate the identity object. Pass NULL to use the default allocator.
28 ///
29 /// Parameter `certificate`: A certificate reference.
30 ///
31 /// Parameter `privateKey`: A private key reference.
32 ///
33 /// Returns: An identity reference.
34 ///
35 /// This interface returns null if the private does not key correspond to the public key in the certifcate.
36 #[doc(alias = "SecIdentityCreate")]
37 #[cfg(feature = "SecBase")]
38 #[inline]
39 pub unsafe fn new(
40 allocator: Option<&CFAllocator>,
41 certificate: &SecCertificate,
42 private_key: &SecKey,
43 ) -> Option<CFRetained<SecIdentity>> {
44 extern "C-unwind" {
45 fn SecIdentityCreate(
46 allocator: Option<&CFAllocator>,
47 certificate: &SecCertificate,
48 private_key: &SecKey,
49 ) -> Option<NonNull<SecIdentity>>;
50 }
51 let ret = unsafe { SecIdentityCreate(allocator, certificate, private_key) };
52 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
53 }
54
55 /// Creates a new identity reference for the given certificate, assuming the associated private key is in one of the specified keychains.
56 ///
57 /// Parameter `keychainOrArray`: A reference to an array of keychains to search, a single keychain, or NULL to search the user's default keychain search list.
58 ///
59 /// Parameter `certificateRef`: A certificate reference.
60 ///
61 /// Parameter `identityRef`: On return, an identity reference. You are responsible for releasing this reference by calling the CFRelease function.
62 ///
63 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
64 ///
65 /// # Safety
66 ///
67 /// - `keychain_or_array` should be of the correct type.
68 /// - `identity_ref` must be a valid pointer.
69 #[doc(alias = "SecIdentityCreateWithCertificate")]
70 #[cfg(feature = "SecBase")]
71 #[inline]
72 pub unsafe fn create_with_certificate(
73 keychain_or_array: Option<&CFType>,
74 certificate_ref: &SecCertificate,
75 identity_ref: NonNull<*mut SecIdentity>,
76 ) -> OSStatus {
77 extern "C-unwind" {
78 fn SecIdentityCreateWithCertificate(
79 keychain_or_array: Option<&CFType>,
80 certificate_ref: &SecCertificate,
81 identity_ref: NonNull<*mut SecIdentity>,
82 ) -> OSStatus;
83 }
84 unsafe {
85 SecIdentityCreateWithCertificate(keychain_or_array, certificate_ref, identity_ref)
86 }
87 }
88
89 /// Returns a reference to a certificate for the given identity
90 /// reference.
91 ///
92 /// Parameter `identityRef`: An identity reference.
93 ///
94 /// Parameter `certificateRef`: On return, a pointer to the found certificate
95 /// reference. You are responsible for releasing this reference by calling
96 /// the CFRelease function.
97 ///
98 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
99 ///
100 /// # Safety
101 ///
102 /// `certificate_ref` must be a valid pointer.
103 #[doc(alias = "SecIdentityCopyCertificate")]
104 #[cfg(feature = "SecBase")]
105 #[inline]
106 pub unsafe fn copy_certificate(
107 &self,
108 certificate_ref: NonNull<*mut SecCertificate>,
109 ) -> OSStatus {
110 extern "C-unwind" {
111 fn SecIdentityCopyCertificate(
112 identity_ref: &SecIdentity,
113 certificate_ref: NonNull<*mut SecCertificate>,
114 ) -> OSStatus;
115 }
116 unsafe { SecIdentityCopyCertificate(self, certificate_ref) }
117 }
118
119 /// Returns the private key associated with an identity.
120 ///
121 /// Parameter `identityRef`: An identity reference.
122 ///
123 /// Parameter `privateKeyRef`: On return, a pointer to the private key for the given
124 /// identity. On iOS, the private key must be of class type kSecAppleKeyItemClass.
125 /// You are responsible for releasing this reference by calling the CFRelease function.
126 ///
127 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
128 ///
129 /// # Safety
130 ///
131 /// `private_key_ref` must be a valid pointer.
132 #[doc(alias = "SecIdentityCopyPrivateKey")]
133 #[cfg(feature = "SecBase")]
134 #[inline]
135 pub unsafe fn copy_private_key(&self, private_key_ref: NonNull<*mut SecKey>) -> OSStatus {
136 extern "C-unwind" {
137 fn SecIdentityCopyPrivateKey(
138 identity_ref: &SecIdentity,
139 private_key_ref: NonNull<*mut SecKey>,
140 ) -> OSStatus;
141 }
142 unsafe { SecIdentityCopyPrivateKey(self, private_key_ref) }
143 }
144
145 /// Returns the preferred identity for the specified name and key usage, optionally limiting the result to an identity issued by a certificate whose subject is one of the distinguished names in validIssuers. If a preferred identity does not exist, NULL is returned.
146 ///
147 /// Parameter `name`: A string containing a URI, RFC822 email address, DNS hostname, or other name which uniquely identifies the service requiring an identity.
148 ///
149 /// Parameter `keyUsage`: A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to ignore this parameter.
150 ///
151 /// Parameter `validIssuers`: (optional) An array of CFDataRef instances whose contents are the subject names of allowable issuers, as returned by a call to SSLCopyDistinguishedNames (SecureTransport.h). Pass NULL if any issuer is allowed.
152 ///
153 /// Parameter `identity`: On return, a reference to the preferred identity, or NULL if none was found. You are responsible for releasing this reference by calling the CFRelease function.
154 ///
155 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
156 ///
157 /// This API is deprecated in 10.7. Please use the SecIdentityCopyPreferred API instead.
158 ///
159 /// # Safety
160 ///
161 /// - `valid_issuers` generic must be of the correct type.
162 /// - `identity` must be a valid pointer.
163 #[doc(alias = "SecIdentityCopyPreference")]
164 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
165 #[deprecated]
166 #[inline]
167 pub unsafe fn copy_preference(
168 name: &CFString,
169 key_usage: CSSM_KEYUSE,
170 valid_issuers: Option<&CFArray>,
171 identity: NonNull<*mut SecIdentity>,
172 ) -> OSStatus {
173 extern "C-unwind" {
174 fn SecIdentityCopyPreference(
175 name: &CFString,
176 key_usage: CSSM_KEYUSE,
177 valid_issuers: Option<&CFArray>,
178 identity: NonNull<*mut SecIdentity>,
179 ) -> OSStatus;
180 }
181 unsafe { SecIdentityCopyPreference(name, key_usage, valid_issuers, identity) }
182 }
183
184 /// Returns the preferred identity for the specified name and key usage, optionally limiting the result to an identity issued by a certificate whose subject is one of the distinguished names in validIssuers. If a preferred identity does not exist, NULL is returned.
185 ///
186 /// Parameter `name`: A string containing a URI, RFC822 email address, DNS hostname, or other name which uniquely identifies the service requiring an identity.
187 ///
188 /// Parameter `keyUsage`: A CFArrayRef value, containing items defined in SecItem.h Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
189 ///
190 /// Parameter `validIssuers`: (optional) An array of CFDataRef instances whose contents are the subject names of allowable issuers, as returned by a call to SSLCopyDistinguishedNames (SecureTransport.h). Pass NULL if any issuer is allowed.
191 ///
192 /// Returns: An identity or NULL, if the preferred identity has not been set. Your code should then typically perform a search for possible identities using the SecItem APIs.
193 ///
194 /// If a preferred identity has not been set for the supplied name, the returned identity reference will be NULL. Your code should then perform a search for possible identities, using the SecItemCopyMatching API. Note: in versions of macOS prior to 11.3, identity preferences are shared between processes running as the same user. Starting in 11.3, URI names are considered per-application preferences. An identity preference for a URI name may not be found if the calling application is different from the one which set the preference with SecIdentitySetPreferred.
195 ///
196 /// # Safety
197 ///
198 /// - `key_usage` generic must be of the correct type.
199 /// - `valid_issuers` generic must be of the correct type.
200 #[doc(alias = "SecIdentityCopyPreferred")]
201 #[cfg(feature = "SecBase")]
202 #[inline]
203 pub unsafe fn preferred(
204 name: &CFString,
205 key_usage: Option<&CFArray>,
206 valid_issuers: Option<&CFArray>,
207 ) -> Option<CFRetained<SecIdentity>> {
208 extern "C-unwind" {
209 fn SecIdentityCopyPreferred(
210 name: &CFString,
211 key_usage: Option<&CFArray>,
212 valid_issuers: Option<&CFArray>,
213 ) -> Option<NonNull<SecIdentity>>;
214 }
215 let ret = unsafe { SecIdentityCopyPreferred(name, key_usage, valid_issuers) };
216 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
217 }
218
219 /// Sets the preferred identity for the specified name and key usage.
220 ///
221 /// Parameter `identity`: A reference to the identity which will be preferred.
222 ///
223 /// Parameter `name`: A string containing a URI, RFC822 email address, DNS hostname, or other name which uniquely identifies a service requiring this identity.
224 ///
225 /// Parameter `keyUsage`: A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to specify any key usage.
226 ///
227 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
228 ///
229 /// This API is deprecated in 10.7. Please use the SecIdentitySetPreferred API instead.
230 #[doc(alias = "SecIdentitySetPreference")]
231 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
232 #[deprecated]
233 #[inline]
234 pub unsafe fn set_preference(&self, name: &CFString, key_usage: CSSM_KEYUSE) -> OSStatus {
235 extern "C-unwind" {
236 fn SecIdentitySetPreference(
237 identity: &SecIdentity,
238 name: &CFString,
239 key_usage: CSSM_KEYUSE,
240 ) -> OSStatus;
241 }
242 unsafe { SecIdentitySetPreference(self, name, key_usage) }
243 }
244
245 /// Sets the preferred identity for the specified name and key usage.
246 ///
247 /// Parameter `identity`: A reference to the identity which will be preferred. If NULL is passed, any existing preference for the specified name is cleared instead.
248 ///
249 /// Parameter `name`: A string containing a URI, RFC822 email address, DNS hostname, or other name which uniquely identifies a service requiring this identity.
250 ///
251 /// Parameter `keyUsage`: A CFArrayRef value, containing items defined in SecItem.h Pass NULL to specify any key usage. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
252 ///
253 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
254 ///
255 /// Note: in versions of macOS prior to 11.3, identity preferences are shared between processes running as the same user. Starting in 11.3, URI names are considered per-application preferences. An identity preference for a URI name will be scoped to the application which created it, such that a subsequent call to SecIdentityCopyPreferred will only return it for that same application.
256 ///
257 /// # Safety
258 ///
259 /// `key_usage` generic must be of the correct type.
260 #[doc(alias = "SecIdentitySetPreferred")]
261 #[cfg(feature = "SecBase")]
262 #[inline]
263 pub unsafe fn set_preferred(
264 identity: Option<&SecIdentity>,
265 name: &CFString,
266 key_usage: Option<&CFArray>,
267 ) -> OSStatus {
268 extern "C-unwind" {
269 fn SecIdentitySetPreferred(
270 identity: Option<&SecIdentity>,
271 name: &CFString,
272 key_usage: Option<&CFArray>,
273 ) -> OSStatus;
274 }
275 unsafe { SecIdentitySetPreferred(identity, name, key_usage) }
276 }
277
278 /// Obtain the system-wide SecIdentityRef associated with
279 /// a specified domain.
280 ///
281 /// Parameter `domain`: Identifies the SecIdentityRef to be obtained, typically
282 /// in the form "com.apple.subdomain...".
283 ///
284 /// Parameter `idRef`: On return, the system SecIdentityRef assicated with
285 /// the specified domain. Caller must CFRelease this when
286 /// finished with it.
287 ///
288 /// Parameter `actualDomain`: (optional) The actual domain name of the
289 /// the returned identity is returned here. This
290 /// may be different from the requested domain.
291 ///
292 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
293 ///
294 /// If no system SecIdentityRef exists for the specified
295 /// domain, a domain-specific alternate may be returned
296 /// instead, typically (but not exclusively) the
297 /// kSecIdentityDomainDefault SecIdentityRef.
298 ///
299 /// # Safety
300 ///
301 /// - `id_ref` must be a valid pointer.
302 /// - `actual_domain` must be a valid pointer or null.
303 #[doc(alias = "SecIdentityCopySystemIdentity")]
304 #[cfg(feature = "SecBase")]
305 #[inline]
306 pub unsafe fn copy_system_identity(
307 domain: &CFString,
308 id_ref: NonNull<*mut SecIdentity>,
309 actual_domain: *mut *const CFString,
310 ) -> OSStatus {
311 extern "C-unwind" {
312 fn SecIdentityCopySystemIdentity(
313 domain: &CFString,
314 id_ref: NonNull<*mut SecIdentity>,
315 actual_domain: *mut *const CFString,
316 ) -> OSStatus;
317 }
318 unsafe { SecIdentityCopySystemIdentity(domain, id_ref, actual_domain) }
319 }
320
321 /// Assign the supplied SecIdentityRef to the specified
322 /// domain.
323 ///
324 /// Parameter `domain`: Identifies the domain to which the specified
325 /// SecIdentityRef will be assigned.
326 ///
327 /// Parameter `idRef`: (optional) The identity to be assigned to the specified
328 /// domain. Pass NULL to delete a possible entry for the specified
329 /// domain; in this case, it is not an error if no identity
330 /// exists for the specified domain.
331 ///
332 /// Returns: A result code. See "Security Error Codes" (SecBase.h).
333 ///
334 /// The caller must be running as root.
335 #[doc(alias = "SecIdentitySetSystemIdentity")]
336 #[cfg(feature = "SecBase")]
337 #[inline]
338 pub unsafe fn set_system_identity(domain: &CFString, id_ref: Option<&SecIdentity>) -> OSStatus {
339 extern "C-unwind" {
340 fn SecIdentitySetSystemIdentity(
341 domain: &CFString,
342 id_ref: Option<&SecIdentity>,
343 ) -> OSStatus;
344 }
345 unsafe { SecIdentitySetSystemIdentity(domain, id_ref) }
346 }
347}
348
349extern "C" {
350 /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecidentitydomaindefault?language=objc)
351 pub static kSecIdentityDomainDefault: &'static CFString;
352}
353
354extern "C" {
355 /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecidentitydomainkerberoskdc?language=objc)
356 pub static kSecIdentityDomainKerberosKDC: &'static CFString;
357}
358
359#[cfg(feature = "SecBase")]
360#[deprecated = "renamed to `SecIdentity::new`"]
361#[inline]
362pub unsafe extern "C-unwind" fn SecIdentityCreate(
363 allocator: Option<&CFAllocator>,
364 certificate: &SecCertificate,
365 private_key: &SecKey,
366) -> Option<CFRetained<SecIdentity>> {
367 extern "C-unwind" {
368 fn SecIdentityCreate(
369 allocator: Option<&CFAllocator>,
370 certificate: &SecCertificate,
371 private_key: &SecKey,
372 ) -> Option<NonNull<SecIdentity>>;
373 }
374 let ret = unsafe { SecIdentityCreate(allocator, certificate, private_key) };
375 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
376}
377
378extern "C-unwind" {
379 #[cfg(feature = "SecBase")]
380 #[deprecated = "renamed to `SecIdentity::create_with_certificate`"]
381 pub fn SecIdentityCreateWithCertificate(
382 keychain_or_array: Option<&CFType>,
383 certificate_ref: &SecCertificate,
384 identity_ref: NonNull<*mut SecIdentity>,
385 ) -> OSStatus;
386}
387
388extern "C-unwind" {
389 #[cfg(feature = "SecBase")]
390 #[deprecated = "renamed to `SecIdentity::copy_certificate`"]
391 pub fn SecIdentityCopyCertificate(
392 identity_ref: &SecIdentity,
393 certificate_ref: NonNull<*mut SecCertificate>,
394 ) -> OSStatus;
395}
396
397extern "C-unwind" {
398 #[cfg(feature = "SecBase")]
399 #[deprecated = "renamed to `SecIdentity::copy_private_key`"]
400 pub fn SecIdentityCopyPrivateKey(
401 identity_ref: &SecIdentity,
402 private_key_ref: NonNull<*mut SecKey>,
403 ) -> OSStatus;
404}
405
406extern "C-unwind" {
407 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
408 #[deprecated = "renamed to `SecIdentity::copy_preference`"]
409 pub fn SecIdentityCopyPreference(
410 name: &CFString,
411 key_usage: CSSM_KEYUSE,
412 valid_issuers: Option<&CFArray>,
413 identity: NonNull<*mut SecIdentity>,
414 ) -> OSStatus;
415}
416
417#[cfg(feature = "SecBase")]
418#[deprecated = "renamed to `SecIdentity::preferred`"]
419#[inline]
420pub unsafe extern "C-unwind" fn SecIdentityCopyPreferred(
421 name: &CFString,
422 key_usage: Option<&CFArray>,
423 valid_issuers: Option<&CFArray>,
424) -> Option<CFRetained<SecIdentity>> {
425 extern "C-unwind" {
426 fn SecIdentityCopyPreferred(
427 name: &CFString,
428 key_usage: Option<&CFArray>,
429 valid_issuers: Option<&CFArray>,
430 ) -> Option<NonNull<SecIdentity>>;
431 }
432 let ret = unsafe { SecIdentityCopyPreferred(name, key_usage, valid_issuers) };
433 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
434}
435
436extern "C-unwind" {
437 #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
438 #[deprecated = "renamed to `SecIdentity::set_preference`"]
439 pub fn SecIdentitySetPreference(
440 identity: &SecIdentity,
441 name: &CFString,
442 key_usage: CSSM_KEYUSE,
443 ) -> OSStatus;
444}
445
446extern "C-unwind" {
447 #[cfg(feature = "SecBase")]
448 #[deprecated = "renamed to `SecIdentity::set_preferred`"]
449 pub fn SecIdentitySetPreferred(
450 identity: Option<&SecIdentity>,
451 name: &CFString,
452 key_usage: Option<&CFArray>,
453 ) -> OSStatus;
454}
455
456extern "C-unwind" {
457 #[cfg(feature = "SecBase")]
458 #[deprecated = "renamed to `SecIdentity::copy_system_identity`"]
459 pub fn SecIdentityCopySystemIdentity(
460 domain: &CFString,
461 id_ref: NonNull<*mut SecIdentity>,
462 actual_domain: *mut *const CFString,
463 ) -> OSStatus;
464}
465
466extern "C-unwind" {
467 #[cfg(feature = "SecBase")]
468 #[deprecated = "renamed to `SecIdentity::set_system_identity`"]
469 pub fn SecIdentitySetSystemIdentity(
470 domain: &CFString,
471 id_ref: Option<&SecIdentity>,
472 ) -> OSStatus;
473}