boring/
conf.rs

1//! Interface for processing OpenSSL configuration files.
2use crate::ffi;
3use foreign_types::ForeignType;
4use libc::c_void;
5
6use crate::cvt_p;
7use crate::error::ErrorStack;
8
9pub struct ConfMethod(*mut c_void);
10
11impl ConfMethod {
12    /// Construct from raw pointer.
13    ///
14    /// # Safety
15    ///
16    /// The caller must ensure that the pointer is valid.
17    pub unsafe fn from_ptr(ptr: *mut c_void) -> ConfMethod {
18        ConfMethod(ptr)
19    }
20
21    /// Convert to raw pointer.
22    #[must_use]
23    pub fn as_ptr(&self) -> *mut c_void {
24        self.0
25    }
26}
27
28foreign_type_and_impl_send_sync! {
29    type CType = ffi::CONF;
30    fn drop = ffi::NCONF_free;
31
32    pub struct Conf;
33}
34
35impl Conf {
36    /// Create a configuration parser.
37    pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
38        unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(|p| Conf::from_ptr(p)) }
39    }
40}