boring_imp/
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    pub fn as_ptr(&self) -> *mut c_void {
23        self.0
24    }
25}
26
27foreign_type_and_impl_send_sync! {
28    type CType = ffi::CONF;
29    fn drop = ffi::NCONF_free;
30
31    pub struct Conf;
32}
33
34impl Conf {
35    /// Create a configuration parser.
36    pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
37        unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(|p| Conf::from_ptr(p)) }
38    }
39}