Unverified Commit d0999b56 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #1758 from Alis-dev/OSSLProviderSearchPath

Add OSSL_PROVIDER_set_default_search_path binding
parents 9405df4c b99d7265
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -12,4 +12,9 @@ extern "C" {
    ) -> *mut OSSL_PROVIDER;
    #[cfg(ossl300)]
    pub fn OSSL_PROVIDER_unload(prov: *mut OSSL_PROVIDER) -> c_int;
    #[cfg(ossl300)]
    pub fn OSSL_PROVIDER_set_default_search_path(
        ctx: *mut OSSL_LIB_CTX,
        path: *const c_char,
    ) -> c_int;
}
+17 −1
Original line number Diff line number Diff line
use crate::cvt_p;
use crate::error::ErrorStack;
use crate::lib_ctx::LibCtxRef;
use crate::{cvt, cvt_p};
use foreign_types::{ForeignType, ForeignTypeRef};
use openssl_macros::corresponds;
use std::ffi::CString;
@@ -58,4 +58,20 @@ impl Provider {
            Ok(Provider::from_ptr(p))
        }
    }

    /// Specifies the default search path that is to be used for looking for providers in the specified library context.
    /// If left unspecified, an environment variable and a fall back default value will be used instead
    ///
    /// If `ctx` is `None`, the provider will be loaded into the default library context.
    #[corresponds(OSSL_PROVIDER_set_default_search_path)]
    pub fn set_default_search_path(ctx: Option<&LibCtxRef>, path: &str) -> Result<(), ErrorStack> {
        let path = CString::new(path).unwrap();
        unsafe {
            cvt(ffi::OSSL_PROVIDER_set_default_search_path(
                ctx.map_or(ptr::null_mut(), ForeignTypeRef::as_ptr),
                path.as_ptr(),
            ))
            .map(|_| ())
        }
    }
}