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