Commit 3de9f26c authored by Steffen Eiden's avatar Steffen Eiden
Browse files

Add binding for X509_load_crl_file

parent 5b507990
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ extern "C" {
        ret: *mut *mut c_char,
    ) -> c_int;
    pub fn X509_load_cert_file(ctx: *mut X509_LOOKUP, file: *const c_char, _type: c_int) -> c_int;
    pub fn X509_load_crl_file(ctx: *mut X509_LOOKUP, file: *const c_char, _type: c_int) -> c_int;
}

extern "C" {
+19 −1
Original line number Diff line number Diff line
@@ -194,8 +194,9 @@ impl X509Lookup<File> {

#[cfg(not(boringssl))]
impl X509LookupRef<File> {
    #[corresponds(X509_load_cert_file)]
    /// Specifies a file from which certificates will be loaded
    #[corresponds(X509_load_cert_file)]
    // FIXME should return 'Result<i32, ErrorStack' like load_crl_file
    pub fn load_cert_file<P: AsRef<Path>>(
        &mut self,
        file: P,
@@ -211,6 +212,23 @@ impl X509LookupRef<File> {
            .map(|_| ())
        }
    }

    /// Specifies a file from which certificate revocation lists will be loaded
    #[corresponds(X509_load_crl_file)]
    pub fn load_crl_file<P: AsRef<Path>>(
        &mut self,
        file: P,
        file_type: SslFiletype,
    ) -> Result<i32, ErrorStack> {
        let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap();
        unsafe {
            cvt(ffi::X509_load_crl_file(
                self.as_ptr(),
                file.as_ptr(),
                file_type.as_raw(),
            ))
        }
    }
}

generic_foreign_type_and_impl_send_sync! {
+9 −0
Original line number Diff line number Diff line
@@ -786,3 +786,12 @@ fn test_add_name_entry() {
    assert_eq!(outp_name.data().as_slice(), inp_name.data().as_slice());
    assert!(entries.next().is_none());
}

#[test]
#[cfg(not(boringssl))]
fn test_load_crl_file_fail() {
    let mut store_bldr = X509StoreBuilder::new().unwrap();
    let lookup = store_bldr.add_lookup(X509Lookup::file()).unwrap();
    let res = lookup.load_crl_file("test/root-ca.pem", SslFiletype::PEM);
    assert!(res.is_err());
}