Skip to content

Commit f6f74af

Browse files
authored
Merge pull request #2353 from sfackler/verify-locations
Expose SSL_CTX_load_verify_locations
2 parents b255dee + 555d498 commit f6f74af

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

openssl/src/ssl/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -924,12 +924,23 @@ impl SslContextBuilder {
924924
/// The file should contain a sequence of PEM-formatted CA certificates.
925925
#[corresponds(SSL_CTX_load_verify_locations)]
926926
pub fn set_ca_file<P: AsRef<Path>>(&mut self, file: P) -> Result<(), ErrorStack> {
927-
let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap();
927+
self.load_verify_locations(Some(file.as_ref()), None)
928+
}
929+
930+
/// Loads trusted root certificates from a file and/or a directory.
931+
#[corresponds(SSL_CTX_load_verify_locations)]
932+
pub fn load_verify_locations(
933+
&mut self,
934+
ca_file: Option<&Path>,
935+
ca_path: Option<&Path>,
936+
) -> Result<(), ErrorStack> {
937+
let ca_file = ca_file.map(|p| CString::new(p.as_os_str().to_str().unwrap()).unwrap());
938+
let ca_path = ca_path.map(|p| CString::new(p.as_os_str().to_str().unwrap()).unwrap());
928939
unsafe {
929940
cvt(ffi::SSL_CTX_load_verify_locations(
930941
self.as_ptr(),
931-
file.as_ptr() as *const _,
932-
ptr::null(),
942+
ca_file.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
943+
ca_path.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
933944
))
934945
.map(|_| ())
935946
}

0 commit comments

Comments
 (0)