192f3ab15Sopenharmony_ciuse bitflags::bitflags;
292f3ab15Sopenharmony_ciuse foreign_types::ForeignTypeRef;
392f3ab15Sopenharmony_ciuse libc::{c_int, c_long, c_ulong};
492f3ab15Sopenharmony_ciuse std::mem;
592f3ab15Sopenharmony_ciuse std::ptr;
692f3ab15Sopenharmony_ci
792f3ab15Sopenharmony_ciuse crate::asn1::Asn1GeneralizedTimeRef;
892f3ab15Sopenharmony_ciuse crate::error::ErrorStack;
992f3ab15Sopenharmony_ciuse crate::hash::MessageDigest;
1092f3ab15Sopenharmony_ciuse crate::stack::StackRef;
1192f3ab15Sopenharmony_ciuse crate::util::ForeignTypeRefExt;
1292f3ab15Sopenharmony_ciuse crate::x509::store::X509StoreRef;
1392f3ab15Sopenharmony_ciuse crate::x509::{X509Ref, X509};
1492f3ab15Sopenharmony_ciuse crate::{cvt, cvt_p};
1592f3ab15Sopenharmony_ciuse openssl_macros::corresponds;
1692f3ab15Sopenharmony_ci
1792f3ab15Sopenharmony_cibitflags! {
1892f3ab15Sopenharmony_ci    pub struct OcspFlag: c_ulong {
1992f3ab15Sopenharmony_ci        const NO_CERTS = ffi::OCSP_NOCERTS;
2092f3ab15Sopenharmony_ci        const NO_INTERN = ffi::OCSP_NOINTERN;
2192f3ab15Sopenharmony_ci        const NO_CHAIN = ffi::OCSP_NOCHAIN;
2292f3ab15Sopenharmony_ci        const NO_VERIFY = ffi::OCSP_NOVERIFY;
2392f3ab15Sopenharmony_ci        const NO_EXPLICIT = ffi::OCSP_NOEXPLICIT;
2492f3ab15Sopenharmony_ci        const NO_CA_SIGN = ffi::OCSP_NOCASIGN;
2592f3ab15Sopenharmony_ci        const NO_DELEGATED = ffi::OCSP_NODELEGATED;
2692f3ab15Sopenharmony_ci        const NO_CHECKS = ffi::OCSP_NOCHECKS;
2792f3ab15Sopenharmony_ci        const TRUST_OTHER = ffi::OCSP_TRUSTOTHER;
2892f3ab15Sopenharmony_ci        const RESPID_KEY = ffi::OCSP_RESPID_KEY;
2992f3ab15Sopenharmony_ci        const NO_TIME = ffi::OCSP_NOTIME;
3092f3ab15Sopenharmony_ci    }
3192f3ab15Sopenharmony_ci}
3292f3ab15Sopenharmony_ci
3392f3ab15Sopenharmony_ci#[derive(Copy, Clone, Debug, PartialEq, Eq)]
3492f3ab15Sopenharmony_cipub struct OcspResponseStatus(c_int);
3592f3ab15Sopenharmony_ci
3692f3ab15Sopenharmony_ciimpl OcspResponseStatus {
3792f3ab15Sopenharmony_ci    pub const SUCCESSFUL: OcspResponseStatus =
3892f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_SUCCESSFUL);
3992f3ab15Sopenharmony_ci    pub const MALFORMED_REQUEST: OcspResponseStatus =
4092f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_MALFORMEDREQUEST);
4192f3ab15Sopenharmony_ci    pub const INTERNAL_ERROR: OcspResponseStatus =
4292f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_INTERNALERROR);
4392f3ab15Sopenharmony_ci    pub const TRY_LATER: OcspResponseStatus =
4492f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_TRYLATER);
4592f3ab15Sopenharmony_ci    pub const SIG_REQUIRED: OcspResponseStatus =
4692f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_SIGREQUIRED);
4792f3ab15Sopenharmony_ci    pub const UNAUTHORIZED: OcspResponseStatus =
4892f3ab15Sopenharmony_ci        OcspResponseStatus(ffi::OCSP_RESPONSE_STATUS_UNAUTHORIZED);
4992f3ab15Sopenharmony_ci
5092f3ab15Sopenharmony_ci    pub fn from_raw(raw: c_int) -> OcspResponseStatus {
5192f3ab15Sopenharmony_ci        OcspResponseStatus(raw)
5292f3ab15Sopenharmony_ci    }
5392f3ab15Sopenharmony_ci
5492f3ab15Sopenharmony_ci    #[allow(clippy::trivially_copy_pass_by_ref)]
5592f3ab15Sopenharmony_ci    pub fn as_raw(&self) -> c_int {
5692f3ab15Sopenharmony_ci        self.0
5792f3ab15Sopenharmony_ci    }
5892f3ab15Sopenharmony_ci}
5992f3ab15Sopenharmony_ci
6092f3ab15Sopenharmony_ci#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6192f3ab15Sopenharmony_cipub struct OcspCertStatus(c_int);
6292f3ab15Sopenharmony_ci
6392f3ab15Sopenharmony_ciimpl OcspCertStatus {
6492f3ab15Sopenharmony_ci    pub const GOOD: OcspCertStatus = OcspCertStatus(ffi::V_OCSP_CERTSTATUS_GOOD);
6592f3ab15Sopenharmony_ci    pub const REVOKED: OcspCertStatus = OcspCertStatus(ffi::V_OCSP_CERTSTATUS_REVOKED);
6692f3ab15Sopenharmony_ci    pub const UNKNOWN: OcspCertStatus = OcspCertStatus(ffi::V_OCSP_CERTSTATUS_UNKNOWN);
6792f3ab15Sopenharmony_ci
6892f3ab15Sopenharmony_ci    pub fn from_raw(raw: c_int) -> OcspCertStatus {
6992f3ab15Sopenharmony_ci        OcspCertStatus(raw)
7092f3ab15Sopenharmony_ci    }
7192f3ab15Sopenharmony_ci
7292f3ab15Sopenharmony_ci    #[allow(clippy::trivially_copy_pass_by_ref)]
7392f3ab15Sopenharmony_ci    pub fn as_raw(&self) -> c_int {
7492f3ab15Sopenharmony_ci        self.0
7592f3ab15Sopenharmony_ci    }
7692f3ab15Sopenharmony_ci}
7792f3ab15Sopenharmony_ci
7892f3ab15Sopenharmony_ci#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7992f3ab15Sopenharmony_cipub struct OcspRevokedStatus(c_int);
8092f3ab15Sopenharmony_ci
8192f3ab15Sopenharmony_ciimpl OcspRevokedStatus {
8292f3ab15Sopenharmony_ci    pub const NO_STATUS: OcspRevokedStatus = OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_NOSTATUS);
8392f3ab15Sopenharmony_ci    pub const UNSPECIFIED: OcspRevokedStatus =
8492f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_UNSPECIFIED);
8592f3ab15Sopenharmony_ci    pub const KEY_COMPROMISE: OcspRevokedStatus =
8692f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_KEYCOMPROMISE);
8792f3ab15Sopenharmony_ci    pub const CA_COMPROMISE: OcspRevokedStatus =
8892f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_CACOMPROMISE);
8992f3ab15Sopenharmony_ci    pub const AFFILIATION_CHANGED: OcspRevokedStatus =
9092f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_AFFILIATIONCHANGED);
9192f3ab15Sopenharmony_ci    pub const STATUS_SUPERSEDED: OcspRevokedStatus =
9292f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_SUPERSEDED);
9392f3ab15Sopenharmony_ci    pub const STATUS_CESSATION_OF_OPERATION: OcspRevokedStatus =
9492f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_CESSATIONOFOPERATION);
9592f3ab15Sopenharmony_ci    pub const STATUS_CERTIFICATE_HOLD: OcspRevokedStatus =
9692f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_CERTIFICATEHOLD);
9792f3ab15Sopenharmony_ci    pub const REMOVE_FROM_CRL: OcspRevokedStatus =
9892f3ab15Sopenharmony_ci        OcspRevokedStatus(ffi::OCSP_REVOKED_STATUS_REMOVEFROMCRL);
9992f3ab15Sopenharmony_ci
10092f3ab15Sopenharmony_ci    pub fn from_raw(raw: c_int) -> OcspRevokedStatus {
10192f3ab15Sopenharmony_ci        OcspRevokedStatus(raw)
10292f3ab15Sopenharmony_ci    }
10392f3ab15Sopenharmony_ci
10492f3ab15Sopenharmony_ci    #[allow(clippy::trivially_copy_pass_by_ref)]
10592f3ab15Sopenharmony_ci    pub fn as_raw(&self) -> c_int {
10692f3ab15Sopenharmony_ci        self.0
10792f3ab15Sopenharmony_ci    }
10892f3ab15Sopenharmony_ci}
10992f3ab15Sopenharmony_ci
11092f3ab15Sopenharmony_cipub struct OcspStatus<'a> {
11192f3ab15Sopenharmony_ci    /// The overall status of the response.
11292f3ab15Sopenharmony_ci    pub status: OcspCertStatus,
11392f3ab15Sopenharmony_ci    /// If `status` is `CERT_STATUS_REVOKED`, the reason for the revocation.
11492f3ab15Sopenharmony_ci    pub reason: OcspRevokedStatus,
11592f3ab15Sopenharmony_ci    /// If `status` is `CERT_STATUS_REVOKED`, the time at which the certificate was revoked.
11692f3ab15Sopenharmony_ci    pub revocation_time: Option<&'a Asn1GeneralizedTimeRef>,
11792f3ab15Sopenharmony_ci    /// The time that this revocation check was performed.
11892f3ab15Sopenharmony_ci    pub this_update: &'a Asn1GeneralizedTimeRef,
11992f3ab15Sopenharmony_ci    /// The time at which this revocation check expires.
12092f3ab15Sopenharmony_ci    pub next_update: &'a Asn1GeneralizedTimeRef,
12192f3ab15Sopenharmony_ci}
12292f3ab15Sopenharmony_ci
12392f3ab15Sopenharmony_ciimpl<'a> OcspStatus<'a> {
12492f3ab15Sopenharmony_ci    /// Checks validity of the `this_update` and `next_update` fields.
12592f3ab15Sopenharmony_ci    ///
12692f3ab15Sopenharmony_ci    /// The `nsec` parameter specifies an amount of slack time that will be used when comparing
12792f3ab15Sopenharmony_ci    /// those times with the current time to account for delays and clock skew.
12892f3ab15Sopenharmony_ci    ///
12992f3ab15Sopenharmony_ci    /// The `maxsec` parameter limits the maximum age of the `this_update` parameter to prohibit
13092f3ab15Sopenharmony_ci    /// very old responses.
13192f3ab15Sopenharmony_ci    #[corresponds(OCSP_check_validity)]
13292f3ab15Sopenharmony_ci    pub fn check_validity(&self, nsec: u32, maxsec: Option<u32>) -> Result<(), ErrorStack> {
13392f3ab15Sopenharmony_ci        unsafe {
13492f3ab15Sopenharmony_ci            cvt(ffi::OCSP_check_validity(
13592f3ab15Sopenharmony_ci                self.this_update.as_ptr(),
13692f3ab15Sopenharmony_ci                self.next_update.as_ptr(),
13792f3ab15Sopenharmony_ci                nsec as c_long,
13892f3ab15Sopenharmony_ci                maxsec.map(|n| n as c_long).unwrap_or(-1),
13992f3ab15Sopenharmony_ci            ))
14092f3ab15Sopenharmony_ci            .map(|_| ())
14192f3ab15Sopenharmony_ci        }
14292f3ab15Sopenharmony_ci    }
14392f3ab15Sopenharmony_ci}
14492f3ab15Sopenharmony_ci
14592f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
14692f3ab15Sopenharmony_ci    type CType = ffi::OCSP_BASICRESP;
14792f3ab15Sopenharmony_ci    fn drop = ffi::OCSP_BASICRESP_free;
14892f3ab15Sopenharmony_ci
14992f3ab15Sopenharmony_ci    pub struct OcspBasicResponse;
15092f3ab15Sopenharmony_ci    pub struct OcspBasicResponseRef;
15192f3ab15Sopenharmony_ci}
15292f3ab15Sopenharmony_ci
15392f3ab15Sopenharmony_ciimpl OcspBasicResponseRef {
15492f3ab15Sopenharmony_ci    /// Verifies the validity of the response.
15592f3ab15Sopenharmony_ci    ///
15692f3ab15Sopenharmony_ci    /// The `certs` parameter contains a set of certificates that will be searched when locating the
15792f3ab15Sopenharmony_ci    /// OCSP response signing certificate. Some responders do not include this in the response.
15892f3ab15Sopenharmony_ci    #[corresponds(OCSP_basic_verify)]
15992f3ab15Sopenharmony_ci    pub fn verify(
16092f3ab15Sopenharmony_ci        &self,
16192f3ab15Sopenharmony_ci        certs: &StackRef<X509>,
16292f3ab15Sopenharmony_ci        store: &X509StoreRef,
16392f3ab15Sopenharmony_ci        flags: OcspFlag,
16492f3ab15Sopenharmony_ci    ) -> Result<(), ErrorStack> {
16592f3ab15Sopenharmony_ci        unsafe {
16692f3ab15Sopenharmony_ci            cvt(ffi::OCSP_basic_verify(
16792f3ab15Sopenharmony_ci                self.as_ptr(),
16892f3ab15Sopenharmony_ci                certs.as_ptr(),
16992f3ab15Sopenharmony_ci                store.as_ptr(),
17092f3ab15Sopenharmony_ci                flags.bits(),
17192f3ab15Sopenharmony_ci            ))
17292f3ab15Sopenharmony_ci            .map(|_| ())
17392f3ab15Sopenharmony_ci        }
17492f3ab15Sopenharmony_ci    }
17592f3ab15Sopenharmony_ci
17692f3ab15Sopenharmony_ci    /// Looks up the status for the specified certificate ID.
17792f3ab15Sopenharmony_ci    #[corresponds(OCSP_resp_find_status)]
17892f3ab15Sopenharmony_ci    pub fn find_status<'a>(&'a self, id: &OcspCertIdRef) -> Option<OcspStatus<'a>> {
17992f3ab15Sopenharmony_ci        unsafe {
18092f3ab15Sopenharmony_ci            let mut status = ffi::V_OCSP_CERTSTATUS_UNKNOWN;
18192f3ab15Sopenharmony_ci            let mut reason = ffi::OCSP_REVOKED_STATUS_NOSTATUS;
18292f3ab15Sopenharmony_ci            let mut revocation_time = ptr::null_mut();
18392f3ab15Sopenharmony_ci            let mut this_update = ptr::null_mut();
18492f3ab15Sopenharmony_ci            let mut next_update = ptr::null_mut();
18592f3ab15Sopenharmony_ci
18692f3ab15Sopenharmony_ci            let r = ffi::OCSP_resp_find_status(
18792f3ab15Sopenharmony_ci                self.as_ptr(),
18892f3ab15Sopenharmony_ci                id.as_ptr(),
18992f3ab15Sopenharmony_ci                &mut status,
19092f3ab15Sopenharmony_ci                &mut reason,
19192f3ab15Sopenharmony_ci                &mut revocation_time,
19292f3ab15Sopenharmony_ci                &mut this_update,
19392f3ab15Sopenharmony_ci                &mut next_update,
19492f3ab15Sopenharmony_ci            );
19592f3ab15Sopenharmony_ci            if r == 1 {
19692f3ab15Sopenharmony_ci                let revocation_time = Asn1GeneralizedTimeRef::from_const_ptr_opt(revocation_time);
19792f3ab15Sopenharmony_ci
19892f3ab15Sopenharmony_ci                Some(OcspStatus {
19992f3ab15Sopenharmony_ci                    status: OcspCertStatus(status),
20092f3ab15Sopenharmony_ci                    reason: OcspRevokedStatus(status),
20192f3ab15Sopenharmony_ci                    revocation_time,
20292f3ab15Sopenharmony_ci                    this_update: Asn1GeneralizedTimeRef::from_ptr(this_update),
20392f3ab15Sopenharmony_ci                    next_update: Asn1GeneralizedTimeRef::from_ptr(next_update),
20492f3ab15Sopenharmony_ci                })
20592f3ab15Sopenharmony_ci            } else {
20692f3ab15Sopenharmony_ci                None
20792f3ab15Sopenharmony_ci            }
20892f3ab15Sopenharmony_ci        }
20992f3ab15Sopenharmony_ci    }
21092f3ab15Sopenharmony_ci}
21192f3ab15Sopenharmony_ci
21292f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
21392f3ab15Sopenharmony_ci    type CType = ffi::OCSP_CERTID;
21492f3ab15Sopenharmony_ci    fn drop = ffi::OCSP_CERTID_free;
21592f3ab15Sopenharmony_ci
21692f3ab15Sopenharmony_ci    pub struct OcspCertId;
21792f3ab15Sopenharmony_ci    pub struct OcspCertIdRef;
21892f3ab15Sopenharmony_ci}
21992f3ab15Sopenharmony_ci
22092f3ab15Sopenharmony_ciimpl OcspCertId {
22192f3ab15Sopenharmony_ci    /// Constructs a certificate ID for certificate `subject`.
22292f3ab15Sopenharmony_ci    #[corresponds(OCSP_cert_to_id)]
22392f3ab15Sopenharmony_ci    pub fn from_cert(
22492f3ab15Sopenharmony_ci        digest: MessageDigest,
22592f3ab15Sopenharmony_ci        subject: &X509Ref,
22692f3ab15Sopenharmony_ci        issuer: &X509Ref,
22792f3ab15Sopenharmony_ci    ) -> Result<OcspCertId, ErrorStack> {
22892f3ab15Sopenharmony_ci        unsafe {
22992f3ab15Sopenharmony_ci            cvt_p(ffi::OCSP_cert_to_id(
23092f3ab15Sopenharmony_ci                digest.as_ptr(),
23192f3ab15Sopenharmony_ci                subject.as_ptr(),
23292f3ab15Sopenharmony_ci                issuer.as_ptr(),
23392f3ab15Sopenharmony_ci            ))
23492f3ab15Sopenharmony_ci            .map(OcspCertId)
23592f3ab15Sopenharmony_ci        }
23692f3ab15Sopenharmony_ci    }
23792f3ab15Sopenharmony_ci}
23892f3ab15Sopenharmony_ci
23992f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
24092f3ab15Sopenharmony_ci    type CType = ffi::OCSP_RESPONSE;
24192f3ab15Sopenharmony_ci    fn drop = ffi::OCSP_RESPONSE_free;
24292f3ab15Sopenharmony_ci
24392f3ab15Sopenharmony_ci    pub struct OcspResponse;
24492f3ab15Sopenharmony_ci    pub struct OcspResponseRef;
24592f3ab15Sopenharmony_ci}
24692f3ab15Sopenharmony_ci
24792f3ab15Sopenharmony_ciimpl OcspResponse {
24892f3ab15Sopenharmony_ci    /// Creates an OCSP response from the status and optional body.
24992f3ab15Sopenharmony_ci    ///
25092f3ab15Sopenharmony_ci    /// A body should only be provided if `status` is `RESPONSE_STATUS_SUCCESSFUL`.
25192f3ab15Sopenharmony_ci    #[corresponds(OCSP_response_create)]
25292f3ab15Sopenharmony_ci    pub fn create(
25392f3ab15Sopenharmony_ci        status: OcspResponseStatus,
25492f3ab15Sopenharmony_ci        body: Option<&OcspBasicResponseRef>,
25592f3ab15Sopenharmony_ci    ) -> Result<OcspResponse, ErrorStack> {
25692f3ab15Sopenharmony_ci        unsafe {
25792f3ab15Sopenharmony_ci            ffi::init();
25892f3ab15Sopenharmony_ci
25992f3ab15Sopenharmony_ci            cvt_p(ffi::OCSP_response_create(
26092f3ab15Sopenharmony_ci                status.as_raw(),
26192f3ab15Sopenharmony_ci                body.map(|r| r.as_ptr()).unwrap_or(ptr::null_mut()),
26292f3ab15Sopenharmony_ci            ))
26392f3ab15Sopenharmony_ci            .map(OcspResponse)
26492f3ab15Sopenharmony_ci        }
26592f3ab15Sopenharmony_ci    }
26692f3ab15Sopenharmony_ci
26792f3ab15Sopenharmony_ci    from_der! {
26892f3ab15Sopenharmony_ci        /// Deserializes a DER-encoded OCSP response.
26992f3ab15Sopenharmony_ci        #[corresponds(d2i_OCSP_RESPONSE)]
27092f3ab15Sopenharmony_ci        from_der,
27192f3ab15Sopenharmony_ci        OcspResponse,
27292f3ab15Sopenharmony_ci        ffi::d2i_OCSP_RESPONSE
27392f3ab15Sopenharmony_ci    }
27492f3ab15Sopenharmony_ci}
27592f3ab15Sopenharmony_ci
27692f3ab15Sopenharmony_ciimpl OcspResponseRef {
27792f3ab15Sopenharmony_ci    to_der! {
27892f3ab15Sopenharmony_ci        /// Serializes the response to its standard DER encoding.
27992f3ab15Sopenharmony_ci        #[corresponds(i2d_OCSP_RESPONSE)]
28092f3ab15Sopenharmony_ci        to_der,
28192f3ab15Sopenharmony_ci        ffi::i2d_OCSP_RESPONSE
28292f3ab15Sopenharmony_ci    }
28392f3ab15Sopenharmony_ci
28492f3ab15Sopenharmony_ci    /// Returns the status of the response.
28592f3ab15Sopenharmony_ci    #[corresponds(OCSP_response_status)]
28692f3ab15Sopenharmony_ci    pub fn status(&self) -> OcspResponseStatus {
28792f3ab15Sopenharmony_ci        unsafe { OcspResponseStatus(ffi::OCSP_response_status(self.as_ptr())) }
28892f3ab15Sopenharmony_ci    }
28992f3ab15Sopenharmony_ci
29092f3ab15Sopenharmony_ci    /// Returns the basic response.
29192f3ab15Sopenharmony_ci    ///
29292f3ab15Sopenharmony_ci    /// This will only succeed if `status()` returns `RESPONSE_STATUS_SUCCESSFUL`.
29392f3ab15Sopenharmony_ci    #[corresponds(OCSP_response_get1_basic)]
29492f3ab15Sopenharmony_ci    pub fn basic(&self) -> Result<OcspBasicResponse, ErrorStack> {
29592f3ab15Sopenharmony_ci        unsafe { cvt_p(ffi::OCSP_response_get1_basic(self.as_ptr())).map(OcspBasicResponse) }
29692f3ab15Sopenharmony_ci    }
29792f3ab15Sopenharmony_ci}
29892f3ab15Sopenharmony_ci
29992f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
30092f3ab15Sopenharmony_ci    type CType = ffi::OCSP_REQUEST;
30192f3ab15Sopenharmony_ci    fn drop = ffi::OCSP_REQUEST_free;
30292f3ab15Sopenharmony_ci
30392f3ab15Sopenharmony_ci    pub struct OcspRequest;
30492f3ab15Sopenharmony_ci    pub struct OcspRequestRef;
30592f3ab15Sopenharmony_ci}
30692f3ab15Sopenharmony_ci
30792f3ab15Sopenharmony_ciimpl OcspRequest {
30892f3ab15Sopenharmony_ci    #[corresponds(OCSP_REQUEST_new)]
30992f3ab15Sopenharmony_ci    pub fn new() -> Result<OcspRequest, ErrorStack> {
31092f3ab15Sopenharmony_ci        unsafe {
31192f3ab15Sopenharmony_ci            ffi::init();
31292f3ab15Sopenharmony_ci
31392f3ab15Sopenharmony_ci            cvt_p(ffi::OCSP_REQUEST_new()).map(OcspRequest)
31492f3ab15Sopenharmony_ci        }
31592f3ab15Sopenharmony_ci    }
31692f3ab15Sopenharmony_ci
31792f3ab15Sopenharmony_ci    from_der! {
31892f3ab15Sopenharmony_ci        /// Deserializes a DER-encoded OCSP request.
31992f3ab15Sopenharmony_ci        #[corresponds(d2i_OCSP_REQUEST)]
32092f3ab15Sopenharmony_ci        from_der,
32192f3ab15Sopenharmony_ci        OcspRequest,
32292f3ab15Sopenharmony_ci        ffi::d2i_OCSP_REQUEST
32392f3ab15Sopenharmony_ci    }
32492f3ab15Sopenharmony_ci}
32592f3ab15Sopenharmony_ci
32692f3ab15Sopenharmony_ciimpl OcspRequestRef {
32792f3ab15Sopenharmony_ci    to_der! {
32892f3ab15Sopenharmony_ci        /// Serializes the request to its standard DER encoding.
32992f3ab15Sopenharmony_ci        #[corresponds(i2d_OCSP_REQUEST)]
33092f3ab15Sopenharmony_ci        to_der,
33192f3ab15Sopenharmony_ci        ffi::i2d_OCSP_REQUEST
33292f3ab15Sopenharmony_ci    }
33392f3ab15Sopenharmony_ci
33492f3ab15Sopenharmony_ci    #[corresponds(OCSP_request_add0_id)]
33592f3ab15Sopenharmony_ci    pub fn add_id(&mut self, id: OcspCertId) -> Result<&mut OcspOneReqRef, ErrorStack> {
33692f3ab15Sopenharmony_ci        unsafe {
33792f3ab15Sopenharmony_ci            let ptr = cvt_p(ffi::OCSP_request_add0_id(self.as_ptr(), id.as_ptr()))?;
33892f3ab15Sopenharmony_ci            mem::forget(id);
33992f3ab15Sopenharmony_ci            Ok(OcspOneReqRef::from_ptr_mut(ptr))
34092f3ab15Sopenharmony_ci        }
34192f3ab15Sopenharmony_ci    }
34292f3ab15Sopenharmony_ci}
34392f3ab15Sopenharmony_ci
34492f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
34592f3ab15Sopenharmony_ci    type CType = ffi::OCSP_ONEREQ;
34692f3ab15Sopenharmony_ci    fn drop = ffi::OCSP_ONEREQ_free;
34792f3ab15Sopenharmony_ci
34892f3ab15Sopenharmony_ci    pub struct OcspOneReq;
34992f3ab15Sopenharmony_ci    pub struct OcspOneReqRef;
35092f3ab15Sopenharmony_ci}
351