1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Interface for processing OpenSSL configuration files.
use crate::ffi;
use foreign_types::ForeignType;
use libc::c_void;

use crate::cvt_p;
use crate::error::ErrorStack;

pub struct ConfMethod(*mut c_void);

impl ConfMethod {
    /// Construct from raw pointer.
    ///
    /// # Safety
    ///
    /// The caller must ensure that the pointer is valid.
    pub unsafe fn from_ptr(ptr: *mut c_void) -> ConfMethod {
        ConfMethod(ptr)
    }

    /// Convert to raw pointer.
    pub fn as_ptr(&self) -> *mut c_void {
        self.0
    }
}

foreign_type_and_impl_send_sync! {
    type CType = ffi::CONF;
    fn drop = ffi::NCONF_free;

    pub struct Conf;
}

impl Conf {
    /// Create a configuration parser.
    pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
        unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(|p| Conf::from_ptr(p)) }
    }
}