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

Merge pull request #799 from sfackler/no-any

Drop Any bounds
parents fdb8909c ce0641f0
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
use ffi;
use libc::{c_char, c_int, c_uchar, c_uint, c_void};
use std::any::Any;
use std::ffi::CStr;
use std::ptr;
use std::slice;
@@ -18,7 +17,7 @@ use x509::X509StoreContextRef;

pub extern "C" fn raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int
where
    F: Fn(bool, &mut X509StoreContextRef) -> bool + Any + 'static + Sync + Send,
    F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
{
    unsafe {
        let idx = ffi::SSL_get_ex_data_X509_STORE_CTX_idx();
@@ -44,7 +43,6 @@ pub extern "C" fn raw_psk<F>(
) -> c_uint
where
    F: Fn(&mut SslRef, Option<&[u8]>, &mut [u8], &mut [u8]) -> Result<usize, ErrorStack>
        + Any
        + 'static
        + Sync
        + Send,
@@ -74,7 +72,7 @@ pub extern "C" fn ssl_raw_verify<F>(
    x509_ctx: *mut ffi::X509_STORE_CTX,
) -> c_int
where
    F: Fn(bool, &mut X509StoreContextRef) -> bool + Any + 'static + Sync + Send,
    F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
{
    unsafe {
        let idx = ffi::SSL_get_ex_data_X509_STORE_CTX_idx();
@@ -90,7 +88,7 @@ where

pub extern "C" fn raw_sni<F>(ssl: *mut ffi::SSL, al: *mut c_int, _arg: *mut c_void) -> c_int
where
    F: Fn(&mut SslRef) -> Result<(), SniError> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef) -> Result<(), SniError> + 'static + Sync + Send,
{
    unsafe {
        let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl);
@@ -175,7 +173,7 @@ pub unsafe extern "C" fn raw_tmp_dh<F>(
    keylength: c_int,
) -> *mut ffi::DH
where
    F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + 'static + Sync + Send,
{
    let ctx = ffi::SSL_get_SSL_CTX(ssl);
    let callback = ffi::SSL_CTX_get_ex_data(ctx, get_callback_idx::<F>());
@@ -202,7 +200,7 @@ pub unsafe extern "C" fn raw_tmp_ecdh<F>(
    keylength: c_int,
) -> *mut ffi::EC_KEY
where
    F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + 'static + Sync + Send,
{
    let ctx = ffi::SSL_get_SSL_CTX(ssl);
    let callback = ffi::SSL_CTX_get_ex_data(ctx, get_callback_idx::<F>());
@@ -228,7 +226,7 @@ pub unsafe extern "C" fn raw_tmp_dh_ssl<F>(
    keylength: c_int,
) -> *mut ffi::DH
where
    F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + 'static + Sync + Send,
{
    let callback = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<F>());
    let callback = &*(callback as *mut F);
@@ -254,7 +252,7 @@ pub unsafe extern "C" fn raw_tmp_ecdh_ssl<F>(
    keylength: c_int,
) -> *mut ffi::EC_KEY
where
    F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + 'static + Sync + Send,
{
    let callback = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<F>());
    let callback = &*(callback as *mut F);
@@ -275,7 +273,7 @@ where

pub unsafe extern "C" fn raw_tlsext_status<F>(ssl: *mut ffi::SSL, _: *mut c_void) -> c_int
where
    F: Fn(&mut SslRef) -> Result<bool, ErrorStack> + Any + 'static + Sync + Send,
    F: Fn(&mut SslRef) -> Result<bool, ErrorStack> + 'static + Sync + Send,
{
    let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl as *const _);
    let callback = ffi::SSL_CTX_get_ex_data(ssl_ctx, get_callback_idx::<F>());
+2 −3
Original line number Diff line number Diff line
use std::any::Any;
use std::error;
use std::error::Error as StdError;
use std::fmt;
@@ -107,7 +106,7 @@ pub enum HandshakeError<S> {
    WouldBlock(MidHandshakeSslStream<S>),
}

impl<S: Any + fmt::Debug> StdError for HandshakeError<S> {
impl<S: fmt::Debug> StdError for HandshakeError<S> {
    fn description(&self) -> &str {
        match *self {
            HandshakeError::SetupFailure(_) => "stream setup failed",
@@ -124,7 +123,7 @@ impl<S: Any + fmt::Debug> StdError for HandshakeError<S> {
    }
}

impl<S: Any + fmt::Debug> fmt::Display for HandshakeError<S> {
impl<S: fmt::Debug> fmt::Display for HandshakeError<S> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(StdError::description(self))?;
        match *self {
+10 −12
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ use ffi;
use foreign_types::{ForeignType, ForeignTypeRef, Opaque};
use libc::{c_int, c_long, c_ulong, c_void};
use libc::{c_uchar, c_uint};
use std::any::Any;
use std::any::TypeId;
use std::cmp;
use std::collections::HashMap;
@@ -351,7 +350,7 @@ lazy_static! {
// Creates a static index for user data of type T
// Registers a destructor for the data which will be called
// when context is freed
fn get_callback_idx<T: Any + 'static>() -> c_int {
fn get_callback_idx<T: 'static>() -> c_int {
    *INDEXES
        .lock()
        .unwrap()
@@ -359,7 +358,7 @@ fn get_callback_idx<T: Any + 'static>() -> c_int {
        .or_insert_with(|| get_new_idx::<T>())
}

fn get_ssl_callback_idx<T: Any + 'static>() -> c_int {
fn get_ssl_callback_idx<T: 'static>() -> c_int {
    *SSL_INDEXES
        .lock()
        .unwrap()
@@ -490,7 +489,7 @@ impl SslContextBuilder {
    pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
    where
        // FIXME should take a mutable reference to the store
        F: Fn(bool, &mut X509StoreContextRef) -> bool + Any + 'static + Sync + Send,
        F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
    {
        unsafe {
            let verify = Box::new(verify);
@@ -516,7 +515,7 @@ impl SslContextBuilder {
    /// [`SSL_CTX_set_tlsext_servername_callback`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_tlsext_servername_callback.html
    pub fn set_servername_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef) -> Result<(), SniError> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef) -> Result<(), SniError> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);
@@ -612,7 +611,7 @@ impl SslContextBuilder {
    /// [`SSL_CTX_set_tmp_dh_callback`]: https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_tmp_dh.html
    pub fn set_tmp_dh_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);
@@ -650,7 +649,7 @@ impl SslContextBuilder {
    #[cfg(any(all(feature = "v101", ossl101), all(feature = "v102", ossl102)))]
    pub fn set_tmp_ecdh_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);
@@ -1022,7 +1021,7 @@ impl SslContextBuilder {
    /// [`SSL_CTX_set_tlsext_status_cb`]: https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_tlsext_status_cb.html
    pub fn set_status_callback<F>(&mut self, callback: F) -> Result<(), ErrorStack>
    where
        F: Fn(&mut SslRef) -> Result<bool, ErrorStack> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef) -> Result<bool, ErrorStack> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);
@@ -1051,7 +1050,6 @@ impl SslContextBuilder {
    pub fn set_psk_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef, Option<&[u8]>, &mut [u8], &mut [u8]) -> Result<usize, ErrorStack>
            + Any
            + 'static
            + Sync
            + Send,
@@ -1500,7 +1498,7 @@ impl SslRef {
    pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
    where
        // FIXME should take a mutable reference to the x509 store
        F: Fn(bool, &mut X509StoreContextRef) -> bool + Any + 'static + Sync + Send,
        F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
    {
        unsafe {
            let verify = Box::new(verify);
@@ -1531,7 +1529,7 @@ impl SslRef {
    /// [`SSL_set_tmp_dh_callback`]: https://www.openssl.org/docs/man1.0.2/ssl/SSL_set_tmp_dh.html
    pub fn set_tmp_dh_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef, bool, u32) -> Result<Dh, ErrorStack> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);
@@ -1564,7 +1562,7 @@ impl SslRef {
    #[cfg(any(all(feature = "v101", ossl101), all(feature = "v102", ossl102)))]
    pub fn set_tmp_ecdh_callback<F>(&mut self, callback: F)
    where
        F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + Any + 'static + Sync + Send,
        F: Fn(&mut SslRef, bool, u32) -> Result<EcKey, ErrorStack> + 'static + Sync + Send,
    {
        unsafe {
            let callback = Box::new(callback);