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