192f3ab15Sopenharmony_ci//! Interface for processing OpenSSL configuration files.
292f3ab15Sopenharmony_ci
392f3ab15Sopenharmony_ciforeign_type_and_impl_send_sync! {
492f3ab15Sopenharmony_ci    type CType = ffi::CONF;
592f3ab15Sopenharmony_ci    fn drop = ffi::NCONF_free;
692f3ab15Sopenharmony_ci
792f3ab15Sopenharmony_ci    pub struct Conf;
892f3ab15Sopenharmony_ci    pub struct ConfRef;
992f3ab15Sopenharmony_ci}
1092f3ab15Sopenharmony_ci
1192f3ab15Sopenharmony_ci#[cfg(not(boringssl))]
1292f3ab15Sopenharmony_cimod methods {
1392f3ab15Sopenharmony_ci    use super::Conf;
1492f3ab15Sopenharmony_ci    use crate::cvt_p;
1592f3ab15Sopenharmony_ci    use crate::error::ErrorStack;
1692f3ab15Sopenharmony_ci    use openssl_macros::corresponds;
1792f3ab15Sopenharmony_ci
1892f3ab15Sopenharmony_ci    pub struct ConfMethod(*mut ffi::CONF_METHOD);
1992f3ab15Sopenharmony_ci
2092f3ab15Sopenharmony_ci    impl ConfMethod {
2192f3ab15Sopenharmony_ci        /// Retrieve handle to the default OpenSSL configuration file processing function.
2292f3ab15Sopenharmony_ci        #[corresponds(NCONF_default)]
2392f3ab15Sopenharmony_ci        #[allow(clippy::should_implement_trait)]
2492f3ab15Sopenharmony_ci        pub fn default() -> ConfMethod {
2592f3ab15Sopenharmony_ci            unsafe {
2692f3ab15Sopenharmony_ci                ffi::init();
2792f3ab15Sopenharmony_ci                // `NCONF` stands for "New Conf", as described in crypto/conf/conf_lib.c. This is
2892f3ab15Sopenharmony_ci                // a newer API than the "CONF classic" functions.
2992f3ab15Sopenharmony_ci                ConfMethod(ffi::NCONF_default())
3092f3ab15Sopenharmony_ci            }
3192f3ab15Sopenharmony_ci        }
3292f3ab15Sopenharmony_ci
3392f3ab15Sopenharmony_ci        /// Construct from raw pointer.
3492f3ab15Sopenharmony_ci        ///
3592f3ab15Sopenharmony_ci        /// # Safety
3692f3ab15Sopenharmony_ci        ///
3792f3ab15Sopenharmony_ci        /// The caller must ensure that the pointer is valid.
3892f3ab15Sopenharmony_ci        pub unsafe fn from_ptr(ptr: *mut ffi::CONF_METHOD) -> ConfMethod {
3992f3ab15Sopenharmony_ci            ConfMethod(ptr)
4092f3ab15Sopenharmony_ci        }
4192f3ab15Sopenharmony_ci
4292f3ab15Sopenharmony_ci        /// Convert to raw pointer.
4392f3ab15Sopenharmony_ci        pub fn as_ptr(&self) -> *mut ffi::CONF_METHOD {
4492f3ab15Sopenharmony_ci            self.0
4592f3ab15Sopenharmony_ci        }
4692f3ab15Sopenharmony_ci    }
4792f3ab15Sopenharmony_ci
4892f3ab15Sopenharmony_ci    impl Conf {
4992f3ab15Sopenharmony_ci        /// Create a configuration parser.
5092f3ab15Sopenharmony_ci        ///
5192f3ab15Sopenharmony_ci        /// # Examples
5292f3ab15Sopenharmony_ci        ///
5392f3ab15Sopenharmony_ci        /// ```
5492f3ab15Sopenharmony_ci        /// use openssl::conf::{Conf, ConfMethod};
5592f3ab15Sopenharmony_ci        ///
5692f3ab15Sopenharmony_ci        /// let conf = Conf::new(ConfMethod::default());
5792f3ab15Sopenharmony_ci        /// ```
5892f3ab15Sopenharmony_ci        #[corresponds(NCONF_new)]
5992f3ab15Sopenharmony_ci        pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
6092f3ab15Sopenharmony_ci            unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(Conf) }
6192f3ab15Sopenharmony_ci        }
6292f3ab15Sopenharmony_ci    }
6392f3ab15Sopenharmony_ci}
6492f3ab15Sopenharmony_ci#[cfg(not(boringssl))]
6592f3ab15Sopenharmony_cipub use methods::*;
66