objc2_security/generated/
SecTrust.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// Specifies the trust result type.
14///
15/// SecTrustResultType results have two dimensions.  They specify
16/// both whether evaluation succeeded and whether this is because of a user
17/// decision.  The commonly expected result is kSecTrustResultUnspecified,
18/// which indicates a positive result that wasn't decided by the user.  The
19/// common failure is kSecTrustResultRecoverableTrustFailure, which means a
20/// negative result.  kSecTrustResultProceed and kSecTrustResultDeny are the
21/// positive and negative result respectively when decided by the user.  User
22/// decisions are persisted through the use of SecTrustCopyExceptions() and
23/// SecTrustSetExceptions().  Finally, kSecTrustResultFatalTrustFailure is a
24/// negative result that must not be circumvented.
25///
26/// This result usually means that SecTrustEvaluate has not yet been called.
27///
28/// may be returned by the SecTrustEvaluate function or stored as part of
29/// the user trust settings.
30///
31/// is required before proceeding.  Important: this value is no longer returned
32/// or supported by SecTrustEvaluate or the SecTrustSettings API starting in
33/// OS X 10.5; its use is deprecated in OS X 10.9 and later, as well as in iOS.
34///
35/// proceed. This value may be returned by the SecTrustEvaluate function
36/// or stored as part of the user trust settings.
37///
38/// and the certificate is implicitly trusted, but user intent was not
39/// explicitly specified.  This value may be returned by the SecTrustEvaluate
40/// function or stored as part of the user trust settings.
41///
42/// failure which can be overridden by the user.  This value may be returned
43/// by the SecTrustEvaluate function but not stored as part of the user
44/// trust settings.
45///
46/// which cannot be overridden by the user.  This value may be returned by the
47/// SecTrustEvaluate function but not stored as part of the user trust
48/// settings.
49///
50/// of trust evaluation. This value may be returned by the SecTrustEvaluate
51/// function but not stored as part of the user trust settings.
52///
53/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrustresulttype?language=objc)
54// NS_ENUM
55#[repr(transparent)]
56#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
57pub struct SecTrustResultType(pub u32);
58impl SecTrustResultType {
59    #[doc(alias = "kSecTrustResultInvalid")]
60    pub const Invalid: Self = Self(0);
61    #[doc(alias = "kSecTrustResultProceed")]
62    pub const Proceed: Self = Self(1);
63    #[doc(alias = "kSecTrustResultConfirm")]
64    #[deprecated]
65    pub const Confirm: Self = Self(2);
66    #[doc(alias = "kSecTrustResultDeny")]
67    pub const Deny: Self = Self(3);
68    #[doc(alias = "kSecTrustResultUnspecified")]
69    pub const Unspecified: Self = Self(4);
70    #[doc(alias = "kSecTrustResultRecoverableTrustFailure")]
71    pub const RecoverableTrustFailure: Self = Self(5);
72    #[doc(alias = "kSecTrustResultFatalTrustFailure")]
73    pub const FatalTrustFailure: Self = Self(6);
74    #[doc(alias = "kSecTrustResultOtherError")]
75    pub const OtherError: Self = Self(7);
76}
77
78#[cfg(feature = "objc2")]
79unsafe impl Encode for SecTrustResultType {
80    const ENCODING: Encoding = u32::ENCODING;
81}
82
83#[cfg(feature = "objc2")]
84unsafe impl RefEncode for SecTrustResultType {
85    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
86}
87
88/// CFType used for performing X.509 certificate trust evaluations.
89///
90/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrust?language=objc)
91#[doc(alias = "SecTrustRef")]
92#[repr(C)]
93pub struct SecTrust {
94    inner: [u8; 0],
95    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
96}
97
98cf_type!(
99    unsafe impl SecTrust {}
100);
101#[cfg(feature = "objc2")]
102cf_objc2_type!(
103    unsafe impl RefEncode<"__SecTrust"> for SecTrust {}
104);
105
106extern "C" {
107    /// Predefined key constants used to obtain values in a
108    /// per-certificate dictionary of trust evaluation results,
109    /// as retrieved from a call to SecTrustCopyProperties.
110    ///
111    /// CFStringRef containing the title (display name) of this certificate.
112    ///
113    /// CFStringRef containing the reason for a trust evaluation failure.
114    ///
115    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypetitle?language=objc)
116    pub static kSecPropertyTypeTitle: &'static CFString;
117}
118
119extern "C" {
120    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksecpropertytypeerror?language=objc)
121    pub static kSecPropertyTypeError: &'static CFString;
122}
123
124extern "C" {
125    /// Predefined key constants used to obtain values in a
126    /// dictionary of trust evaluation results for a certificate chain,
127    /// as retrieved from a call to SecTrustCopyResult.
128    ///
129    /// This key will be present if a trust evaluation has been performed
130    /// and results are available. Its value is a CFDateRef representing
131    /// when the evaluation for this trust object took place.
132    ///
133    /// This key will be present and have a value of kCFBooleanTrue
134    /// if this chain was validated for EV.
135    ///
136    /// Organization name field of subject of leaf certificate. This
137    /// field is meant to be displayed to the user as the validated
138    /// name of the company or entity that owns the certificate if the
139    /// kSecTrustExtendedValidation key is present.
140    ///
141    /// This key will be present and have a value of CFStringRef if
142    /// the leaf certificate contains qualified certificate statements.
143    /// The string can be displayed to the user as a representation
144    /// of a qualified certificate's purpose.
145    ///
146    /// This key will be present and have a value of kCFBooleanTrue
147    /// if this chain was successfully validated as a Qualified Website
148    /// Authentication Certificate.
149    ///
150    /// This key will be present if a trust evaluation has been performed.
151    /// Its value is a CFNumberRef representing the SecTrustResultType result
152    /// for the evaluation.
153    ///
154    /// This key will be present iff this chain had its revocation checked.
155    /// The value will be a kCFBooleanTrue if revocation checking was
156    /// successful and none of the certificates in the chain were revoked.
157    /// The value will be kCFBooleanFalse if no current revocation status
158    /// could be obtained for one or more certificates in the chain due
159    /// to connection problems or timeouts.  This is a hint to a client
160    /// to retry revocation checking at a later time.
161    ///
162    /// This key will be present iff kSecTrustRevocationChecked has a
163    /// value of kCFBooleanTrue. The value will be a CFDateRef representing
164    /// the earliest date at which the revocation info for one of the
165    /// certificates in this chain might change.
166    ///
167    /// This key will be present and have a value of kCFBooleanTrue
168    /// if this chain is CT qualified.
169    ///
170    /// This key will be present and have a value of kCFBooleanTrue
171    /// if this chain is EV, but not CT qualified, and is permitted
172    /// as an exception to CT policy requirements.
173    /// Note: in macOS 10.12 and iOS 10, previously-issued EV certificates
174    /// were considered exempt from the CT requirement. As those certificates
175    /// expired, exempting them was no longer needed. This key is deprecated
176    /// in macOS 10.13 and iOS 11, and is no longer returned in the trust
177    /// results dictionary as of those releases.
178    ///
179    /// See also [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustevaluationdate?language=objc)
180    pub static kSecTrustEvaluationDate: &'static CFString;
181}
182
183extern "C" {
184    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustextendedvalidation?language=objc)
185    pub static kSecTrustExtendedValidation: &'static CFString;
186}
187
188extern "C" {
189    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustorganizationname?language=objc)
190    pub static kSecTrustOrganizationName: &'static CFString;
191}
192
193extern "C" {
194    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustresultvalue?language=objc)
195    pub static kSecTrustResultValue: &'static CFString;
196}
197
198extern "C" {
199    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustrevocationchecked?language=objc)
200    pub static kSecTrustRevocationChecked: &'static CFString;
201}
202
203extern "C" {
204    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustrevocationvaliduntildate?language=objc)
205    pub static kSecTrustRevocationValidUntilDate: &'static CFString;
206}
207
208extern "C" {
209    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustcertificatetransparency?language=objc)
210    pub static kSecTrustCertificateTransparency: &'static CFString;
211}
212
213extern "C" {
214    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustcertificatetransparencywhitelist?language=objc)
215    #[deprecated]
216    pub static kSecTrustCertificateTransparencyWhiteList: &'static CFString;
217}
218
219extern "C" {
220    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustqcstatements?language=objc)
221    pub static kSecTrustQCStatements: &'static CFString;
222}
223
224extern "C" {
225    /// [Apple's documentation](https://developer.apple.com/documentation/security/ksectrustqwacvalidation?language=objc)
226    pub static kSecTrustQWACValidation: &'static CFString;
227}
228
229/// Delivers the result from an asynchronous trust evaluation.
230///
231/// Parameter `trustRef`: A reference to the trust object which has been evaluated.
232///
233/// Parameter `trustResult`: The trust result of the evaluation. Additional status
234/// information can be obtained by calling SecTrustCopyProperties().
235///
236/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrustcallback?language=objc)
237#[cfg(feature = "block2")]
238pub type SecTrustCallback = *mut block2::DynBlock<dyn Fn(NonNull<SecTrust>, SecTrustResultType)>;
239
240unsafe impl ConcreteType for SecTrust {
241    /// Returns the type identifier of SecTrust instances.
242    ///
243    /// Returns: The CFTypeID of SecTrust instances.
244    #[doc(alias = "SecTrustGetTypeID")]
245    #[inline]
246    fn type_id() -> CFTypeID {
247        extern "C-unwind" {
248            fn SecTrustGetTypeID() -> CFTypeID;
249        }
250        unsafe { SecTrustGetTypeID() }
251    }
252}
253
254impl SecTrust {
255    /// Creates a trust object based on the given certificates and
256    /// policies.
257    ///
258    /// Parameter `certificates`: The group of certificates to verify.  This can either
259    /// be a CFArrayRef of SecCertificateRef objects or a single SecCertificateRef
260    ///
261    /// Parameter `policies`: An array of one or more policies. You may pass a
262    /// SecPolicyRef to represent a single policy.
263    ///
264    /// Parameter `trust`: On return, a pointer to the trust management reference.
265    ///
266    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
267    ///
268    /// If multiple policies are passed in, all policies must verify
269    /// for the chain to be considered valid.
270    ///
271    /// # Safety
272    ///
273    /// - `certificates` should be of the correct type.
274    /// - `policies` should be of the correct type.
275    /// - `trust` must be a valid pointer.
276    #[doc(alias = "SecTrustCreateWithCertificates")]
277    #[inline]
278    pub unsafe fn create_with_certificates(
279        certificates: &CFType,
280        policies: Option<&CFType>,
281        trust: NonNull<*mut SecTrust>,
282    ) -> OSStatus {
283        extern "C-unwind" {
284            fn SecTrustCreateWithCertificates(
285                certificates: &CFType,
286                policies: Option<&CFType>,
287                trust: NonNull<*mut SecTrust>,
288            ) -> OSStatus;
289        }
290        unsafe { SecTrustCreateWithCertificates(certificates, policies, trust) }
291    }
292
293    /// Set the policies for which trust should be verified.
294    ///
295    /// Parameter `trust`: A trust reference.
296    ///
297    /// Parameter `policies`: An array of one or more policies. You may pass a
298    /// SecPolicyRef to represent a single policy.
299    ///
300    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
301    ///
302    /// This function will invalidate the existing trust result,
303    /// requiring a fresh evaluation for the newly-set policies.
304    ///
305    /// # Safety
306    ///
307    /// `policies` should be of the correct type.
308    #[doc(alias = "SecTrustSetPolicies")]
309    #[inline]
310    pub unsafe fn set_policies(&self, policies: &CFType) -> OSStatus {
311        extern "C-unwind" {
312            fn SecTrustSetPolicies(trust: &SecTrust, policies: &CFType) -> OSStatus;
313        }
314        unsafe { SecTrustSetPolicies(self, policies) }
315    }
316
317    /// Returns an array of policies used for this evaluation.
318    ///
319    /// Parameter `trust`: A reference to a trust object.
320    ///
321    /// Parameter `policies`: On return, an array of policies used by this trust.
322    /// Call the CFRelease function to release this reference.
323    ///
324    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
325    ///
326    /// # Safety
327    ///
328    /// `policies` must be a valid pointer.
329    #[doc(alias = "SecTrustCopyPolicies")]
330    #[inline]
331    pub unsafe fn copy_policies(&self, policies: NonNull<*const CFArray>) -> OSStatus {
332        extern "C-unwind" {
333            fn SecTrustCopyPolicies(
334                trust: &SecTrust,
335                policies: NonNull<*const CFArray>,
336            ) -> OSStatus;
337        }
338        unsafe { SecTrustCopyPolicies(self, policies) }
339    }
340
341    /// Specifies whether a trust evaluation is permitted to fetch missing
342    /// intermediate certificates from the network.
343    ///
344    /// Parameter `trust`: A trust reference.
345    ///
346    /// Parameter `allowFetch`: If true, and a certificate's issuer is not present in the
347    /// trust reference but its network location is known, the evaluation is permitted
348    /// to attempt to download it automatically. Pass false to disable network fetch
349    /// for this trust evaluation.
350    ///
351    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
352    ///
353    /// By default, network fetch of missing certificates is enabled if
354    /// the trust evaluation includes the SSL policy, otherwise it is disabled.
355    #[doc(alias = "SecTrustSetNetworkFetchAllowed")]
356    #[inline]
357    pub unsafe fn set_network_fetch_allowed(&self, allow_fetch: bool) -> OSStatus {
358        extern "C-unwind" {
359            fn SecTrustSetNetworkFetchAllowed(trust: &SecTrust, allow_fetch: Boolean) -> OSStatus;
360        }
361        unsafe { SecTrustSetNetworkFetchAllowed(self, allow_fetch as _) }
362    }
363
364    /// Returns whether a trust evaluation is permitted to fetch missing
365    /// intermediate certificates from the network.
366    ///
367    /// Parameter `trust`: A trust reference.
368    ///
369    /// Parameter `allowFetch`: On return, the boolean pointed to by this parameter is
370    /// set to true if the evaluation is permitted to download missing certificates.
371    ///
372    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
373    ///
374    /// By default, network fetch of missing certificates is enabled if
375    /// the trust evaluation includes the SSL policy, otherwise it is disabled.
376    ///
377    /// # Safety
378    ///
379    /// `allow_fetch` must be a valid pointer.
380    #[doc(alias = "SecTrustGetNetworkFetchAllowed")]
381    #[inline]
382    pub unsafe fn network_fetch_allowed(&self, allow_fetch: NonNull<Boolean>) -> OSStatus {
383        extern "C-unwind" {
384            fn SecTrustGetNetworkFetchAllowed(
385                trust: &SecTrust,
386                allow_fetch: NonNull<Boolean>,
387            ) -> OSStatus;
388        }
389        unsafe { SecTrustGetNetworkFetchAllowed(self, allow_fetch) }
390    }
391
392    /// Sets the anchor certificates for a given trust.
393    ///
394    /// Parameter `trust`: A reference to a trust object.
395    ///
396    /// Parameter `anchorCertificates`: An array of anchor certificates.
397    /// Pass NULL to restore the default set of anchor certificates.
398    ///
399    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
400    ///
401    /// Calling this function without also calling
402    /// SecTrustSetAnchorCertificatesOnly() will disable trusting any
403    /// anchors other than the ones in anchorCertificates.
404    ///
405    /// # Safety
406    ///
407    /// `anchor_certificates` generic must be of the correct type.
408    #[doc(alias = "SecTrustSetAnchorCertificates")]
409    #[inline]
410    pub unsafe fn set_anchor_certificates(
411        &self,
412        anchor_certificates: Option<&CFArray>,
413    ) -> OSStatus {
414        extern "C-unwind" {
415            fn SecTrustSetAnchorCertificates(
416                trust: &SecTrust,
417                anchor_certificates: Option<&CFArray>,
418            ) -> OSStatus;
419        }
420        unsafe { SecTrustSetAnchorCertificates(self, anchor_certificates) }
421    }
422
423    /// Reenables trusting anchor certificates in addition to those
424    /// passed in via the SecTrustSetAnchorCertificates API.
425    ///
426    /// Parameter `trust`: A reference to a trust object.
427    ///
428    /// Parameter `anchorCertificatesOnly`: If true, disables trusting any anchors other
429    /// than the ones passed in via SecTrustSetAnchorCertificates().  If false,
430    /// the built in anchor certificates are also trusted.
431    ///
432    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
433    #[doc(alias = "SecTrustSetAnchorCertificatesOnly")]
434    #[inline]
435    pub unsafe fn set_anchor_certificates_only(&self, anchor_certificates_only: bool) -> OSStatus {
436        extern "C-unwind" {
437            fn SecTrustSetAnchorCertificatesOnly(
438                trust: &SecTrust,
439                anchor_certificates_only: Boolean,
440            ) -> OSStatus;
441        }
442        unsafe { SecTrustSetAnchorCertificatesOnly(self, anchor_certificates_only as _) }
443    }
444
445    /// Returns an array of custom anchor certificates used by a given
446    /// trust, as set by a prior call to SecTrustSetAnchorCertificates, or NULL if
447    /// no custom anchors have been specified.
448    ///
449    /// Parameter `trust`: A reference to a trust object.
450    ///
451    /// Parameter `anchors`: On return, an array of custom anchor certificates (roots)
452    /// used by this trust, or NULL if no custom anchors have been specified. Call
453    /// the CFRelease function to release this reference.
454    ///
455    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
456    ///
457    /// # Safety
458    ///
459    /// `anchors` must be a valid pointer.
460    #[doc(alias = "SecTrustCopyCustomAnchorCertificates")]
461    #[inline]
462    pub unsafe fn copy_custom_anchor_certificates(
463        &self,
464        anchors: NonNull<*const CFArray>,
465    ) -> OSStatus {
466        extern "C-unwind" {
467            fn SecTrustCopyCustomAnchorCertificates(
468                trust: &SecTrust,
469                anchors: NonNull<*const CFArray>,
470            ) -> OSStatus;
471        }
472        unsafe { SecTrustCopyCustomAnchorCertificates(self, anchors) }
473    }
474
475    /// Set the date for which the trust should be verified.
476    ///
477    /// Parameter `trust`: A reference to a trust object.
478    ///
479    /// Parameter `verifyDate`: The date for which to verify trust.
480    ///
481    /// Returns: A result code.  See "Security Error Codes" (SecBase.h).
482    ///
483    /// This function lets you evaluate certificate validity for a
484    /// given date (for example, to determine if a signature was valid on the date
485    /// it was signed, even if the certificate has since expired.) If this function
486    /// is not called, the time at which SecTrustEvaluate() is called is used
487    /// implicitly as the verification time.
488    #[doc(alias = "SecTrustSetVerifyDate")]
489    #[inline]
490    pub unsafe fn set_verify_date(&self, verify_date: &CFDate) -> OSStatus {
491        extern "C-unwind" {
492            fn SecTrustSetVerifyDate(trust: &SecTrust, verify_date: &CFDate) -> OSStatus;
493        }
494        unsafe { SecTrustSetVerifyDate(self, verify_date) }
495    }
496
497    /// Returns the verify time.
498    ///
499    /// Parameter `trust`: A reference to the trust object being verified.
500    ///
501    /// Returns: A CFAbsoluteTime value representing the time at which certificates
502    /// should be checked for validity.
503    ///
504    /// This function retrieves the verification time for the given
505    /// trust reference, as set by a prior call to SecTrustSetVerifyDate(). If the
506    /// verification time has not been set, this function returns a value of 0,
507    /// indicating that the current date/time is implicitly used for verification.
508    #[doc(alias = "SecTrustGetVerifyTime")]
509    #[inline]
510    pub unsafe fn verify_time(&self) -> CFAbsoluteTime {
511        extern "C-unwind" {
512            fn SecTrustGetVerifyTime(trust: &SecTrust) -> CFAbsoluteTime;
513        }
514        unsafe { SecTrustGetVerifyTime(self) }
515    }
516
517    /// Evaluates a trust reference synchronously.
518    ///
519    /// Parameter `trust`: A reference to the trust object to evaluate.
520    ///
521    /// Parameter `result`: A pointer to a result type.
522    ///
523    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
524    ///
525    /// This function will completely evaluate trust before returning,
526    /// possibly including network access to fetch intermediate certificates or to
527    /// perform revocation checking. Since this function can block during those
528    /// operations, you should call it from within a function that is placed on a
529    /// dispatch queue, or in a separate thread from your application's main
530    /// run loop. Alternatively, you can use the SecTrustEvaluateAsync function.
531    ///
532    /// # Safety
533    ///
534    /// `result` must be a valid pointer.
535    #[doc(alias = "SecTrustEvaluate")]
536    #[deprecated]
537    #[inline]
538    pub unsafe fn evaluate(&self, result: NonNull<SecTrustResultType>) -> OSStatus {
539        extern "C-unwind" {
540            fn SecTrustEvaluate(trust: &SecTrust, result: NonNull<SecTrustResultType>) -> OSStatus;
541        }
542        unsafe { SecTrustEvaluate(self, result) }
543    }
544
545    /// Evaluates a trust reference synchronously.
546    ///
547    /// Parameter `trust`: A reference to the trust object to evaluate.
548    ///
549    /// Parameter `error`: A pointer to an error object
550    ///
551    /// Returns: A boolean value indicating whether the certificate is trusted
552    ///
553    /// This function will completely evaluate trust before returning,
554    /// possibly including network access to fetch intermediate certificates or to
555    /// perform revocation checking. Since this function can block during those
556    /// operations, you should call it from within a function that is placed on a
557    /// dispatch queue, or in a separate thread from your application's main
558    /// run loop.
559    /// If the certificate is trusted and the result is true, the error will be set to NULL.
560    /// If the certificate is not trusted or the evaluation was unable to complete, the result
561    /// will be false and the error will be set with a description of the failure.
562    /// The error contains a code for the most serious error encountered (if multiple trust
563    /// failures occurred). The localized description indicates the certificate with the most
564    /// serious problem and the type of error. The underlying error contains a localized
565    /// description of each certificate in the chain that had an error and all errors found
566    /// with that certificate.
567    ///
568    /// # Safety
569    ///
570    /// `error` must be a valid pointer or null.
571    #[doc(alias = "SecTrustEvaluateWithError")]
572    #[must_use]
573    #[inline]
574    pub unsafe fn evaluate_with_error(&self, error: *mut *mut CFError) -> bool {
575        extern "C-unwind" {
576            fn SecTrustEvaluateWithError(trust: &SecTrust, error: *mut *mut CFError) -> bool;
577        }
578        unsafe { SecTrustEvaluateWithError(self, error) }
579    }
580}
581
582/// Delivers the result from an asynchronous trust evaluation.
583///
584/// Parameter `trustRef`: A reference to the trust object which has been evaluated.
585///
586/// Parameter `result`: A boolean value indicating whether the certificate is trusted.
587///
588/// Parameter `error`: An error if the trust evaluation failed.
589///
590/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrustwitherrorcallback?language=objc)
591#[cfg(feature = "block2")]
592pub type SecTrustWithErrorCallback =
593    *mut block2::DynBlock<dyn Fn(NonNull<SecTrust>, bool, *mut CFError)>;
594
595impl SecTrust {
596    /// Parameter `trust`: A reference to a trust object.
597    ///
598    /// Parameter `result`: A pointer to the result from the most recent call to
599    /// SecTrustEvaluate for this trust reference. If SecTrustEvaluate has not been
600    /// called or trust parameters have changed, the result is kSecTrustResultInvalid.
601    ///
602    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
603    ///
604    /// This function replaces SecTrustGetResult for the purpose of
605    /// obtaining the current evaluation result of a given trust reference.
606    ///
607    /// # Safety
608    ///
609    /// `result` must be a valid pointer.
610    #[doc(alias = "SecTrustGetTrustResult")]
611    #[inline]
612    pub unsafe fn trust_result(&self, result: NonNull<SecTrustResultType>) -> OSStatus {
613        extern "C-unwind" {
614            fn SecTrustGetTrustResult(
615                trust: &SecTrust,
616                result: NonNull<SecTrustResultType>,
617            ) -> OSStatus;
618        }
619        unsafe { SecTrustGetTrustResult(self, result) }
620    }
621
622    /// Return the public key for a leaf certificate after it has
623    /// been evaluated.
624    ///
625    /// Parameter `trust`: A reference to the trust object which has been evaluated.
626    ///
627    /// Returns: The certificate's public key, or NULL if it the public key could
628    /// not be extracted (this can happen if the public key algorithm is not
629    /// supported).  The caller is responsible for calling CFRelease on the
630    /// returned key when it is no longer needed.
631    #[doc(alias = "SecTrustCopyPublicKey")]
632    #[cfg(feature = "SecBase")]
633    #[deprecated]
634    #[inline]
635    pub unsafe fn public_key(&self) -> Option<CFRetained<SecKey>> {
636        extern "C-unwind" {
637            fn SecTrustCopyPublicKey(trust: &SecTrust) -> Option<NonNull<SecKey>>;
638        }
639        let ret = unsafe { SecTrustCopyPublicKey(self) };
640        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
641    }
642
643    /// Return the public key for a leaf certificate after it has
644    /// been evaluated.
645    ///
646    /// Parameter `trust`: A reference to the trust object which has been evaluated.
647    ///
648    /// Returns: The certificate's public key, or NULL if it the public key could
649    /// not be extracted (this can happen if the public key algorithm is not
650    /// supported).  The caller is responsible for calling CFRelease on the
651    /// returned key when it is no longer needed.
652    ///
653    /// RSA and ECDSA public keys are supported. All other public key algorithms are unsupported.
654    #[doc(alias = "SecTrustCopyKey")]
655    #[cfg(feature = "SecBase")]
656    #[inline]
657    pub unsafe fn key(&self) -> Option<CFRetained<SecKey>> {
658        extern "C-unwind" {
659            fn SecTrustCopyKey(trust: &SecTrust) -> Option<NonNull<SecKey>>;
660        }
661        let ret = unsafe { SecTrustCopyKey(self) };
662        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
663    }
664
665    /// Returns the number of certificates in an evaluated certificate
666    /// chain.
667    ///
668    /// Parameter `trust`: A reference to a trust object.
669    ///
670    /// Returns: The number of certificates in the trust chain, including the anchor.
671    ///
672    /// Important: if the trust reference has not yet been evaluated,
673    /// this function will evaluate it first before returning. If speed is critical,
674    /// you may want to call SecTrustGetTrustResult first to make sure that a
675    /// result other than kSecTrustResultInvalid is present for the trust object.
676    #[doc(alias = "SecTrustGetCertificateCount")]
677    #[inline]
678    pub unsafe fn certificate_count(&self) -> CFIndex {
679        extern "C-unwind" {
680            fn SecTrustGetCertificateCount(trust: &SecTrust) -> CFIndex;
681        }
682        unsafe { SecTrustGetCertificateCount(self) }
683    }
684
685    /// Returns a certificate from the trust chain.
686    ///
687    /// Parameter `trust`: Reference to a trust object.
688    ///
689    /// Parameter `ix`: The index of the requested certificate.  Indices run from 0
690    /// (leaf) to the anchor (or last certificate found if no anchor was found).
691    /// The leaf cert (index 0) is always present regardless of whether the trust
692    /// reference has been evaluated or not.
693    ///
694    /// Returns: A SecCertificateRef for the requested certificate.
695    ///
696    /// This API is fundamentally not thread-safe -- other threads using the same
697    /// trust object may trigger trust evaluations that release the returned certificate or change the
698    /// certificate chain as a thread is iterating through the certificate chain. The replacement function
699    /// SecTrustCopyCertificateChain provides thread-safe results.
700    #[doc(alias = "SecTrustGetCertificateAtIndex")]
701    #[cfg(feature = "SecBase")]
702    #[deprecated]
703    #[inline]
704    pub unsafe fn certificate_at_index(&self, ix: CFIndex) -> Option<CFRetained<SecCertificate>> {
705        extern "C-unwind" {
706            fn SecTrustGetCertificateAtIndex(
707                trust: &SecTrust,
708                ix: CFIndex,
709            ) -> Option<NonNull<SecCertificate>>;
710        }
711        let ret = unsafe { SecTrustGetCertificateAtIndex(self, ix) };
712        ret.map(|ret| unsafe { CFRetained::retain(ret) })
713    }
714
715    /// Returns an opaque cookie which will allow future evaluations
716    /// of the current certificate to succeed.
717    ///
718    /// Parameter `trust`: A reference to an evaluated trust object.
719    ///
720    /// Returns: An opaque cookie which when passed to SecTrustSetExceptions() will
721    /// cause a call to SecTrustEvaluate() return kSecTrustResultProceed.  This
722    /// will happen upon subsequent evaluation of the current certificate unless
723    /// some new error starts happening that wasn't being reported when the cookie
724    /// was returned from this function (for example, if the certificate expires
725    /// then evaluation will start failing again until a new cookie is obtained.)
726    ///
727    /// Normally this API should only be called once the errors have
728    /// been presented to the user and the user decided to trust the current
729    /// certificate chain regardless of the errors being presented, for the
730    /// current application/server/protocol combination.
731    #[doc(alias = "SecTrustCopyExceptions")]
732    #[inline]
733    pub unsafe fn exceptions(&self) -> Option<CFRetained<CFData>> {
734        extern "C-unwind" {
735            fn SecTrustCopyExceptions(trust: &SecTrust) -> Option<NonNull<CFData>>;
736        }
737        let ret = unsafe { SecTrustCopyExceptions(self) };
738        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
739    }
740
741    /// Set a trust cookie to be used for evaluating this certificate chain.
742    ///
743    /// Parameter `trust`: A reference to a trust object.
744    ///
745    /// Parameter `exceptions`: An exceptions cookie as returned by a call to
746    /// SecTrustCopyExceptions() in the past.  You may pass NULL to clear any
747    /// exceptions which have been previously set on this trust reference.
748    ///
749    /// Returns: Upon calling SecTrustEvaluate(), any failures that were present at the
750    /// time the exceptions object was created are ignored, and instead of returning
751    /// kSecTrustResultRecoverableTrustFailure, kSecTrustResultProceed will be returned
752    /// (if the certificate for which exceptions was created matches the current leaf
753    /// certificate).
754    ///
755    /// Returns: Returns true if the exceptions cookies was valid and matches the current
756    /// leaf certificate, false otherwise.  This function will invalidate the existing
757    /// trust result, requiring a subsequent evaluation for the newly-set exceptions.
758    /// Note that this function returning true doesn't mean the caller can skip calling
759    /// SecTrustEvaluate, as there may be new errors since the exceptions cookie was
760    /// created (for example, a certificate may have subsequently expired.)
761    ///
762    /// Clients of this interface will need to establish the context of this
763    /// exception to later decide when this exception cookie is to be used.
764    /// Examples of this context would be the server we are connecting to, the ssid
765    /// of the wireless network for which this cert is needed, the account for which
766    /// this cert should be considered valid, and so on.
767    #[doc(alias = "SecTrustSetExceptions")]
768    #[inline]
769    pub unsafe fn set_exceptions(&self, exceptions: Option<&CFData>) -> bool {
770        extern "C-unwind" {
771            fn SecTrustSetExceptions(trust: &SecTrust, exceptions: Option<&CFData>) -> bool;
772        }
773        unsafe { SecTrustSetExceptions(self, exceptions) }
774    }
775
776    /// Return a property array for this trust evaluation.
777    ///
778    /// Parameter `trust`: A reference to a trust object. If the trust has not been
779    /// evaluated, the returned property array will be empty.
780    ///
781    /// Returns: A property array. It is the caller's responsibility to CFRelease
782    /// the returned array when it is no longer needed.
783    ///
784    /// On macOS, this function returns an ordered array of CFDictionaryRef
785    /// instances for each certificate in the chain. Indices run from 0 (leaf) to
786    /// the anchor (or last certificate found if no anchor was found.)
787    /// On other platforms, this function returns an unordered array of CFDictionary instances.
788    /// See the "Trust Property Constants" section for a list of currently defined keys.
789    /// The error information conveyed via this interface is also conveyed via the
790    /// returned error of SecTrustEvaluateWithError.
791    #[doc(alias = "SecTrustCopyProperties")]
792    #[deprecated]
793    #[inline]
794    pub unsafe fn properties(&self) -> Option<CFRetained<CFArray>> {
795        extern "C-unwind" {
796            fn SecTrustCopyProperties(trust: &SecTrust) -> Option<NonNull<CFArray>>;
797        }
798        let ret = unsafe { SecTrustCopyProperties(self) };
799        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
800    }
801
802    /// Returns a dictionary containing information about the
803    /// evaluated certificate chain for use by clients.
804    ///
805    /// Parameter `trust`: A reference to a trust object.
806    ///
807    /// Returns: A dictionary with various fields that can be displayed to the user,
808    /// or NULL if no additional info is available or the trust has not yet been
809    /// validated.  The caller is responsible for calling CFRelease on the value
810    /// returned when it is no longer needed.
811    ///
812    /// Returns a dictionary for the overall trust evaluation. See the
813    /// "Trust Result Constants" section for a list of currently defined keys.
814    #[doc(alias = "SecTrustCopyResult")]
815    #[inline]
816    pub unsafe fn result(&self) -> Option<CFRetained<CFDictionary>> {
817        extern "C-unwind" {
818            fn SecTrustCopyResult(trust: &SecTrust) -> Option<NonNull<CFDictionary>>;
819        }
820        let ret = unsafe { SecTrustCopyResult(self) };
821        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
822    }
823
824    /// Attach OCSPResponse data to a trust object.
825    ///
826    /// Parameter `trust`: A reference to a trust object.
827    ///
828    /// Parameter `responseData`: This may be either a CFData object containing a single
829    /// DER-encoded OCSPResponse (per RFC 2560), or a CFArray of these.
830    ///
831    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
832    ///
833    /// Allows the caller to provide OCSPResponse data (which may be
834    /// obtained during a TLS/SSL handshake, per RFC 3546) as input to a trust
835    /// evaluation. If this data is available, it can obviate the need to contact
836    /// an OCSP server for current revocation information.
837    ///
838    /// # Safety
839    ///
840    /// `response_data` should be of the correct type.
841    #[doc(alias = "SecTrustSetOCSPResponse")]
842    #[inline]
843    pub unsafe fn set_ocsp_response(&self, response_data: Option<&CFType>) -> OSStatus {
844        extern "C-unwind" {
845            fn SecTrustSetOCSPResponse(
846                trust: &SecTrust,
847                response_data: Option<&CFType>,
848            ) -> OSStatus;
849        }
850        unsafe { SecTrustSetOCSPResponse(self, response_data) }
851    }
852
853    /// Attach SignedCertificateTimestamp data to a trust object.
854    ///
855    /// Parameter `trust`: A reference to a trust object.
856    ///
857    /// Parameter `sctArray`: is a CFArray of CFData objects each containing a SCT (per RFC 6962).
858    ///
859    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
860    ///
861    /// Allows the caller to provide SCT data (which may be
862    /// obtained during a TLS/SSL handshake, per RFC 6962) as input to a trust
863    /// evaluation.
864    ///
865    /// # Safety
866    ///
867    /// `sct_array` generic must be of the correct type.
868    #[doc(alias = "SecTrustSetSignedCertificateTimestamps")]
869    #[inline]
870    pub unsafe fn set_signed_certificate_timestamps(
871        &self,
872        sct_array: Option<&CFArray>,
873    ) -> OSStatus {
874        extern "C-unwind" {
875            fn SecTrustSetSignedCertificateTimestamps(
876                trust: &SecTrust,
877                sct_array: Option<&CFArray>,
878            ) -> OSStatus;
879        }
880        unsafe { SecTrustSetSignedCertificateTimestamps(self, sct_array) }
881    }
882
883    /// Returns the certificate trust chain
884    ///
885    /// Parameter `trust`: Reference to a trust object.
886    ///
887    /// Returns: A CFArray of the SecCertificateRefs for the resulting certificate chain
888    #[doc(alias = "SecTrustCopyCertificateChain")]
889    #[inline]
890    pub unsafe fn certificate_chain(&self) -> Option<CFRetained<CFArray>> {
891        extern "C-unwind" {
892            fn SecTrustCopyCertificateChain(trust: &SecTrust) -> Option<NonNull<CFArray>>;
893        }
894        let ret = unsafe { SecTrustCopyCertificateChain(self) };
895        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
896    }
897}
898
899/// Specifies a user-specified trust setting value.
900///
901/// Deprecated in OS X 10.9. User trust settings are managed by
902/// functions in SecTrustSettings.h (starting with OS X 10.5), and by the
903/// SecTrustCopyExceptions and SecTrustSetExceptions functions (starting with
904/// iOS 4 and OS X 10.9). The latter two functions are recommended for both macOS
905/// and iOS, as they avoid the need to explicitly specify these values.
906///
907/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrustusersetting?language=objc)
908#[deprecated]
909pub type SecTrustUserSetting = SecTrustResultType;
910
911/// Options for customizing trust evaluation.
912///
913///
914///
915///
916///
917/// check per certificate.
918///
919/// anchors.
920///
921/// treated as anchors implicitly.
922///
923/// See also [Apple's documentation](https://developer.apple.com/documentation/security/sectrustoptionflags?language=objc)
924// NS_OPTIONS
925#[repr(transparent)]
926#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
927pub struct SecTrustOptionFlags(pub u32);
928bitflags::bitflags! {
929    impl SecTrustOptionFlags: u32 {
930        #[doc(alias = "kSecTrustOptionAllowExpired")]
931        const AllowExpired = 0x00000001;
932        #[doc(alias = "kSecTrustOptionLeafIsCA")]
933        const LeafIsCA = 0x00000002;
934        #[doc(alias = "kSecTrustOptionFetchIssuerFromNet")]
935        const FetchIssuerFromNet = 0x00000004;
936        #[doc(alias = "kSecTrustOptionAllowExpiredRoot")]
937        const AllowExpiredRoot = 0x00000008;
938        #[doc(alias = "kSecTrustOptionRequireRevPerCert")]
939        const RequireRevPerCert = 0x00000010;
940        #[doc(alias = "kSecTrustOptionUseTrustSettings")]
941        const UseTrustSettings = 0x00000020;
942        #[doc(alias = "kSecTrustOptionImplicitAnchors")]
943        const ImplicitAnchors = 0x00000040;
944    }
945}
946
947#[cfg(feature = "objc2")]
948unsafe impl Encode for SecTrustOptionFlags {
949    const ENCODING: Encoding = u32::ENCODING;
950}
951
952#[cfg(feature = "objc2")]
953unsafe impl RefEncode for SecTrustOptionFlags {
954    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
955}
956
957impl SecTrust {
958    /// Sets optional flags for customizing a trust evaluation.
959    ///
960    /// Parameter `trustRef`: A trust reference.
961    ///
962    /// Parameter `options`: Flags to change evaluation behavior for this trust.
963    ///
964    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
965    ///
966    /// This function is not available on iOS. Use SecTrustSetExceptions
967    /// and SecTrustCopyExceptions to modify default trust results, and
968    /// SecTrustSetNetworkFetchAllowed to specify whether missing CA certificates
969    /// can be fetched from the network.
970    #[doc(alias = "SecTrustSetOptions")]
971    #[inline]
972    pub unsafe fn set_options(&self, options: SecTrustOptionFlags) -> OSStatus {
973        extern "C-unwind" {
974            fn SecTrustSetOptions(trust_ref: &SecTrust, options: SecTrustOptionFlags) -> OSStatus;
975        }
976        unsafe { SecTrustSetOptions(self, options) }
977    }
978
979    /// Sets the action and action data for a trust object.
980    ///
981    /// Parameter `trustRef`: The reference to the trust to change.
982    ///
983    /// Parameter `action`: A trust action.
984    ///
985    /// Parameter `actionData`: A reference to data associated with this action.
986    ///
987    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
988    ///
989    /// This function is deprecated in OS X 10.7 and later, where it
990    /// was replaced by SecTrustSetOptions, and is not available on iOS. Your code
991    /// should use SecTrustSetExceptions and SecTrustCopyExceptions to modify default
992    /// trust results, and SecTrustSetNetworkFetchAllowed to specify whether missing
993    /// CA certificates can be fetched from the network.
994    #[doc(alias = "SecTrustSetParameters")]
995    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
996    #[deprecated]
997    #[inline]
998    pub unsafe fn set_parameters(&self, action: CSSM_TP_ACTION, action_data: &CFData) -> OSStatus {
999        extern "C-unwind" {
1000            fn SecTrustSetParameters(
1001                trust_ref: &SecTrust,
1002                action: CSSM_TP_ACTION,
1003                action_data: &CFData,
1004            ) -> OSStatus;
1005        }
1006        unsafe { SecTrustSetParameters(self, action, action_data) }
1007    }
1008
1009    /// Sets the keychains for a given trust object.
1010    ///
1011    /// Parameter `trust`: A reference to a trust object.
1012    ///
1013    /// Parameter `keychainOrArray`: A reference to an array of keychains to search, a
1014    /// single keychain, or NULL to use the default keychain search list.
1015    ///
1016    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
1017    ///
1018    /// This function is deprecated in macOS 10.13 and later. Beginning in
1019    /// macOS 10.12, this function no longer affected the behavior of the trust
1020    /// evaluation: the user's keychain search list and the system
1021    /// anchors keychain are searched for certificates to complete the chain. To change
1022    /// the keychains that are searched, callers must use SecKeychainSetSearchList to
1023    /// change the user's keychain search list.
1024    /// Note: this function was never applicable to iOS.
1025    ///
1026    /// # Safety
1027    ///
1028    /// `keychain_or_array` should be of the correct type.
1029    #[doc(alias = "SecTrustSetKeychains")]
1030    #[deprecated]
1031    #[inline]
1032    pub unsafe fn set_keychains(&self, keychain_or_array: Option<&CFType>) -> OSStatus {
1033        extern "C-unwind" {
1034            fn SecTrustSetKeychains(
1035                trust: &SecTrust,
1036                keychain_or_array: Option<&CFType>,
1037            ) -> OSStatus;
1038        }
1039        unsafe { SecTrustSetKeychains(self, keychain_or_array) }
1040    }
1041
1042    /// Returns detailed information on the outcome of an evaluation.
1043    ///
1044    /// Parameter `trustRef`: A reference to a trust object.
1045    ///
1046    /// Parameter `result`: A pointer to the result from the call to SecTrustEvaluate.
1047    ///
1048    /// Parameter `certChain`: On return, a pointer to the certificate chain used to
1049    /// validate the input certificate. Call the CFRelease function to release
1050    /// this pointer.
1051    ///
1052    /// Parameter `statusChain`: On return, a pointer to the status of the certificate
1053    /// chain. Do not attempt to free this pointer; it remains valid until the
1054    /// trust is destroyed or the next call to SecTrustEvaluate.
1055    ///
1056    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
1057    ///
1058    /// This function is deprecated in OS X 10.7 and later,
1059    /// and is not available on iOS.
1060    /// To get the complete certificate chain, use SecTrustCopyCertificateChain.
1061    /// To get detailed status information for each certificate, use
1062    /// SecTrustCopyProperties. To get the overall trust result for the evaluation,
1063    /// use SecTrustGetTrustResult.
1064    ///
1065    /// # Safety
1066    ///
1067    /// - `result` must be a valid pointer or null.
1068    /// - `cert_chain` must be a valid pointer or null.
1069    /// - `status_chain` must be a valid pointer or null.
1070    #[doc(alias = "SecTrustGetResult")]
1071    #[cfg(all(
1072        feature = "SecAsn1Types",
1073        feature = "cssmapple",
1074        feature = "cssmconfig",
1075        feature = "cssmtype"
1076    ))]
1077    #[deprecated]
1078    #[inline]
1079    pub unsafe fn get_trust(
1080        &self,
1081        result: *mut SecTrustResultType,
1082        cert_chain: *mut *const CFArray,
1083        status_chain: *mut *mut CSSM_TP_APPLE_EVIDENCE_INFO,
1084    ) -> OSStatus {
1085        extern "C-unwind" {
1086            fn SecTrustGetResult(
1087                trust_ref: &SecTrust,
1088                result: *mut SecTrustResultType,
1089                cert_chain: *mut *const CFArray,
1090                status_chain: *mut *mut CSSM_TP_APPLE_EVIDENCE_INFO,
1091            ) -> OSStatus;
1092        }
1093        unsafe { SecTrustGetResult(self, result, cert_chain, status_chain) }
1094    }
1095
1096    /// Gets the CSSM trust result.
1097    ///
1098    /// Parameter `trust`: A reference to a trust.
1099    ///
1100    /// Parameter `result`: On return, a pointer to the CSSM trust result.
1101    ///
1102    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
1103    ///
1104    /// This function is deprecated in OS X 10.7 and later,
1105    /// and is not available on iOS.
1106    /// To get detailed status information for each certificate, use
1107    /// SecTrustCopyProperties. To get the overall trust result for the evaluation,
1108    /// use SecTrustGetTrustResult.
1109    ///
1110    /// # Safety
1111    ///
1112    /// `result` must be a valid pointer.
1113    #[doc(alias = "SecTrustGetCssmResult")]
1114    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
1115    #[deprecated]
1116    #[inline]
1117    pub unsafe fn cssm_result(
1118        &self,
1119        result: NonNull<CSSM_TP_VERIFY_CONTEXT_RESULT_PTR>,
1120    ) -> OSStatus {
1121        extern "C-unwind" {
1122            fn SecTrustGetCssmResult(
1123                trust: &SecTrust,
1124                result: NonNull<CSSM_TP_VERIFY_CONTEXT_RESULT_PTR>,
1125            ) -> OSStatus;
1126        }
1127        unsafe { SecTrustGetCssmResult(self, result) }
1128    }
1129
1130    /// Gets the result code from the most recent call to SecTrustEvaluate
1131    /// for the specified trust.
1132    ///
1133    /// Parameter `trust`: A reference to a trust.
1134    ///
1135    /// Parameter `resultCode`: On return, the result code produced by the most recent
1136    /// evaluation of the given trust (cssmerr.h). The value of resultCode is
1137    /// undefined if SecTrustEvaluate has not been called.
1138    ///
1139    /// Returns: A result code. See "Security Error Codes" (SecBase.h). Returns
1140    /// errSecTrustNotAvailable if SecTrustEvaluate has not been called for the
1141    /// specified trust.
1142    ///
1143    /// This function is deprecated in OS X 10.7 and later,
1144    /// and is not available on iOS.
1145    /// To get detailed status information for each certificate, use
1146    /// SecTrustCopyProperties. To get the overall trust result for the evaluation,
1147    /// use SecTrustGetTrustResult.
1148    ///
1149    /// # Safety
1150    ///
1151    /// `result_code` must be a valid pointer.
1152    #[doc(alias = "SecTrustGetCssmResultCode")]
1153    #[deprecated]
1154    #[inline]
1155    pub unsafe fn cssm_result_code(&self, result_code: NonNull<OSStatus>) -> OSStatus {
1156        extern "C-unwind" {
1157            fn SecTrustGetCssmResultCode(
1158                trust: &SecTrust,
1159                result_code: NonNull<OSStatus>,
1160            ) -> OSStatus;
1161        }
1162        unsafe { SecTrustGetCssmResultCode(self, result_code) }
1163    }
1164
1165    /// Gets the CSSM trust handle
1166    ///
1167    /// Parameter `trust`: A reference to a trust.
1168    ///
1169    /// Parameter `handle`: On return, a CSSM trust handle.
1170    ///
1171    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
1172    ///
1173    /// This function is deprecated in OS X 10.7 and later.
1174    ///
1175    /// # Safety
1176    ///
1177    /// `handle` must be a valid pointer.
1178    #[doc(alias = "SecTrustGetTPHandle")]
1179    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
1180    #[deprecated]
1181    #[inline]
1182    pub unsafe fn tp_handle(&self, handle: NonNull<CSSM_TP_HANDLE>) -> OSStatus {
1183        extern "C-unwind" {
1184            fn SecTrustGetTPHandle(trust: &SecTrust, handle: NonNull<CSSM_TP_HANDLE>) -> OSStatus;
1185        }
1186        unsafe { SecTrustGetTPHandle(self, handle) }
1187    }
1188
1189    /// Returns an array of default anchor (root) certificates used by
1190    /// the system.
1191    ///
1192    /// Parameter `anchors`: On return, an array containing the system's default anchors
1193    /// (roots). Call the CFRelease function to release this pointer.
1194    ///
1195    /// Returns: A result code. See "Security Error Codes" (SecBase.h).
1196    ///
1197    /// This function is not available on iOS, as certificate data
1198    /// for system-trusted roots is currently unavailable on that platform.
1199    ///
1200    /// # Safety
1201    ///
1202    /// `anchors` must be a valid pointer.
1203    #[doc(alias = "SecTrustCopyAnchorCertificates")]
1204    #[inline]
1205    pub unsafe fn copy_anchor_certificates(anchors: NonNull<*const CFArray>) -> OSStatus {
1206        extern "C-unwind" {
1207            fn SecTrustCopyAnchorCertificates(anchors: NonNull<*const CFArray>) -> OSStatus;
1208        }
1209        unsafe { SecTrustCopyAnchorCertificates(anchors) }
1210    }
1211}
1212
1213extern "C-unwind" {
1214    #[deprecated = "renamed to `SecTrust::create_with_certificates`"]
1215    pub fn SecTrustCreateWithCertificates(
1216        certificates: &CFType,
1217        policies: Option<&CFType>,
1218        trust: NonNull<*mut SecTrust>,
1219    ) -> OSStatus;
1220}
1221
1222extern "C-unwind" {
1223    #[deprecated = "renamed to `SecTrust::set_policies`"]
1224    pub fn SecTrustSetPolicies(trust: &SecTrust, policies: &CFType) -> OSStatus;
1225}
1226
1227extern "C-unwind" {
1228    #[deprecated = "renamed to `SecTrust::copy_policies`"]
1229    pub fn SecTrustCopyPolicies(trust: &SecTrust, policies: NonNull<*const CFArray>) -> OSStatus;
1230}
1231
1232#[deprecated = "renamed to `SecTrust::set_network_fetch_allowed`"]
1233#[inline]
1234pub unsafe extern "C-unwind" fn SecTrustSetNetworkFetchAllowed(
1235    trust: &SecTrust,
1236    allow_fetch: bool,
1237) -> OSStatus {
1238    extern "C-unwind" {
1239        fn SecTrustSetNetworkFetchAllowed(trust: &SecTrust, allow_fetch: Boolean) -> OSStatus;
1240    }
1241    unsafe { SecTrustSetNetworkFetchAllowed(trust, allow_fetch as _) }
1242}
1243
1244extern "C-unwind" {
1245    #[deprecated = "renamed to `SecTrust::network_fetch_allowed`"]
1246    pub fn SecTrustGetNetworkFetchAllowed(
1247        trust: &SecTrust,
1248        allow_fetch: NonNull<Boolean>,
1249    ) -> OSStatus;
1250}
1251
1252extern "C-unwind" {
1253    #[deprecated = "renamed to `SecTrust::set_anchor_certificates`"]
1254    pub fn SecTrustSetAnchorCertificates(
1255        trust: &SecTrust,
1256        anchor_certificates: Option<&CFArray>,
1257    ) -> OSStatus;
1258}
1259
1260#[deprecated = "renamed to `SecTrust::set_anchor_certificates_only`"]
1261#[inline]
1262pub unsafe extern "C-unwind" fn SecTrustSetAnchorCertificatesOnly(
1263    trust: &SecTrust,
1264    anchor_certificates_only: bool,
1265) -> OSStatus {
1266    extern "C-unwind" {
1267        fn SecTrustSetAnchorCertificatesOnly(
1268            trust: &SecTrust,
1269            anchor_certificates_only: Boolean,
1270        ) -> OSStatus;
1271    }
1272    unsafe { SecTrustSetAnchorCertificatesOnly(trust, anchor_certificates_only as _) }
1273}
1274
1275extern "C-unwind" {
1276    #[deprecated = "renamed to `SecTrust::copy_custom_anchor_certificates`"]
1277    pub fn SecTrustCopyCustomAnchorCertificates(
1278        trust: &SecTrust,
1279        anchors: NonNull<*const CFArray>,
1280    ) -> OSStatus;
1281}
1282
1283extern "C-unwind" {
1284    #[deprecated = "renamed to `SecTrust::set_verify_date`"]
1285    pub fn SecTrustSetVerifyDate(trust: &SecTrust, verify_date: &CFDate) -> OSStatus;
1286}
1287
1288extern "C-unwind" {
1289    #[deprecated = "renamed to `SecTrust::verify_time`"]
1290    pub fn SecTrustGetVerifyTime(trust: &SecTrust) -> CFAbsoluteTime;
1291}
1292
1293extern "C-unwind" {
1294    #[deprecated = "renamed to `SecTrust::evaluate`"]
1295    pub fn SecTrustEvaluate(trust: &SecTrust, result: NonNull<SecTrustResultType>) -> OSStatus;
1296}
1297
1298extern "C-unwind" {
1299    #[deprecated = "renamed to `SecTrust::evaluate_with_error`"]
1300    #[must_use]
1301    pub fn SecTrustEvaluateWithError(trust: &SecTrust, error: *mut *mut CFError) -> bool;
1302}
1303
1304extern "C-unwind" {
1305    #[deprecated = "renamed to `SecTrust::trust_result`"]
1306    pub fn SecTrustGetTrustResult(
1307        trust: &SecTrust,
1308        result: NonNull<SecTrustResultType>,
1309    ) -> OSStatus;
1310}
1311
1312#[cfg(feature = "SecBase")]
1313#[deprecated = "renamed to `SecTrust::public_key`"]
1314#[inline]
1315pub unsafe extern "C-unwind" fn SecTrustCopyPublicKey(
1316    trust: &SecTrust,
1317) -> Option<CFRetained<SecKey>> {
1318    extern "C-unwind" {
1319        fn SecTrustCopyPublicKey(trust: &SecTrust) -> Option<NonNull<SecKey>>;
1320    }
1321    let ret = unsafe { SecTrustCopyPublicKey(trust) };
1322    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1323}
1324
1325#[cfg(feature = "SecBase")]
1326#[deprecated = "renamed to `SecTrust::key`"]
1327#[inline]
1328pub unsafe extern "C-unwind" fn SecTrustCopyKey(trust: &SecTrust) -> Option<CFRetained<SecKey>> {
1329    extern "C-unwind" {
1330        fn SecTrustCopyKey(trust: &SecTrust) -> Option<NonNull<SecKey>>;
1331    }
1332    let ret = unsafe { SecTrustCopyKey(trust) };
1333    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1334}
1335
1336extern "C-unwind" {
1337    #[deprecated = "renamed to `SecTrust::certificate_count`"]
1338    pub fn SecTrustGetCertificateCount(trust: &SecTrust) -> CFIndex;
1339}
1340
1341#[cfg(feature = "SecBase")]
1342#[deprecated = "renamed to `SecTrust::certificate_at_index`"]
1343#[inline]
1344pub unsafe extern "C-unwind" fn SecTrustGetCertificateAtIndex(
1345    trust: &SecTrust,
1346    ix: CFIndex,
1347) -> Option<CFRetained<SecCertificate>> {
1348    extern "C-unwind" {
1349        fn SecTrustGetCertificateAtIndex(
1350            trust: &SecTrust,
1351            ix: CFIndex,
1352        ) -> Option<NonNull<SecCertificate>>;
1353    }
1354    let ret = unsafe { SecTrustGetCertificateAtIndex(trust, ix) };
1355    ret.map(|ret| unsafe { CFRetained::retain(ret) })
1356}
1357
1358#[deprecated = "renamed to `SecTrust::exceptions`"]
1359#[inline]
1360pub unsafe extern "C-unwind" fn SecTrustCopyExceptions(
1361    trust: &SecTrust,
1362) -> Option<CFRetained<CFData>> {
1363    extern "C-unwind" {
1364        fn SecTrustCopyExceptions(trust: &SecTrust) -> Option<NonNull<CFData>>;
1365    }
1366    let ret = unsafe { SecTrustCopyExceptions(trust) };
1367    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1368}
1369
1370extern "C-unwind" {
1371    #[deprecated = "renamed to `SecTrust::set_exceptions`"]
1372    pub fn SecTrustSetExceptions(trust: &SecTrust, exceptions: Option<&CFData>) -> bool;
1373}
1374
1375#[deprecated = "renamed to `SecTrust::properties`"]
1376#[inline]
1377pub unsafe extern "C-unwind" fn SecTrustCopyProperties(
1378    trust: &SecTrust,
1379) -> Option<CFRetained<CFArray>> {
1380    extern "C-unwind" {
1381        fn SecTrustCopyProperties(trust: &SecTrust) -> Option<NonNull<CFArray>>;
1382    }
1383    let ret = unsafe { SecTrustCopyProperties(trust) };
1384    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1385}
1386
1387#[deprecated = "renamed to `SecTrust::result`"]
1388#[inline]
1389pub unsafe extern "C-unwind" fn SecTrustCopyResult(
1390    trust: &SecTrust,
1391) -> Option<CFRetained<CFDictionary>> {
1392    extern "C-unwind" {
1393        fn SecTrustCopyResult(trust: &SecTrust) -> Option<NonNull<CFDictionary>>;
1394    }
1395    let ret = unsafe { SecTrustCopyResult(trust) };
1396    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1397}
1398
1399extern "C-unwind" {
1400    #[deprecated = "renamed to `SecTrust::set_ocsp_response`"]
1401    pub fn SecTrustSetOCSPResponse(trust: &SecTrust, response_data: Option<&CFType>) -> OSStatus;
1402}
1403
1404extern "C-unwind" {
1405    #[deprecated = "renamed to `SecTrust::set_signed_certificate_timestamps`"]
1406    pub fn SecTrustSetSignedCertificateTimestamps(
1407        trust: &SecTrust,
1408        sct_array: Option<&CFArray>,
1409    ) -> OSStatus;
1410}
1411
1412#[deprecated = "renamed to `SecTrust::certificate_chain`"]
1413#[inline]
1414pub unsafe extern "C-unwind" fn SecTrustCopyCertificateChain(
1415    trust: &SecTrust,
1416) -> Option<CFRetained<CFArray>> {
1417    extern "C-unwind" {
1418        fn SecTrustCopyCertificateChain(trust: &SecTrust) -> Option<NonNull<CFArray>>;
1419    }
1420    let ret = unsafe { SecTrustCopyCertificateChain(trust) };
1421    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
1422}
1423
1424extern "C-unwind" {
1425    #[deprecated = "renamed to `SecTrust::set_options`"]
1426    pub fn SecTrustSetOptions(trust_ref: &SecTrust, options: SecTrustOptionFlags) -> OSStatus;
1427}
1428
1429extern "C-unwind" {
1430    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
1431    #[deprecated = "renamed to `SecTrust::set_parameters`"]
1432    pub fn SecTrustSetParameters(
1433        trust_ref: &SecTrust,
1434        action: CSSM_TP_ACTION,
1435        action_data: &CFData,
1436    ) -> OSStatus;
1437}
1438
1439extern "C-unwind" {
1440    #[deprecated = "renamed to `SecTrust::set_keychains`"]
1441    pub fn SecTrustSetKeychains(trust: &SecTrust, keychain_or_array: Option<&CFType>) -> OSStatus;
1442}
1443
1444extern "C-unwind" {
1445    #[cfg(all(
1446        feature = "SecAsn1Types",
1447        feature = "cssmapple",
1448        feature = "cssmconfig",
1449        feature = "cssmtype"
1450    ))]
1451    #[deprecated = "renamed to `SecTrust::get_trust`"]
1452    pub fn SecTrustGetResult(
1453        trust_ref: &SecTrust,
1454        result: *mut SecTrustResultType,
1455        cert_chain: *mut *const CFArray,
1456        status_chain: *mut *mut CSSM_TP_APPLE_EVIDENCE_INFO,
1457    ) -> OSStatus;
1458}
1459
1460extern "C-unwind" {
1461    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
1462    #[deprecated = "renamed to `SecTrust::cssm_result`"]
1463    pub fn SecTrustGetCssmResult(
1464        trust: &SecTrust,
1465        result: NonNull<CSSM_TP_VERIFY_CONTEXT_RESULT_PTR>,
1466    ) -> OSStatus;
1467}
1468
1469extern "C-unwind" {
1470    #[deprecated = "renamed to `SecTrust::cssm_result_code`"]
1471    pub fn SecTrustGetCssmResultCode(trust: &SecTrust, result_code: NonNull<OSStatus>) -> OSStatus;
1472}
1473
1474extern "C-unwind" {
1475    #[cfg(all(feature = "cssmconfig", feature = "cssmtype"))]
1476    #[deprecated = "renamed to `SecTrust::tp_handle`"]
1477    pub fn SecTrustGetTPHandle(trust: &SecTrust, handle: NonNull<CSSM_TP_HANDLE>) -> OSStatus;
1478}
1479
1480extern "C-unwind" {
1481    #[deprecated = "renamed to `SecTrust::copy_anchor_certificates`"]
1482    pub fn SecTrustCopyAnchorCertificates(anchors: NonNull<*const CFArray>) -> OSStatus;
1483}