objc2_security/generated/
SecCertificate.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#[cfg(feature = "SecBase")]
12unsafe impl ConcreteType for SecCertificate {
13    /// Returns the type identifier of SecCertificate instances.
14    ///
15    /// Returns: The CFTypeID of SecCertificate instances.
16    #[doc(alias = "SecCertificateGetTypeID")]
17    #[inline]
18    fn type_id() -> CFTypeID {
19        extern "C-unwind" {
20            fn SecCertificateGetTypeID() -> CFTypeID;
21        }
22        unsafe { SecCertificateGetTypeID() }
23    }
24}
25
26#[cfg(feature = "SecBase")]
27impl SecCertificate {
28    /// Create a certificate given it's DER representation as a CFData.
29    ///
30    /// Parameter `allocator`: CFAllocator to allocate the certificate with.
31    ///
32    /// Parameter `data`: DER encoded X.509 certificate.
33    ///
34    /// Returns: Return NULL if the passed-in data is not a valid DER-encoded
35    /// X.509 certificate, return a SecCertificateRef otherwise.
36    #[doc(alias = "SecCertificateCreateWithData")]
37    #[cfg(feature = "SecBase")]
38    #[inline]
39    pub unsafe fn with_data(
40        allocator: Option<&CFAllocator>,
41        data: &CFData,
42    ) -> Option<CFRetained<SecCertificate>> {
43        extern "C-unwind" {
44            fn SecCertificateCreateWithData(
45                allocator: Option<&CFAllocator>,
46                data: &CFData,
47            ) -> Option<NonNull<SecCertificate>>;
48        }
49        let ret = unsafe { SecCertificateCreateWithData(allocator, data) };
50        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
51    }
52
53    /// Return the DER representation of an X.509 certificate.
54    ///
55    /// Parameter `certificate`: SecCertificate object created with
56    /// SecCertificateCreateWithData().
57    ///
58    /// Returns: DER encoded X.509 certificate.
59    #[doc(alias = "SecCertificateCopyData")]
60    #[cfg(feature = "SecBase")]
61    #[inline]
62    pub unsafe fn data(&self) -> CFRetained<CFData> {
63        extern "C-unwind" {
64            fn SecCertificateCopyData(certificate: &SecCertificate) -> Option<NonNull<CFData>>;
65        }
66        let ret = unsafe { SecCertificateCopyData(self) };
67        let ret =
68            ret.expect("function was marked as returning non-null, but actually returned NULL");
69        unsafe { CFRetained::from_raw(ret) }
70    }
71
72    /// Return a simple string which hopefully represents a human
73    /// understandable summary.
74    ///
75    /// Parameter `certificate`: A reference to the certificate from which to derive
76    /// the subject summary string.
77    ///
78    /// All the data in this string comes from the certificate itself
79    /// and thus it's in whatever language the certificate itself is in.
80    ///
81    /// Returns: A CFStringRef which the caller should CFRelease() once it's no
82    /// longer needed.
83    #[doc(alias = "SecCertificateCopySubjectSummary")]
84    #[cfg(feature = "SecBase")]
85    #[inline]
86    pub unsafe fn subject_summary(&self) -> Option<CFRetained<CFString>> {
87        extern "C-unwind" {
88            fn SecCertificateCopySubjectSummary(
89                certificate: &SecCertificate,
90            ) -> Option<NonNull<CFString>>;
91        }
92        let ret = unsafe { SecCertificateCopySubjectSummary(self) };
93        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
94    }
95
96    /// Retrieves the common name of the subject of a given certificate.
97    ///
98    /// Parameter `certificate`: A reference to the certificate from which to retrieve the common name.
99    ///
100    /// Parameter `commonName`: On return, a reference to the common name. Your code must release this reference by calling the CFRelease function.
101    ///
102    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
103    ///
104    /// All the data in this string comes from the certificate itself, and thus it's in whatever language the certificate itself is in.
105    /// Note that the certificate's common name field may not be present, or may be inadequate to describe the certificate; for display purposes,
106    /// you should consider using SecCertificateCopySubjectSummary instead of this function.
107    ///
108    /// # Safety
109    ///
110    /// `common_name` must be a valid pointer.
111    #[doc(alias = "SecCertificateCopyCommonName")]
112    #[cfg(feature = "SecBase")]
113    #[inline]
114    pub unsafe fn copy_common_name(&self, common_name: NonNull<*const CFString>) -> OSStatus {
115        extern "C-unwind" {
116            fn SecCertificateCopyCommonName(
117                certificate: &SecCertificate,
118                common_name: NonNull<*const CFString>,
119            ) -> OSStatus;
120        }
121        unsafe { SecCertificateCopyCommonName(self, common_name) }
122    }
123
124    /// Returns an array of zero or more email addresses for the subject of a given certificate.
125    ///
126    /// Parameter `certificate`: A reference to the certificate from which to retrieve the email addresses.
127    ///
128    /// Parameter `emailAddresses`: On return, an array of zero or more CFStringRef elements corresponding to each email address found.
129    /// Your code must release this array reference by calling the CFRelease function.
130    ///
131    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
132    ///
133    /// # Safety
134    ///
135    /// `email_addresses` must be a valid pointer.
136    #[doc(alias = "SecCertificateCopyEmailAddresses")]
137    #[cfg(feature = "SecBase")]
138    #[inline]
139    pub unsafe fn copy_email_addresses(
140        &self,
141        email_addresses: NonNull<*const CFArray>,
142    ) -> OSStatus {
143        extern "C-unwind" {
144            fn SecCertificateCopyEmailAddresses(
145                certificate: &SecCertificate,
146                email_addresses: NonNull<*const CFArray>,
147            ) -> OSStatus;
148        }
149        unsafe { SecCertificateCopyEmailAddresses(self, email_addresses) }
150    }
151
152    /// Return the certificate's normalized issuer
153    ///
154    /// Parameter `certificate`: The certificate from which to get values
155    ///
156    /// The issuer is a sequence in the format used by SecItemCopyMatching.  The content returned is a DER-encoded X.509 distinguished name. For a display version of the issuer, call SecCertificateCopyValues. The caller must CFRelease the value returned.
157    #[doc(alias = "SecCertificateCopyNormalizedIssuerSequence")]
158    #[cfg(feature = "SecBase")]
159    #[inline]
160    pub unsafe fn normalized_issuer_sequence(&self) -> Option<CFRetained<CFData>> {
161        extern "C-unwind" {
162            fn SecCertificateCopyNormalizedIssuerSequence(
163                certificate: &SecCertificate,
164            ) -> Option<NonNull<CFData>>;
165        }
166        let ret = unsafe { SecCertificateCopyNormalizedIssuerSequence(self) };
167        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
168    }
169
170    /// Return the certificate's normalized subject
171    ///
172    /// Parameter `certificate`: The certificate from which to get values
173    ///
174    /// The subject is a sequence in the format used by SecItemCopyMatching. The content returned is a DER-encoded X.509 distinguished name. For a display version of the subject, call SecCertificateCopyValues. The caller must CFRelease the value returned.
175    #[doc(alias = "SecCertificateCopyNormalizedSubjectSequence")]
176    #[cfg(feature = "SecBase")]
177    #[inline]
178    pub unsafe fn normalized_subject_sequence(&self) -> Option<CFRetained<CFData>> {
179        extern "C-unwind" {
180            fn SecCertificateCopyNormalizedSubjectSequence(
181                certificate: &SecCertificate,
182            ) -> Option<NonNull<CFData>>;
183        }
184        let ret = unsafe { SecCertificateCopyNormalizedSubjectSequence(self) };
185        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
186    }
187
188    /// Retrieves the public key for a given certificate.
189    ///
190    /// Parameter `certificate`: A reference to the certificate from which to retrieve the public key.
191    ///
192    /// Returns: A reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function. If the public key has an encoding issue or uses an unsupported algorithm, the returned reference will be null.
193    ///
194    /// RSA and ECDSA public keys are supported. All other public key algorithms are unsupported.
195    #[doc(alias = "SecCertificateCopyKey")]
196    #[cfg(feature = "SecBase")]
197    #[inline]
198    pub unsafe fn key(&self) -> Option<CFRetained<SecKey>> {
199        extern "C-unwind" {
200            fn SecCertificateCopyKey(certificate: &SecCertificate) -> Option<NonNull<SecKey>>;
201        }
202        let ret = unsafe { SecCertificateCopyKey(self) };
203        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
204    }
205
206    /// Retrieves the public key for a given certificate.
207    ///
208    /// Parameter `certificate`: A reference to the certificate from which to retrieve the public key.
209    ///
210    /// Parameter `key`: On return, a reference to the public key for the specified certificate. Your code must release this reference by calling the CFRelease function.
211    ///
212    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
213    ///
214    /// NOTE: Deprecated in macOS 10.14; use SecCertificateCopyKey instead for cross-platform availability.
215    ///
216    /// # Safety
217    ///
218    /// `key` must be a valid pointer.
219    #[doc(alias = "SecCertificateCopyPublicKey")]
220    #[cfg(feature = "SecBase")]
221    #[deprecated]
222    #[inline]
223    pub unsafe fn copy_public_key(&self, key: NonNull<*mut SecKey>) -> OSStatus {
224        extern "C-unwind" {
225            #[cfg_attr(
226                target_os = "macos",
227                link_name = "SecCertificateCopyPublicKey$LEGACYMAC"
228            )]
229            fn SecCertificateCopyPublicKey(
230                certificate: &SecCertificate,
231                key: NonNull<*mut SecKey>,
232            ) -> OSStatus;
233        }
234        unsafe { SecCertificateCopyPublicKey(self, key) }
235    }
236
237    /// Return the certificate's serial number.
238    ///
239    /// Parameter `certificate`: The certificate from which to get values.
240    ///
241    /// Parameter `error`: An optional pointer to a CFErrorRef which will be set on return from the function if an error occurred. If not NULL, the caller is responsible for releasing the CFErrorRef.
242    ///
243    /// Return the content of a DER-encoded integer (without the tag and length fields) for this certificate's serial number. The caller must CFRelease the value returned.
244    ///
245    /// # Safety
246    ///
247    /// `error` must be a valid pointer or null.
248    #[doc(alias = "SecCertificateCopySerialNumberData")]
249    #[cfg(feature = "SecBase")]
250    #[inline]
251    pub unsafe fn serial_number_data(
252        &self,
253        error: *mut *mut CFError,
254    ) -> Option<CFRetained<CFData>> {
255        extern "C-unwind" {
256            fn SecCertificateCopySerialNumberData(
257                certificate: &SecCertificate,
258                error: *mut *mut CFError,
259            ) -> Option<NonNull<CFData>>;
260        }
261        let ret = unsafe { SecCertificateCopySerialNumberData(self, error) };
262        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
263    }
264
265    /// Obtain the starting date of the given certificate.
266    ///
267    /// Parameter `certificate`: The certificate from which to get values.
268    ///
269    /// Returns: Returns the absolute time at which the given certificate becomes valid,
270    /// or NULL if this value could not be obtained. The caller must CFRelease the value returned.
271    #[doc(alias = "SecCertificateCopyNotValidBeforeDate")]
272    #[cfg(feature = "SecBase")]
273    #[inline]
274    pub unsafe fn not_valid_before_date(&self) -> Option<CFRetained<CFDate>> {
275        extern "C-unwind" {
276            fn SecCertificateCopyNotValidBeforeDate(
277                certificate: &SecCertificate,
278            ) -> Option<NonNull<CFDate>>;
279        }
280        let ret = unsafe { SecCertificateCopyNotValidBeforeDate(self) };
281        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
282    }
283
284    /// Obtain the expiration date of the given certificate.
285    ///
286    /// Parameter `certificate`: The certificate from which to get values.
287    ///
288    /// Returns: Returns the absolute time at which the given certificate expires,
289    /// or NULL if this value could not be obtained. The caller must CFRelease the value returned.
290    #[doc(alias = "SecCertificateCopyNotValidAfterDate")]
291    #[cfg(feature = "SecBase")]
292    #[inline]
293    pub unsafe fn not_valid_after_date(&self) -> Option<CFRetained<CFDate>> {
294        extern "C-unwind" {
295            fn SecCertificateCopyNotValidAfterDate(
296                certificate: &SecCertificate,
297            ) -> Option<NonNull<CFDate>>;
298        }
299        let ret = unsafe { SecCertificateCopyNotValidAfterDate(self) };
300        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
301    }
302
303    /// Return the certificate's serial number.
304    ///
305    /// Parameter `certificate`: The certificate from which to get values.
306    ///
307    /// Parameter `error`: An optional pointer to a CFErrorRef which will be set on return from the function if an error occurred. If not NULL, the caller is responsible for releasing the CFErrorRef.
308    ///
309    /// Return the content of a DER-encoded integer (without the tag and length fields) for this certificate's serial number. The caller must CFRelease the value returned. NOTE: Deprecated in macOS 10.13; use SecCertificateCopySerialNumberData instead for cross-platform availability.
310    ///
311    /// # Safety
312    ///
313    /// `error` must be a valid pointer or null.
314    #[doc(alias = "SecCertificateCopySerialNumber")]
315    #[cfg(feature = "SecBase")]
316    #[deprecated]
317    #[inline]
318    pub unsafe fn serial_number(&self, error: *mut *mut CFError) -> Option<CFRetained<CFData>> {
319        extern "C-unwind" {
320            #[cfg_attr(
321                target_os = "macos",
322                link_name = "SecCertificateCopySerialNumber$LEGACYMAC"
323            )]
324            fn SecCertificateCopySerialNumber(
325                certificate: &SecCertificate,
326                error: *mut *mut CFError,
327            ) -> Option<NonNull<CFData>>;
328        }
329        let ret = unsafe { SecCertificateCopySerialNumber(self, error) };
330        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
331    }
332}
333
334/// [Apple's documentation](https://developer.apple.com/documentation/security/ksecsubjectitemattr?language=objc)
335pub const kSecSubjectItemAttr: c_uint = 1937072746;
336/// [Apple's documentation](https://developer.apple.com/documentation/security/ksecissueritemattr?language=objc)
337pub const kSecIssuerItemAttr: c_uint = 1769173877;
338/// [Apple's documentation](https://developer.apple.com/documentation/security/ksecserialnumberitemattr?language=objc)
339pub const kSecSerialNumberItemAttr: c_uint = 1936614002;
340/// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpublickeyhashitemattr?language=objc)
341pub const kSecPublicKeyHashItemAttr: c_uint = 1752198009;
342/// [Apple's documentation](https://developer.apple.com/documentation/security/ksecsubjectkeyidentifieritemattr?language=objc)
343pub const kSecSubjectKeyIdentifierItemAttr: c_uint = 1936419172;
344/// [Apple's documentation](https://developer.apple.com/documentation/security/kseccerttypeitemattr?language=objc)
345pub const kSecCertTypeItemAttr: c_uint = 1668577648;
346/// [Apple's documentation](https://developer.apple.com/documentation/security/kseccertencodingitemattr?language=objc)
347pub const kSecCertEncodingItemAttr: c_uint = 1667591779;
348
349#[cfg(feature = "SecBase")]
350impl SecCertificate {
351    /// Creates a certificate based on the input data, type, and encoding.
352    ///
353    /// Parameter `data`: A pointer to the certificate data.
354    ///
355    /// Parameter `type`: The certificate type as defined in cssmtype.h.
356    ///
357    /// Parameter `encoding`: The certificate encoding as defined in cssmtype.h.
358    ///
359    /// Parameter `certificate`: On return, a reference to the newly created certificate.
360    ///
361    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
362    ///
363    /// This API is deprecated in 10.7  Please use the SecCertificateCreateWithData API instead.
364    ///
365    /// # Safety
366    ///
367    /// - `data` must be a valid pointer.
368    /// - `certificate` must be a valid pointer.
369    #[doc(alias = "SecCertificateCreateFromData")]
370    #[cfg(all(
371        feature = "SecAsn1Types",
372        feature = "SecBase",
373        feature = "cssmconfig",
374        feature = "cssmtype"
375    ))]
376    #[deprecated]
377    #[inline]
378    pub unsafe fn create_from_data(
379        data: NonNull<SecAsn1Item>,
380        r#type: CSSM_CERT_TYPE,
381        encoding: CSSM_CERT_ENCODING,
382        certificate: NonNull<*mut SecCertificate>,
383    ) -> OSStatus {
384        extern "C-unwind" {
385            fn SecCertificateCreateFromData(
386                data: NonNull<SecAsn1Item>,
387                r#type: CSSM_CERT_TYPE,
388                encoding: CSSM_CERT_ENCODING,
389                certificate: NonNull<*mut SecCertificate>,
390            ) -> OSStatus;
391        }
392        unsafe { SecCertificateCreateFromData(data, r#type, encoding, certificate) }
393    }
394
395    /// Adds a certificate to the specified keychain.
396    ///
397    /// Parameter `certificate`: A reference to a certificate.
398    ///
399    /// Parameter `keychain`: A reference to the keychain in which to add the certificate. Pass NULL to add the certificate to the default keychain.
400    ///
401    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
402    ///
403    /// This function is successful only if the certificate was created using the SecCertificateCreateFromData or
404    /// SecCertificateCreateWithData functions, and the certificate has not yet been added to the specified keychain.
405    #[doc(alias = "SecCertificateAddToKeychain")]
406    #[cfg(feature = "SecBase")]
407    #[inline]
408    pub unsafe fn add_to_keychain(&self, keychain: Option<&SecKeychain>) -> OSStatus {
409        extern "C-unwind" {
410            fn SecCertificateAddToKeychain(
411                certificate: &SecCertificate,
412                keychain: Option<&SecKeychain>,
413            ) -> OSStatus;
414        }
415        unsafe { SecCertificateAddToKeychain(self, keychain) }
416    }
417
418    /// Retrieves the data for a given certificate.
419    ///
420    /// Parameter `certificate`: A reference to the certificate from which to retrieve the data.
421    ///
422    /// Parameter `data`: On return, the CSSM_DATA structure pointed to by data is filled in. You must allocate the space for a CSSM_DATA structure before calling this function. This data pointer is only guaranteed to remain valid as long as the certificate remains unchanged and valid.
423    ///
424    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
425    ///
426    /// This API is deprecated in 10.7. Please use the SecCertificateCopyData API instead.
427    ///
428    /// # Safety
429    ///
430    /// `data` must be a valid pointer.
431    #[doc(alias = "SecCertificateGetData")]
432    #[cfg(all(feature = "SecAsn1Types", feature = "SecBase", feature = "cssmtype"))]
433    #[deprecated]
434    #[inline]
435    pub unsafe fn get_data(&self, data: CSSM_DATA_PTR) -> OSStatus {
436        extern "C-unwind" {
437            fn SecCertificateGetData(certificate: &SecCertificate, data: CSSM_DATA_PTR)
438                -> OSStatus;
439        }
440        unsafe { SecCertificateGetData(self, data) }
441    }
442
443    /// Retrieves the type for a given certificate.
444    ///
445    /// Parameter `certificate`: A reference to the certificate from which to obtain the type.
446    ///
447    /// Parameter `certificateType`: On return, the certificate type of the certificate. Certificate types are defined in cssmtype.h.
448    ///
449    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
450    ///
451    /// This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
452    ///
453    /// # Safety
454    ///
455    /// `certificate_type` must be a valid pointer.
456    #[doc(alias = "SecCertificateGetType")]
457    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
458    #[deprecated]
459    #[inline]
460    pub unsafe fn r#type(&self, certificate_type: NonNull<CSSM_CERT_TYPE>) -> OSStatus {
461        extern "C-unwind" {
462            fn SecCertificateGetType(
463                certificate: &SecCertificate,
464                certificate_type: NonNull<CSSM_CERT_TYPE>,
465            ) -> OSStatus;
466        }
467        unsafe { SecCertificateGetType(self, certificate_type) }
468    }
469
470    /// Retrieves the subject name for a given certificate.
471    ///
472    /// Parameter `certificate`: A reference to the certificate from which to obtain the subject name.
473    ///
474    /// Parameter `subject`: On return, a pointer to a CSSM_X509_NAME struct which contains the subject's X.509 name (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
475    ///
476    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
477    ///
478    /// Prior to Mac OS X 10.5, this function did not return any output in the subject parameter. Your code should check the returned pointer value (in addition to the function result) before attempting to use it.
479    /// For example:
480    /// const CSSM_X509_NAME *subject = NULL;
481    /// OSStatus status = SecCertificateGetSubject(certificate,
482    /// &subject
483    /// );
484    /// if ( (status == errSecSuccess)
485    /// &
486    /// &
487    /// (subject != NULL) ) {
488    /// // subject is valid
489    /// }
490    /// This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
491    ///
492    /// # Safety
493    ///
494    /// `subject` must be a valid pointer.
495    #[doc(alias = "SecCertificateGetSubject")]
496    #[cfg(all(
497        feature = "SecAsn1Types",
498        feature = "SecBase",
499        feature = "cssmconfig",
500        feature = "x509defs"
501    ))]
502    #[deprecated]
503    #[inline]
504    pub unsafe fn subject(&self, subject: NonNull<*const CSSM_X509_NAME>) -> OSStatus {
505        extern "C-unwind" {
506            fn SecCertificateGetSubject(
507                certificate: &SecCertificate,
508                subject: NonNull<*const CSSM_X509_NAME>,
509            ) -> OSStatus;
510        }
511        unsafe { SecCertificateGetSubject(self, subject) }
512    }
513
514    /// Retrieves the issuer name for a given certificate.
515    ///
516    /// Parameter `certificate`: A reference to the certificate from which to obtain the issuer name.
517    ///
518    /// Parameter `issuer`: On return, a pointer to a CSSM_X509_NAME struct which contains the issuer's X.509 name (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
519    ///
520    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
521    ///
522    /// Prior to Mac OS X 10.5, this function did not return any output in the issuer parameter. Your code should check the returned pointer value (in addition to the function result) before attempting to use it.
523    /// For example:
524    /// const CSSM_X509_NAME *issuer = NULL;
525    /// OSStatus status = SecCertificateGetIssuer(certificate,
526    /// &issuer
527    /// );
528    /// if ( (status == errSecSuccess)
529    /// &
530    /// &
531    /// (issuer != NULL) ) {
532    /// // issuer is valid
533    /// }
534    /// This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
535    ///
536    /// # Safety
537    ///
538    /// `issuer` must be a valid pointer.
539    #[doc(alias = "SecCertificateGetIssuer")]
540    #[cfg(all(
541        feature = "SecAsn1Types",
542        feature = "SecBase",
543        feature = "cssmconfig",
544        feature = "x509defs"
545    ))]
546    #[deprecated]
547    #[inline]
548    pub unsafe fn issuer(&self, issuer: NonNull<*const CSSM_X509_NAME>) -> OSStatus {
549        extern "C-unwind" {
550            fn SecCertificateGetIssuer(
551                certificate: &SecCertificate,
552                issuer: NonNull<*const CSSM_X509_NAME>,
553            ) -> OSStatus;
554        }
555        unsafe { SecCertificateGetIssuer(self, issuer) }
556    }
557
558    /// Retrieves the certificate library handle for a given certificate.
559    ///
560    /// Parameter `certificate`: A reference to the certificate from which to obtain the certificate library handle.
561    ///
562    /// Parameter `clHandle`: On return, the certificate library handle of the given certificate. This handle remains valid at least as long as the certificate does.
563    ///
564    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
565    ///
566    /// This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
567    ///
568    /// # Safety
569    ///
570    /// `cl_handle` must be a valid pointer.
571    #[doc(alias = "SecCertificateGetCLHandle")]
572    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
573    #[deprecated]
574    #[inline]
575    pub unsafe fn cl_handle(&self, cl_handle: NonNull<CSSM_CL_HANDLE>) -> OSStatus {
576        extern "C-unwind" {
577            fn SecCertificateGetCLHandle(
578                certificate: &SecCertificate,
579                cl_handle: NonNull<CSSM_CL_HANDLE>,
580            ) -> OSStatus;
581        }
582        unsafe { SecCertificateGetCLHandle(self, cl_handle) }
583    }
584
585    /// Retrieves the algorithm identifier for a given certificate.
586    ///
587    /// Parameter `certificate`: A reference to the certificate from which to retrieve the algorithm identifier.
588    ///
589    /// Parameter `algid`: On return, a pointer to a CSSM_X509_ALGORITHM_IDENTIFIER struct which identifies the algorithm for this certificate (x509defs.h). This pointer remains valid until the certificate reference is released. The caller should not attempt to free this pointer.
590    ///
591    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
592    /// discussion This API is deprecated in 10.7. Please use the SecCertificateCopyValues API instead.
593    ///
594    /// # Safety
595    ///
596    /// `algid` must be a valid pointer.
597    #[doc(alias = "SecCertificateGetAlgorithmID")]
598    #[cfg(all(feature = "SecAsn1Types", feature = "SecBase"))]
599    #[deprecated]
600    #[inline]
601    pub unsafe fn algorithm_id(&self, algid: NonNull<*const SecAsn1AlgId>) -> OSStatus {
602        extern "C-unwind" {
603            fn SecCertificateGetAlgorithmID(
604                certificate: &SecCertificate,
605                algid: NonNull<*const SecAsn1AlgId>,
606            ) -> OSStatus;
607        }
608        unsafe { SecCertificateGetAlgorithmID(self, algid) }
609    }
610
611    /// Returns the preferred certificate for the specified name and key usage. If a preferred certificate does not exist for the specified name and key usage, NULL is returned.
612    ///
613    /// Parameter `name`: A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
614    ///
615    /// Parameter `keyUsage`: A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to ignore this parameter.
616    ///
617    /// Parameter `certificate`: On return, a reference to the preferred certificate, or NULL if none was found. You are responsible for releasing this reference by calling the CFRelease function.
618    ///
619    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
620    ///
621    /// This function will typically be used to obtain the preferred encryption certificate for an email recipient.
622    /// This API is deprecated in 10.7. Please use the SecCertificateCopyPreferred API instead.
623    ///
624    /// # Safety
625    ///
626    /// `certificate` must be a valid pointer.
627    #[doc(alias = "SecCertificateCopyPreference")]
628    #[cfg(all(feature = "SecBase", feature = "cssmconfig"))]
629    #[deprecated]
630    #[inline]
631    pub unsafe fn copy_preference(
632        name: &CFString,
633        key_usage: uint32,
634        certificate: NonNull<*mut SecCertificate>,
635    ) -> OSStatus {
636        extern "C-unwind" {
637            fn SecCertificateCopyPreference(
638                name: &CFString,
639                key_usage: uint32,
640                certificate: NonNull<*mut SecCertificate>,
641            ) -> OSStatus;
642        }
643        unsafe { SecCertificateCopyPreference(name, key_usage, certificate) }
644    }
645
646    /// Returns the preferred certificate for the specified name and key usage. If a preferred certificate does not exist for the specified name and key usage, NULL is returned.
647    ///
648    /// Parameter `name`: A string containing an email address (RFC822) or other name for which a preferred certificate is requested.
649    ///
650    /// Parameter `keyUsage`: A CFArrayRef value, containing items defined in SecItem.h  Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
651    ///
652    /// Returns: On return, a reference to the preferred certificate, or NULL if none was found. You are responsible for releasing this reference by calling the CFRelease function.
653    ///
654    /// This function will typically be used to obtain the preferred encryption certificate for an email recipient. If a preferred certificate has not been set
655    /// for the supplied name, the returned reference will be NULL. Your code should then perform a search for possible certificates, using the SecItemCopyMatching API.
656    ///
657    /// # Safety
658    ///
659    /// `key_usage` generic must be of the correct type.
660    #[doc(alias = "SecCertificateCopyPreferred")]
661    #[cfg(feature = "SecBase")]
662    #[inline]
663    pub unsafe fn preferred(
664        name: &CFString,
665        key_usage: Option<&CFArray>,
666    ) -> Option<CFRetained<SecCertificate>> {
667        extern "C-unwind" {
668            fn SecCertificateCopyPreferred(
669                name: &CFString,
670                key_usage: Option<&CFArray>,
671            ) -> Option<NonNull<SecCertificate>>;
672        }
673        let ret = unsafe { SecCertificateCopyPreferred(name, key_usage) };
674        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
675    }
676
677    /// Sets the preferred certificate for a specified name, key usage, and date.
678    ///
679    /// Parameter `certificate`: A reference to the certificate which will be preferred.
680    ///
681    /// Parameter `name`: A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
682    ///
683    /// Parameter `keyUsage`: A CSSM_KEYUSE key usage value, as defined in cssmtype.h. Pass 0 to avoid specifying a particular key usage.
684    ///
685    /// Parameter `date`: (optional) A date reference. If supplied, the preferred certificate will be changed only if this date is later than the currently saved setting. Pass NULL if this preference should not be restricted by date.
686    ///
687    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
688    ///
689    /// This function will typically be used to set the preferred encryption certificate for an email recipient, either manually (when encrypting email to a recipient) or automatically upon receipt of encrypted email.
690    /// This API is deprecated in 10.7. Plese use the SecCertificateSetPreferred API instead.
691    #[doc(alias = "SecCertificateSetPreference")]
692    #[cfg(all(feature = "SecBase", feature = "cssmconfig"))]
693    #[deprecated]
694    #[inline]
695    pub unsafe fn set_preference(
696        &self,
697        name: &CFString,
698        key_usage: uint32,
699        date: Option<&CFDate>,
700    ) -> OSStatus {
701        extern "C-unwind" {
702            fn SecCertificateSetPreference(
703                certificate: &SecCertificate,
704                name: &CFString,
705                key_usage: uint32,
706                date: Option<&CFDate>,
707            ) -> OSStatus;
708        }
709        unsafe { SecCertificateSetPreference(self, name, key_usage, date) }
710    }
711
712    /// Sets the preferred certificate for a specified name and optional key usage.
713    ///
714    /// Parameter `certificate`: A reference to the preferred certificate. If NULL is passed, any existing preference for the specified name is cleared instead.
715    ///
716    /// Parameter `name`: A string containing an email address (RFC822) or other name for which a preferred certificate will be associated.
717    ///
718    /// Parameter `keyUsage`: A CFArrayRef value, containing items defined in SecItem.h  Pass NULL to ignore this parameter. (kSecAttrCanEncrypt, kSecAttrCanDecrypt, kSecAttrCanDerive, kSecAttrCanSign, kSecAttrCanVerify, kSecAttrCanWrap, kSecAttrCanUnwrap)
719    ///
720    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
721    ///
722    /// This function will typically be used to set the preferred encryption certificate for an email recipient, either manually (when encrypting email to a recipient)
723    /// or automatically upon receipt of encrypted email.
724    ///
725    /// # Safety
726    ///
727    /// `key_usage` generic must be of the correct type.
728    #[doc(alias = "SecCertificateSetPreferred")]
729    #[cfg(feature = "SecBase")]
730    #[inline]
731    pub unsafe fn set_preferred(
732        certificate: Option<&SecCertificate>,
733        name: &CFString,
734        key_usage: Option<&CFArray>,
735    ) -> OSStatus {
736        extern "C-unwind" {
737            fn SecCertificateSetPreferred(
738                certificate: Option<&SecCertificate>,
739                name: &CFString,
740                key_usage: Option<&CFArray>,
741            ) -> OSStatus;
742        }
743        unsafe { SecCertificateSetPreferred(certificate, name, key_usage) }
744    }
745}
746
747/// Flags to indicate key usages in the KeyUsage extension of a certificate
748///
749/// See also [Apple's documentation](https://developer.apple.com/documentation/security/seckeyusage?language=objc)
750// NS_OPTIONS
751#[repr(transparent)]
752#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
753pub struct SecKeyUsage(pub u32);
754bitflags::bitflags! {
755    impl SecKeyUsage: u32 {
756        #[doc(alias = "kSecKeyUsageUnspecified")]
757        const Unspecified = 0;
758        #[doc(alias = "kSecKeyUsageDigitalSignature")]
759        const DigitalSignature = 1<<0;
760        #[doc(alias = "kSecKeyUsageNonRepudiation")]
761        const NonRepudiation = 1<<1;
762        #[doc(alias = "kSecKeyUsageContentCommitment")]
763        const ContentCommitment = 1<<1;
764        #[doc(alias = "kSecKeyUsageKeyEncipherment")]
765        const KeyEncipherment = 1<<2;
766        #[doc(alias = "kSecKeyUsageDataEncipherment")]
767        const DataEncipherment = 1<<3;
768        #[doc(alias = "kSecKeyUsageKeyAgreement")]
769        const KeyAgreement = 1<<4;
770        #[doc(alias = "kSecKeyUsageKeyCertSign")]
771        const KeyCertSign = 1<<5;
772        #[doc(alias = "kSecKeyUsageCRLSign")]
773        const CRLSign = 1<<6;
774        #[doc(alias = "kSecKeyUsageEncipherOnly")]
775        const EncipherOnly = 1<<7;
776        #[doc(alias = "kSecKeyUsageDecipherOnly")]
777        const DecipherOnly = 1<<8;
778        #[doc(alias = "kSecKeyUsageCritical")]
779        const Critical = 1<<31;
780        #[doc(alias = "kSecKeyUsageAll")]
781        const All = 0x7FFFFFFF;
782    }
783}
784
785#[cfg(feature = "objc2")]
786unsafe impl Encode for SecKeyUsage {
787    const ENCODING: Encoding = u32::ENCODING;
788}
789
790#[cfg(feature = "objc2")]
791unsafe impl RefEncode for SecKeyUsage {
792    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
793}
794
795extern "C" {
796    /// Constants used to access dictionary entries returned by SecCertificateCopyValues
797    ///
798    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertykeytype?language=objc)
799    pub static kSecPropertyKeyType: &'static CFString;
800}
801
802extern "C" {
803    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertykeylabel?language=objc)
804    pub static kSecPropertyKeyLabel: &'static CFString;
805}
806
807extern "C" {
808    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertykeylocalizedlabel?language=objc)
809    pub static kSecPropertyKeyLocalizedLabel: &'static CFString;
810}
811
812extern "C" {
813    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertykeyvalue?language=objc)
814    pub static kSecPropertyKeyValue: &'static CFString;
815}
816
817extern "C" {
818    /// Public Constants for property list values returned by SecCertificateCopyValues
819    ///
820    /// Note that kSecPropertyTypeTitle and kSecPropertyTypeError are defined in SecTrust.h
821    ///
822    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypewarning?language=objc)
823    pub static kSecPropertyTypeWarning: &'static CFString;
824}
825
826extern "C" {
827    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypesuccess?language=objc)
828    pub static kSecPropertyTypeSuccess: &'static CFString;
829}
830
831extern "C" {
832    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypesection?language=objc)
833    pub static kSecPropertyTypeSection: &'static CFString;
834}
835
836extern "C" {
837    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypedata?language=objc)
838    pub static kSecPropertyTypeData: &'static CFString;
839}
840
841extern "C" {
842    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypestring?language=objc)
843    pub static kSecPropertyTypeString: &'static CFString;
844}
845
846extern "C" {
847    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypeurl?language=objc)
848    pub static kSecPropertyTypeURL: &'static CFString;
849}
850
851extern "C" {
852    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypedate?language=objc)
853    pub static kSecPropertyTypeDate: &'static CFString;
854}
855
856extern "C" {
857    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypearray?language=objc)
858    pub static kSecPropertyTypeArray: &'static CFString;
859}
860
861extern "C" {
862    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypenumber?language=objc)
863    pub static kSecPropertyTypeNumber: &'static CFString;
864}
865
866#[cfg(feature = "SecBase")]
867impl SecCertificate {
868    /// Creates a dictionary that represents a certificate's contents.
869    ///
870    /// Parameter `certificate`: The certificate from which to get values
871    ///
872    /// Parameter `keys`: An array of string OID values, or NULL. If present, this is
873    /// the subset of values from the certificate to return. If NULL,
874    /// all values will be returned. Only OIDs that are top level keys
875    /// in the returned dictionary can be specified. Unknown OIDs are
876    /// ignored.
877    ///
878    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is
879    /// set if an error occurred.  If not NULL the caller is
880    /// responsible for releasing the CFErrorRef.
881    ///
882    /// The keys array will contain all of the keys used in the
883    /// returned dictionary. The top level keys in the returned
884    /// dictionary are OIDs, many of which are found in SecCertificateOIDs.h.
885    /// Each entry that is returned is itself a dictionary with four
886    /// entries, whose keys are kSecPropertyKeyType, kSecPropertyKeyLabel,
887    /// kSecPropertyKeyLocalizedLabel, kSecPropertyKeyValue. The label
888    /// entries may contain a descriptive (localized) string, or an
889    /// OID string. The kSecPropertyKeyType describes the type in the
890    /// value entry. The value entry may be any CFType, although it
891    /// is usually a CFStringRef, CFArrayRef or a CFDictionaryRef.
892    ///
893    /// # Safety
894    ///
895    /// - `keys` generic must be of the correct type.
896    /// - `error` must be a valid pointer or null.
897    #[doc(alias = "SecCertificateCopyValues")]
898    #[cfg(feature = "SecBase")]
899    #[inline]
900    pub unsafe fn values(
901        &self,
902        keys: Option<&CFArray>,
903        error: *mut *mut CFError,
904    ) -> Option<CFRetained<CFDictionary>> {
905        extern "C-unwind" {
906            fn SecCertificateCopyValues(
907                certificate: &SecCertificate,
908                keys: Option<&CFArray>,
909                error: *mut *mut CFError,
910            ) -> Option<NonNull<CFDictionary>>;
911        }
912        let ret = unsafe { SecCertificateCopyValues(self, keys, error) };
913        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
914    }
915
916    /// Return the long description of a certificate
917    ///
918    /// Parameter `alloc`: The CFAllocator which should be used to allocate
919    /// memory for the dictionary and its storage for values. This
920    /// parameter may be NULL in which case the current default
921    /// CFAllocator is used. If this reference is not a valid
922    /// CFAllocator, the behavior is undefined.
923    ///
924    /// Parameter `certificate`: The certificate from which to retrieve the long description
925    ///
926    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is
927    /// set if an error occurred.  If not NULL the caller is
928    /// responsible for releasing the CFErrorRef.
929    ///
930    /// Returns: A CFStringRef of the long description or NULL. If NULL and the error
931    /// parameter is supplied the error will be returned in the error parameter
932    ///
933    /// Note that the format of this string may change in the future
934    ///
935    /// # Safety
936    ///
937    /// `error` must be a valid pointer or null.
938    #[doc(alias = "SecCertificateCopyLongDescription")]
939    #[cfg(feature = "SecBase")]
940    #[inline]
941    pub unsafe fn long_description(
942        alloc: Option<&CFAllocator>,
943        certificate: &SecCertificate,
944        error: *mut *mut CFError,
945    ) -> Option<CFRetained<CFString>> {
946        extern "C-unwind" {
947            fn SecCertificateCopyLongDescription(
948                alloc: Option<&CFAllocator>,
949                certificate: &SecCertificate,
950                error: *mut *mut CFError,
951            ) -> Option<NonNull<CFString>>;
952        }
953        let ret = unsafe { SecCertificateCopyLongDescription(alloc, certificate, error) };
954        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
955    }
956
957    /// Return the short description of a certificate
958    ///
959    /// Parameter `alloc`: The CFAllocator which should be used to allocate
960    /// memory for the dictionary and its storage for values. This
961    /// parameter may be NULL in which case the current default
962    /// CFAllocator is used. If this reference is not a valid
963    /// CFAllocator, the behavior is undefined.
964    ///
965    /// Parameter `certificate`: The certificate from which to retrieve the short description
966    ///
967    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is
968    /// set if an error occurred.  If not NULL the caller is
969    /// responsible for releasing the CFErrorRef.
970    ///
971    /// Returns: A CFStringRef of the short description or NULL. If NULL and the error
972    /// parameter is supplied the error will be returned in the error parameter
973    ///
974    /// Note that the format of this string may change in the future
975    ///
976    /// # Safety
977    ///
978    /// `error` must be a valid pointer or null.
979    #[doc(alias = "SecCertificateCopyShortDescription")]
980    #[cfg(feature = "SecBase")]
981    #[inline]
982    pub unsafe fn short_description(
983        alloc: Option<&CFAllocator>,
984        certificate: &SecCertificate,
985        error: *mut *mut CFError,
986    ) -> Option<CFRetained<CFString>> {
987        extern "C-unwind" {
988            fn SecCertificateCopyShortDescription(
989                alloc: Option<&CFAllocator>,
990                certificate: &SecCertificate,
991                error: *mut *mut CFError,
992            ) -> Option<NonNull<CFString>>;
993        }
994        let ret = unsafe { SecCertificateCopyShortDescription(alloc, certificate, error) };
995        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
996    }
997
998    /// Return the certificate's normalized issuer
999    ///
1000    /// Parameter `certificate`: The certificate from which to get values
1001    ///
1002    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is
1003    /// set if an error occurred.  If not NULL the caller is
1004    /// responsible for releasing the CFErrorRef.
1005    ///
1006    /// The issuer is a sequence in the format used by
1007    /// SecItemCopyMatching.  The content returned is a DER-encoded
1008    /// X.509 distinguished name. For a display version of the issuer,
1009    /// call SecCertificateCopyValues. The caller must CFRelease
1010    /// the value returned.
1011    ///
1012    /// # Safety
1013    ///
1014    /// `error` must be a valid pointer or null.
1015    #[doc(alias = "SecCertificateCopyNormalizedIssuerContent")]
1016    #[cfg(feature = "SecBase")]
1017    #[deprecated = "SecCertificateCopyNormalizedIssuerContent is deprecated. Use SecCertificateCopyNormalizedIssuerSequence instead."]
1018    #[inline]
1019    pub unsafe fn normalized_issuer_content(
1020        &self,
1021        error: *mut *mut CFError,
1022    ) -> Option<CFRetained<CFData>> {
1023        extern "C-unwind" {
1024            fn SecCertificateCopyNormalizedIssuerContent(
1025                certificate: &SecCertificate,
1026                error: *mut *mut CFError,
1027            ) -> Option<NonNull<CFData>>;
1028        }
1029        let ret = unsafe { SecCertificateCopyNormalizedIssuerContent(self, error) };
1030        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1031    }
1032
1033    /// Return the certificate's normalized subject
1034    ///
1035    /// Parameter `certificate`: The certificate from which to get values
1036    ///
1037    /// Parameter `error`: An optional pointer to a CFErrorRef. This value is
1038    /// set if an error occurred.  If not NULL the caller is
1039    /// responsible for releasing the CFErrorRef.
1040    ///
1041    /// The subject is a sequence in the format used by
1042    /// SecItemCopyMatching. The content returned is a DER-encoded
1043    /// X.509 distinguished name. For a display version of the subject,
1044    /// call SecCertificateCopyValues. The caller must CFRelease
1045    /// the value returned.
1046    ///
1047    /// # Safety
1048    ///
1049    /// `error` must be a valid pointer or null.
1050    #[doc(alias = "SecCertificateCopyNormalizedSubjectContent")]
1051    #[cfg(feature = "SecBase")]
1052    #[deprecated = "SecCertificateCopyNormalizedSubjectContent is deprecated. Use SecCertificateCopyNormalizedSubjectSequence instead."]
1053    #[inline]
1054    pub unsafe fn normalized_subject_content(
1055        &self,
1056        error: *mut *mut CFError,
1057    ) -> Option<CFRetained<CFData>> {
1058        extern "C-unwind" {
1059            fn SecCertificateCopyNormalizedSubjectContent(
1060                certificate: &SecCertificate,
1061                error: *mut *mut CFError,
1062            ) -> Option<NonNull<CFData>>;
1063        }
1064        let ret = unsafe { SecCertificateCopyNormalizedSubjectContent(self, error) };
1065        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1066    }
1067}
1068
1069#[cfg(feature = "SecBase")]
1070#[deprecated = "renamed to `SecCertificate::with_data`"]
1071#[inline]
1072pub unsafe extern "C-unwind" fn SecCertificateCreateWithData(
1073    allocator: Option<&CFAllocator>,
1074    data: &CFData,
1075) -> Option<CFRetained<SecCertificate>> {
1076    extern "C-unwind" {
1077        fn SecCertificateCreateWithData(
1078            allocator: Option<&CFAllocator>,
1079            data: &CFData,
1080        ) -> Option<NonNull<SecCertificate>>;
1081    }
1082    let ret = unsafe { SecCertificateCreateWithData(allocator, data) };
1083    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1084}
1085
1086#[cfg(feature = "SecBase")]
1087#[deprecated = "renamed to `SecCertificate::data`"]
1088#[inline]
1089pub unsafe extern "C-unwind" fn SecCertificateCopyData(
1090    certificate: &SecCertificate,
1091) -> CFRetained<CFData> {
1092    extern "C-unwind" {
1093        fn SecCertificateCopyData(certificate: &SecCertificate) -> Option<NonNull<CFData>>;
1094    }
1095    let ret = unsafe { SecCertificateCopyData(certificate) };
1096    let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
1097    unsafe { CFRetained::from_raw(ret) }
1098}
1099
1100#[cfg(feature = "SecBase")]
1101#[deprecated = "renamed to `SecCertificate::subject_summary`"]
1102#[inline]
1103pub unsafe extern "C-unwind" fn SecCertificateCopySubjectSummary(
1104    certificate: &SecCertificate,
1105) -> Option<CFRetained<CFString>> {
1106    extern "C-unwind" {
1107        fn SecCertificateCopySubjectSummary(
1108            certificate: &SecCertificate,
1109        ) -> Option<NonNull<CFString>>;
1110    }
1111    let ret = unsafe { SecCertificateCopySubjectSummary(certificate) };
1112    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1113}
1114
1115extern "C-unwind" {
1116    #[cfg(feature = "SecBase")]
1117    #[deprecated = "renamed to `SecCertificate::copy_common_name`"]
1118    pub fn SecCertificateCopyCommonName(
1119        certificate: &SecCertificate,
1120        common_name: NonNull<*const CFString>,
1121    ) -> OSStatus;
1122}
1123
1124extern "C-unwind" {
1125    #[cfg(feature = "SecBase")]
1126    #[deprecated = "renamed to `SecCertificate::copy_email_addresses`"]
1127    pub fn SecCertificateCopyEmailAddresses(
1128        certificate: &SecCertificate,
1129        email_addresses: NonNull<*const CFArray>,
1130    ) -> OSStatus;
1131}
1132
1133#[cfg(feature = "SecBase")]
1134#[deprecated = "renamed to `SecCertificate::normalized_issuer_sequence`"]
1135#[inline]
1136pub unsafe extern "C-unwind" fn SecCertificateCopyNormalizedIssuerSequence(
1137    certificate: &SecCertificate,
1138) -> Option<CFRetained<CFData>> {
1139    extern "C-unwind" {
1140        fn SecCertificateCopyNormalizedIssuerSequence(
1141            certificate: &SecCertificate,
1142        ) -> Option<NonNull<CFData>>;
1143    }
1144    let ret = unsafe { SecCertificateCopyNormalizedIssuerSequence(certificate) };
1145    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1146}
1147
1148#[cfg(feature = "SecBase")]
1149#[deprecated = "renamed to `SecCertificate::normalized_subject_sequence`"]
1150#[inline]
1151pub unsafe extern "C-unwind" fn SecCertificateCopyNormalizedSubjectSequence(
1152    certificate: &SecCertificate,
1153) -> Option<CFRetained<CFData>> {
1154    extern "C-unwind" {
1155        fn SecCertificateCopyNormalizedSubjectSequence(
1156            certificate: &SecCertificate,
1157        ) -> Option<NonNull<CFData>>;
1158    }
1159    let ret = unsafe { SecCertificateCopyNormalizedSubjectSequence(certificate) };
1160    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1161}
1162
1163#[cfg(feature = "SecBase")]
1164#[deprecated = "renamed to `SecCertificate::key`"]
1165#[inline]
1166pub unsafe extern "C-unwind" fn SecCertificateCopyKey(
1167    certificate: &SecCertificate,
1168) -> Option<CFRetained<SecKey>> {
1169    extern "C-unwind" {
1170        fn SecCertificateCopyKey(certificate: &SecCertificate) -> Option<NonNull<SecKey>>;
1171    }
1172    let ret = unsafe { SecCertificateCopyKey(certificate) };
1173    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1174}
1175
1176extern "C-unwind" {
1177    #[cfg(feature = "SecBase")]
1178    #[deprecated = "renamed to `SecCertificate::copy_public_key`"]
1179    #[cfg_attr(
1180        target_os = "macos",
1181        link_name = "SecCertificateCopyPublicKey$LEGACYMAC"
1182    )]
1183    pub fn SecCertificateCopyPublicKey(
1184        certificate: &SecCertificate,
1185        key: NonNull<*mut SecKey>,
1186    ) -> OSStatus;
1187}
1188
1189#[cfg(feature = "SecBase")]
1190#[deprecated = "renamed to `SecCertificate::serial_number_data`"]
1191#[inline]
1192pub unsafe extern "C-unwind" fn SecCertificateCopySerialNumberData(
1193    certificate: &SecCertificate,
1194    error: *mut *mut CFError,
1195) -> Option<CFRetained<CFData>> {
1196    extern "C-unwind" {
1197        fn SecCertificateCopySerialNumberData(
1198            certificate: &SecCertificate,
1199            error: *mut *mut CFError,
1200        ) -> Option<NonNull<CFData>>;
1201    }
1202    let ret = unsafe { SecCertificateCopySerialNumberData(certificate, error) };
1203    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1204}
1205
1206#[cfg(feature = "SecBase")]
1207#[deprecated = "renamed to `SecCertificate::not_valid_before_date`"]
1208#[inline]
1209pub unsafe extern "C-unwind" fn SecCertificateCopyNotValidBeforeDate(
1210    certificate: &SecCertificate,
1211) -> Option<CFRetained<CFDate>> {
1212    extern "C-unwind" {
1213        fn SecCertificateCopyNotValidBeforeDate(
1214            certificate: &SecCertificate,
1215        ) -> Option<NonNull<CFDate>>;
1216    }
1217    let ret = unsafe { SecCertificateCopyNotValidBeforeDate(certificate) };
1218    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1219}
1220
1221#[cfg(feature = "SecBase")]
1222#[deprecated = "renamed to `SecCertificate::not_valid_after_date`"]
1223#[inline]
1224pub unsafe extern "C-unwind" fn SecCertificateCopyNotValidAfterDate(
1225    certificate: &SecCertificate,
1226) -> Option<CFRetained<CFDate>> {
1227    extern "C-unwind" {
1228        fn SecCertificateCopyNotValidAfterDate(
1229            certificate: &SecCertificate,
1230        ) -> Option<NonNull<CFDate>>;
1231    }
1232    let ret = unsafe { SecCertificateCopyNotValidAfterDate(certificate) };
1233    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1234}
1235
1236#[cfg(feature = "SecBase")]
1237#[deprecated = "renamed to `SecCertificate::serial_number`"]
1238#[inline]
1239pub unsafe extern "C-unwind" fn SecCertificateCopySerialNumber(
1240    certificate: &SecCertificate,
1241    error: *mut *mut CFError,
1242) -> Option<CFRetained<CFData>> {
1243    extern "C-unwind" {
1244        #[cfg_attr(
1245            target_os = "macos",
1246            link_name = "SecCertificateCopySerialNumber$LEGACYMAC"
1247        )]
1248        fn SecCertificateCopySerialNumber(
1249            certificate: &SecCertificate,
1250            error: *mut *mut CFError,
1251        ) -> Option<NonNull<CFData>>;
1252    }
1253    let ret = unsafe { SecCertificateCopySerialNumber(certificate, error) };
1254    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1255}
1256
1257extern "C-unwind" {
1258    #[cfg(all(
1259        feature = "SecAsn1Types",
1260        feature = "SecBase",
1261        feature = "cssmconfig",
1262        feature = "cssmtype"
1263    ))]
1264    #[deprecated = "renamed to `SecCertificate::create_from_data`"]
1265    pub fn SecCertificateCreateFromData(
1266        data: NonNull<SecAsn1Item>,
1267        r#type: CSSM_CERT_TYPE,
1268        encoding: CSSM_CERT_ENCODING,
1269        certificate: NonNull<*mut SecCertificate>,
1270    ) -> OSStatus;
1271}
1272
1273extern "C-unwind" {
1274    #[cfg(feature = "SecBase")]
1275    #[deprecated = "renamed to `SecCertificate::add_to_keychain`"]
1276    pub fn SecCertificateAddToKeychain(
1277        certificate: &SecCertificate,
1278        keychain: Option<&SecKeychain>,
1279    ) -> OSStatus;
1280}
1281
1282extern "C-unwind" {
1283    #[cfg(all(feature = "SecAsn1Types", feature = "SecBase", feature = "cssmtype"))]
1284    #[deprecated = "renamed to `SecCertificate::get_data`"]
1285    pub fn SecCertificateGetData(certificate: &SecCertificate, data: CSSM_DATA_PTR) -> OSStatus;
1286}
1287
1288extern "C-unwind" {
1289    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
1290    #[deprecated = "renamed to `SecCertificate::type`"]
1291    pub fn SecCertificateGetType(
1292        certificate: &SecCertificate,
1293        certificate_type: NonNull<CSSM_CERT_TYPE>,
1294    ) -> OSStatus;
1295}
1296
1297extern "C-unwind" {
1298    #[cfg(all(
1299        feature = "SecAsn1Types",
1300        feature = "SecBase",
1301        feature = "cssmconfig",
1302        feature = "x509defs"
1303    ))]
1304    #[deprecated = "renamed to `SecCertificate::subject`"]
1305    pub fn SecCertificateGetSubject(
1306        certificate: &SecCertificate,
1307        subject: NonNull<*const CSSM_X509_NAME>,
1308    ) -> OSStatus;
1309}
1310
1311extern "C-unwind" {
1312    #[cfg(all(
1313        feature = "SecAsn1Types",
1314        feature = "SecBase",
1315        feature = "cssmconfig",
1316        feature = "x509defs"
1317    ))]
1318    #[deprecated = "renamed to `SecCertificate::issuer`"]
1319    pub fn SecCertificateGetIssuer(
1320        certificate: &SecCertificate,
1321        issuer: NonNull<*const CSSM_X509_NAME>,
1322    ) -> OSStatus;
1323}
1324
1325extern "C-unwind" {
1326    #[cfg(all(feature = "SecBase", feature = "cssmconfig", feature = "cssmtype"))]
1327    #[deprecated = "renamed to `SecCertificate::cl_handle`"]
1328    pub fn SecCertificateGetCLHandle(
1329        certificate: &SecCertificate,
1330        cl_handle: NonNull<CSSM_CL_HANDLE>,
1331    ) -> OSStatus;
1332}
1333
1334extern "C-unwind" {
1335    #[cfg(all(feature = "SecAsn1Types", feature = "SecBase"))]
1336    #[deprecated = "renamed to `SecCertificate::algorithm_id`"]
1337    pub fn SecCertificateGetAlgorithmID(
1338        certificate: &SecCertificate,
1339        algid: NonNull<*const SecAsn1AlgId>,
1340    ) -> OSStatus;
1341}
1342
1343extern "C-unwind" {
1344    #[cfg(all(feature = "SecBase", feature = "cssmconfig"))]
1345    #[deprecated = "renamed to `SecCertificate::copy_preference`"]
1346    pub fn SecCertificateCopyPreference(
1347        name: &CFString,
1348        key_usage: uint32,
1349        certificate: NonNull<*mut SecCertificate>,
1350    ) -> OSStatus;
1351}
1352
1353#[cfg(feature = "SecBase")]
1354#[deprecated = "renamed to `SecCertificate::preferred`"]
1355#[inline]
1356pub unsafe extern "C-unwind" fn SecCertificateCopyPreferred(
1357    name: &CFString,
1358    key_usage: Option<&CFArray>,
1359) -> Option<CFRetained<SecCertificate>> {
1360    extern "C-unwind" {
1361        fn SecCertificateCopyPreferred(
1362            name: &CFString,
1363            key_usage: Option<&CFArray>,
1364        ) -> Option<NonNull<SecCertificate>>;
1365    }
1366    let ret = unsafe { SecCertificateCopyPreferred(name, key_usage) };
1367    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1368}
1369
1370extern "C-unwind" {
1371    #[cfg(all(feature = "SecBase", feature = "cssmconfig"))]
1372    #[deprecated = "renamed to `SecCertificate::set_preference`"]
1373    pub fn SecCertificateSetPreference(
1374        certificate: &SecCertificate,
1375        name: &CFString,
1376        key_usage: uint32,
1377        date: Option<&CFDate>,
1378    ) -> OSStatus;
1379}
1380
1381extern "C-unwind" {
1382    #[cfg(feature = "SecBase")]
1383    #[deprecated = "renamed to `SecCertificate::set_preferred`"]
1384    pub fn SecCertificateSetPreferred(
1385        certificate: Option<&SecCertificate>,
1386        name: &CFString,
1387        key_usage: Option<&CFArray>,
1388    ) -> OSStatus;
1389}
1390
1391#[cfg(feature = "SecBase")]
1392#[deprecated = "renamed to `SecCertificate::values`"]
1393#[inline]
1394pub unsafe extern "C-unwind" fn SecCertificateCopyValues(
1395    certificate: &SecCertificate,
1396    keys: Option<&CFArray>,
1397    error: *mut *mut CFError,
1398) -> Option<CFRetained<CFDictionary>> {
1399    extern "C-unwind" {
1400        fn SecCertificateCopyValues(
1401            certificate: &SecCertificate,
1402            keys: Option<&CFArray>,
1403            error: *mut *mut CFError,
1404        ) -> Option<NonNull<CFDictionary>>;
1405    }
1406    let ret = unsafe { SecCertificateCopyValues(certificate, keys, error) };
1407    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1408}
1409
1410#[cfg(feature = "SecBase")]
1411#[deprecated = "renamed to `SecCertificate::long_description`"]
1412#[inline]
1413pub unsafe extern "C-unwind" fn SecCertificateCopyLongDescription(
1414    alloc: Option<&CFAllocator>,
1415    certificate: &SecCertificate,
1416    error: *mut *mut CFError,
1417) -> Option<CFRetained<CFString>> {
1418    extern "C-unwind" {
1419        fn SecCertificateCopyLongDescription(
1420            alloc: Option<&CFAllocator>,
1421            certificate: &SecCertificate,
1422            error: *mut *mut CFError,
1423        ) -> Option<NonNull<CFString>>;
1424    }
1425    let ret = unsafe { SecCertificateCopyLongDescription(alloc, certificate, error) };
1426    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1427}
1428
1429#[cfg(feature = "SecBase")]
1430#[deprecated = "renamed to `SecCertificate::short_description`"]
1431#[inline]
1432pub unsafe extern "C-unwind" fn SecCertificateCopyShortDescription(
1433    alloc: Option<&CFAllocator>,
1434    certificate: &SecCertificate,
1435    error: *mut *mut CFError,
1436) -> Option<CFRetained<CFString>> {
1437    extern "C-unwind" {
1438        fn SecCertificateCopyShortDescription(
1439            alloc: Option<&CFAllocator>,
1440            certificate: &SecCertificate,
1441            error: *mut *mut CFError,
1442        ) -> Option<NonNull<CFString>>;
1443    }
1444    let ret = unsafe { SecCertificateCopyShortDescription(alloc, certificate, error) };
1445    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1446}
1447
1448#[cfg(feature = "SecBase")]
1449#[deprecated = "renamed to `SecCertificate::normalized_issuer_content`"]
1450#[inline]
1451pub unsafe extern "C-unwind" fn SecCertificateCopyNormalizedIssuerContent(
1452    certificate: &SecCertificate,
1453    error: *mut *mut CFError,
1454) -> Option<CFRetained<CFData>> {
1455    extern "C-unwind" {
1456        fn SecCertificateCopyNormalizedIssuerContent(
1457            certificate: &SecCertificate,
1458            error: *mut *mut CFError,
1459        ) -> Option<NonNull<CFData>>;
1460    }
1461    let ret = unsafe { SecCertificateCopyNormalizedIssuerContent(certificate, error) };
1462    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1463}
1464
1465#[cfg(feature = "SecBase")]
1466#[deprecated = "renamed to `SecCertificate::normalized_subject_content`"]
1467#[inline]
1468pub unsafe extern "C-unwind" fn SecCertificateCopyNormalizedSubjectContent(
1469    certificate: &SecCertificate,
1470    error: *mut *mut CFError,
1471) -> Option<CFRetained<CFData>> {
1472    extern "C-unwind" {
1473        fn SecCertificateCopyNormalizedSubjectContent(
1474            certificate: &SecCertificate,
1475            error: *mut *mut CFError,
1476        ) -> Option<NonNull<CFData>>;
1477    }
1478    let ret = unsafe { SecCertificateCopyNormalizedSubjectContent(certificate, error) };
1479    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1480}