Unverified Commit 41162e27 authored by Noah's avatar Noah
Browse files

Add a shim for X509_STORE_get0_objects and X509_OBJECT_free

parent 5c6179ce
Loading
Loading
Loading
Loading
+41 −2
Original line number Diff line number Diff line
@@ -342,8 +342,46 @@ cfg_if! {
    }
}
pub enum X509_CRL {}
stack!(stack_st_X509_CRL);

pub enum X509_NAME {}

cfg_if! {
    if #[cfg(any(ossl110, libressl270))] {
        pub enum X509_STORE {}
    } else {
        #[repr(C)]
        pub struct X509_STORE {
            cache: c_int,
            pub objs: *mut stack_st_X509_OBJECT,
            get_cert_methods: *mut stack_st_X509_LOOKUP,
            param: *mut X509_VERIFY_PARAM,
            verify: Option<extern "C" fn(ctx: *mut X509_STORE_CTX) -> c_int>,
            verify_cb: Option<extern "C" fn(ok: c_int, ctx: *mut X509_STORE_CTX) -> c_int>,
            get_issuer: Option<
                extern "C" fn(issuer: *mut *mut X509, ctx: *mut X509_STORE_CTX, x: *mut X509) -> c_int,
            >,
            check_issued:
                Option<extern "C" fn(ctx: *mut X509_STORE_CTX, x: *mut X509, issuer: *mut X509) -> c_int>,
            check_revocation: Option<extern "C" fn(ctx: *mut X509_STORE_CTX) -> c_int>,
            get_crl: Option<
                extern "C" fn(ctx: *mut X509_STORE_CTX, crl: *mut *mut X509_CRL, x: *mut X509) -> c_int,
            >,
            check_crl: Option<extern "C" fn(ctx: *mut X509_STORE_CTX, crl: *mut X509_CRL) -> c_int>,
            cert_crl:
                Option<extern "C" fn(ctx: *mut X509_STORE_CTX, crl: *mut X509_CRL, x: *mut X509) -> c_int>,
            lookup_certs:
                Option<extern "C" fn(ctx: *mut X509_STORE_CTX, nm: *const X509_NAME) -> *mut stack_st_X509>,
            lookup_crls: Option<
                extern "C" fn(ctx: *const X509_STORE_CTX, nm: *const X509_NAME) -> *mut stack_st_X509_CRL,
            >,
            cleanup: Option<extern "C" fn(ctx: *mut X509_STORE_CTX) -> c_int>,
            ex_data: CRYPTO_EX_DATA,
            references: c_int,
        }
    }
}

pub enum X509_STORE_CTX {}

cfg_if! {
@@ -375,7 +413,7 @@ cfg_if! {
            pub policies: *mut stack_st_ASN1_OBJECT,
            //pub id: *mut X509_VERIFY_PARAM_ID,
        }
    } else if #[cfg(ossl102)] {
    } else {
        #[repr(C)]
        pub struct X509_VERIFY_PARAM {
            pub name: *mut c_char,
@@ -386,6 +424,7 @@ cfg_if! {
            pub trust: c_int,
            pub depth: c_int,
            pub policies: *mut stack_st_ASN1_OBJECT,
            #[cfg(ossl102)]
            pub id: *mut X509_VERIFY_PARAM_ID,
        }
    }
+12 −3
Original line number Diff line number Diff line
@@ -103,6 +103,10 @@ cfg_if! {

stack!(stack_st_X509_OBJECT);

pub enum X509_LOOKUP {}

stack!(stack_st_X509_LOOKUP);

extern "C" {
    pub fn X509_verify_cert_error_string(n: c_long) -> *const c_char;

@@ -377,15 +381,20 @@ extern "C" {
    pub fn X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int;
}

#[cfg(any(ossl110, libressl270))]
extern "C" {
    pub fn X509_STORE_get0_objects(ctx: *mut X509_STORE) -> *mut stack_st_X509_OBJECT;
    pub fn X509_OBJECT_free(a: *mut X509_OBJECT);
    pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509;
}

cfg_if! {
    if #[cfg(any(ossl110, libressl270))] {
    if #[cfg(ossl110)] {
        extern "C" {
            pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509;
            pub fn X509_OBJECT_free(a: *mut X509_OBJECT);
        }
    } else {
        extern "C" {
            pub fn X509_OBJECT_free_contents(a: *mut X509_OBJECT);
        }
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -1324,7 +1324,7 @@ impl X509AlgorithmRef {

foreign_type_and_impl_send_sync! {
    type CType = ffi::X509_OBJECT;
    fn drop = ffi::X509_OBJECT_free;
    fn drop = X509_OBJECT_free;

    /// An `X509` or an X509 certificate revocation list.
    pub struct X509Object;
@@ -1444,3 +1444,15 @@ cfg_if! {
        }
    }
}

cfg_if! {
    if #[cfg(ossl110)] {
        use ffi::X509_OBJECT_free;
    } else {
        #[allow(bad_style)]
        unsafe fn X509_OBJECT_free(x: *mut ffi::X509_OBJECT) {
            ffi::X509_OBJECT_free_contents(x);
            ffi::CRYPTO_free(x as *mut libc::c_void);
        }
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -109,6 +109,17 @@ foreign_type_and_impl_send_sync! {
impl X509StoreRef {
    /// Get a reference to the cache of certificates in this store.
    pub fn certs(&self) -> &StackRef<X509Object> {
        unsafe { StackRef::from_ptr(ffi::X509_STORE_get0_objects(self.as_ptr())) }
        unsafe { StackRef::from_ptr(X509_STORE_get0_objects(self.as_ptr())) }
    }
}

cfg_if! {
    if #[cfg(any(ossl110, libressl270))] {
        use ffi::X509_STORE_get0_objects;
    } else {
        #[allow(bad_style)]
        unsafe fn X509_STORE_get0_objects(x: *mut ffi::X509_STORE) -> *mut ffi::stack_st_X509_OBJECT {
            (*x).objs
        }
    }
}