openssl/
conf.rs

1//! Interface for processing OpenSSL configuration files.
2
3foreign_type_and_impl_send_sync! {
4    type CType = ffi::CONF;
5    fn drop = ffi::NCONF_free;
6
7    pub struct Conf;
8    pub struct ConfRef;
9}
10
11#[cfg(not(any(boringssl, libressl400, awslc)))]
12mod methods {
13    use super::Conf;
14    use crate::cvt_p;
15    use crate::error::ErrorStack;
16    use openssl_macros::corresponds;
17
18    pub struct ConfMethod(*mut ffi::CONF_METHOD);
19
20    impl ConfMethod {
21        /// Retrieve handle to the default OpenSSL configuration file processing function.
22        #[corresponds(NCONF_default)]
23        #[allow(clippy::should_implement_trait)]
24        pub fn default() -> ConfMethod {
25            unsafe {
26                ffi::init();
27                // `NCONF` stands for "New Conf", as described in crypto/conf/conf_lib.c. This is
28                // a newer API than the "CONF classic" functions.
29                ConfMethod(ffi::NCONF_default())
30            }
31        }
32
33        /// Construct from raw pointer.
34        ///
35        /// # Safety
36        ///
37        /// The caller must ensure that the pointer is valid.
38        pub unsafe fn from_ptr(ptr: *mut ffi::CONF_METHOD) -> ConfMethod {
39            ConfMethod(ptr)
40        }
41
42        /// Convert to raw pointer.
43        pub fn as_ptr(&self) -> *mut ffi::CONF_METHOD {
44            self.0
45        }
46    }
47
48    impl Conf {
49        /// Create a configuration parser.
50        ///
51        /// # Examples
52        ///
53        /// ```
54        /// use openssl::conf::{Conf, ConfMethod};
55        ///
56        /// let conf = Conf::new(ConfMethod::default());
57        /// ```
58        #[corresponds(NCONF_new)]
59        pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
60            unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(Conf) }
61        }
62    }
63}
64#[cfg(not(any(boringssl, libressl400, awslc)))]
65pub use methods::*;