Loading openssl/src/ssl/callbacks.rs +21 −21 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ use ffi; use libc::{c_char, c_int, c_uchar, c_uint, c_void}; #[cfg(all(feature = "v111", ossl111))] use libc::size_t; #[cfg(all(feature = "v111", ossl111))] use std::borrow::Cow; use std::ffi::CStr; use std::ptr; use std::slice; Loading Loading @@ -426,17 +424,18 @@ where } #[cfg(all(feature = "v111", ossl111))] pub struct CustomExtAddState(Option<Cow<'static, [u8]>>); pub struct CustomExtAddState<T>(Option<T>); #[cfg(all(feature = "v111", ossl111))] pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, pub extern "C" fn raw_custom_ext_add<F, T>(ssl: *mut ffi::SSL, _: c_uint, context: c_uint, out: *mut *const c_uchar, outlen: *mut size_t, x: *mut ffi::X509, chainidx: size_t, al: *mut c_int, _: *mut c_void) -> c_int where F: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<Cow<'static, [u8]>>, SslAlert> + 'static where F: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<T>, SslAlert> + 'static, T: AsRef<[u8]> + 'static, { unsafe { let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl as *const _); Loading @@ -448,13 +447,13 @@ pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, match (callback)(ssl, ectx, cert) { Ok(None) => 0, Ok(Some(buf)) => { *outlen = buf.len() as size_t; *out = buf.as_ptr(); *outlen = buf.as_ref().len() as size_t; *out = buf.as_ref().as_ptr(); let idx = get_ssl_callback_idx::<CustomExtAddState>(); let idx = get_ssl_callback_idx::<CustomExtAddState<T>>(); let ptr = ffi::SSL_get_ex_data(ssl.as_ptr(), idx); if ptr.is_null() { let x = Box::into_raw(Box::<CustomExtAddState>::new(CustomExtAddState(Some(buf)))) as *mut c_void; let x = Box::into_raw(Box::<CustomExtAddState<T>>::new(CustomExtAddState(Some(buf)))) as *mut c_void; ffi::SSL_set_ex_data(ssl.as_ptr(), idx, x); } else { *(ptr as *mut _) = CustomExtAddState(Some(buf)) Loading @@ -470,14 +469,15 @@ pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, } #[cfg(all(feature = "v111", ossl111))] pub extern "C" fn raw_custom_ext_free(ssl: *mut ffi::SSL, _: c_uint, pub extern "C" fn raw_custom_ext_free<T>(ssl: *mut ffi::SSL, _: c_uint, _: c_uint, _: *mut *const c_uchar, _: *mut c_void) where T: 'static { unsafe { let state = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<CustomExtAddState>()); let state = &mut (*(state as *mut CustomExtAddState)).0; let state = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<CustomExtAddState<T>>()); let state = &mut (*(state as *mut CustomExtAddState<T>)).0; state.take(); } } Loading openssl/src/ssl/mod.rs +7 −7 Original line number Diff line number Diff line Loading @@ -61,8 +61,6 @@ use ffi; use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; use std::any::TypeId; #[cfg(all(feature = "v111", ossl111))] use std::borrow::Cow; use std::cmp; use std::collections::HashMap; use std::ffi::{CStr, CString}; Loading Loading @@ -1511,10 +1509,12 @@ impl SslContextBuilder { /// /// [`SSL_CTX_add_custom_ext`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_add_custom_ext.html #[cfg(all(feature = "v111", ossl111))] pub fn add_custom_ext<AddFn, ParseFn>(&mut self, ext_type: u16, context: ExtensionContext, add_cb: AddFn, parse_cb: ParseFn) -> Result<(), ErrorStack> pub fn add_custom_ext<AddFn, ParseFn, T>( &mut self, ext_type: u16, context: ExtensionContext, add_cb: AddFn, parse_cb: ParseFn ) -> Result<(), ErrorStack> where AddFn: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<Cow<'static, [u8]>>, SslAlert> + 'static + Sync + Send, -> Result<Option<T>, SslAlert> + 'static + Sync + Send, T: AsRef<[u8]> + 'static, ParseFn: Fn(&mut SslRef, ExtensionContext, &[u8], Option<(usize, &X509Ref)>) -> Result<(), SslAlert> + 'static + Sync + Send, { Loading @@ -1534,8 +1534,8 @@ impl SslContextBuilder { ); ffi::SSL_CTX_add_custom_ext(self.as_ptr(), ext_type as c_uint, context.bits(), Some(raw_custom_ext_add::<AddFn>), Some(raw_custom_ext_free), Some(raw_custom_ext_add::<AddFn, T>), Some(raw_custom_ext_free::<T>), ptr::null_mut(), Some(raw_custom_ext_parse::<ParseFn>), ptr::null_mut()) Loading openssl/src/ssl/test.rs +2 −2 Original line number Diff line number Diff line Loading @@ -1370,7 +1370,7 @@ fn custom_extensions() { .unwrap(); ctx.add_custom_ext( 12345, ssl::ExtensionContext::CLIENT_HELLO, |_, _, _| unreachable!(), |_, _, _| -> Result<Option<&'static [u8]>, _> { unreachable!() }, |_, _, data, _| { FOUND_EXTENSION.store(data == b"hello", Ordering::SeqCst); Ok(()) } ).unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap(); Loading @@ -1381,7 +1381,7 @@ fn custom_extensions() { let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); ctx.add_custom_ext( 12345, ssl::ExtensionContext::CLIENT_HELLO, |_, _, _| Ok(Some(b"hello"[..].into())), |_, _, _| Ok(Some(b"hello")), |_, _, _, _| unreachable!() ).unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap(); Loading Loading
openssl/src/ssl/callbacks.rs +21 −21 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ use ffi; use libc::{c_char, c_int, c_uchar, c_uint, c_void}; #[cfg(all(feature = "v111", ossl111))] use libc::size_t; #[cfg(all(feature = "v111", ossl111))] use std::borrow::Cow; use std::ffi::CStr; use std::ptr; use std::slice; Loading Loading @@ -426,17 +424,18 @@ where } #[cfg(all(feature = "v111", ossl111))] pub struct CustomExtAddState(Option<Cow<'static, [u8]>>); pub struct CustomExtAddState<T>(Option<T>); #[cfg(all(feature = "v111", ossl111))] pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, pub extern "C" fn raw_custom_ext_add<F, T>(ssl: *mut ffi::SSL, _: c_uint, context: c_uint, out: *mut *const c_uchar, outlen: *mut size_t, x: *mut ffi::X509, chainidx: size_t, al: *mut c_int, _: *mut c_void) -> c_int where F: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<Cow<'static, [u8]>>, SslAlert> + 'static where F: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<T>, SslAlert> + 'static, T: AsRef<[u8]> + 'static, { unsafe { let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl as *const _); Loading @@ -448,13 +447,13 @@ pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, match (callback)(ssl, ectx, cert) { Ok(None) => 0, Ok(Some(buf)) => { *outlen = buf.len() as size_t; *out = buf.as_ptr(); *outlen = buf.as_ref().len() as size_t; *out = buf.as_ref().as_ptr(); let idx = get_ssl_callback_idx::<CustomExtAddState>(); let idx = get_ssl_callback_idx::<CustomExtAddState<T>>(); let ptr = ffi::SSL_get_ex_data(ssl.as_ptr(), idx); if ptr.is_null() { let x = Box::into_raw(Box::<CustomExtAddState>::new(CustomExtAddState(Some(buf)))) as *mut c_void; let x = Box::into_raw(Box::<CustomExtAddState<T>>::new(CustomExtAddState(Some(buf)))) as *mut c_void; ffi::SSL_set_ex_data(ssl.as_ptr(), idx, x); } else { *(ptr as *mut _) = CustomExtAddState(Some(buf)) Loading @@ -470,14 +469,15 @@ pub extern "C" fn raw_custom_ext_add<F>(ssl: *mut ffi::SSL, _: c_uint, } #[cfg(all(feature = "v111", ossl111))] pub extern "C" fn raw_custom_ext_free(ssl: *mut ffi::SSL, _: c_uint, pub extern "C" fn raw_custom_ext_free<T>(ssl: *mut ffi::SSL, _: c_uint, _: c_uint, _: *mut *const c_uchar, _: *mut c_void) where T: 'static { unsafe { let state = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<CustomExtAddState>()); let state = &mut (*(state as *mut CustomExtAddState)).0; let state = ffi::SSL_get_ex_data(ssl, get_ssl_callback_idx::<CustomExtAddState<T>>()); let state = &mut (*(state as *mut CustomExtAddState<T>)).0; state.take(); } } Loading
openssl/src/ssl/mod.rs +7 −7 Original line number Diff line number Diff line Loading @@ -61,8 +61,6 @@ use ffi; use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; use std::any::TypeId; #[cfg(all(feature = "v111", ossl111))] use std::borrow::Cow; use std::cmp; use std::collections::HashMap; use std::ffi::{CStr, CString}; Loading Loading @@ -1511,10 +1509,12 @@ impl SslContextBuilder { /// /// [`SSL_CTX_add_custom_ext`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_add_custom_ext.html #[cfg(all(feature = "v111", ossl111))] pub fn add_custom_ext<AddFn, ParseFn>(&mut self, ext_type: u16, context: ExtensionContext, add_cb: AddFn, parse_cb: ParseFn) -> Result<(), ErrorStack> pub fn add_custom_ext<AddFn, ParseFn, T>( &mut self, ext_type: u16, context: ExtensionContext, add_cb: AddFn, parse_cb: ParseFn ) -> Result<(), ErrorStack> where AddFn: Fn(&mut SslRef, ExtensionContext, Option<(usize, &X509Ref)>) -> Result<Option<Cow<'static, [u8]>>, SslAlert> + 'static + Sync + Send, -> Result<Option<T>, SslAlert> + 'static + Sync + Send, T: AsRef<[u8]> + 'static, ParseFn: Fn(&mut SslRef, ExtensionContext, &[u8], Option<(usize, &X509Ref)>) -> Result<(), SslAlert> + 'static + Sync + Send, { Loading @@ -1534,8 +1534,8 @@ impl SslContextBuilder { ); ffi::SSL_CTX_add_custom_ext(self.as_ptr(), ext_type as c_uint, context.bits(), Some(raw_custom_ext_add::<AddFn>), Some(raw_custom_ext_free), Some(raw_custom_ext_add::<AddFn, T>), Some(raw_custom_ext_free::<T>), ptr::null_mut(), Some(raw_custom_ext_parse::<ParseFn>), ptr::null_mut()) Loading
openssl/src/ssl/test.rs +2 −2 Original line number Diff line number Diff line Loading @@ -1370,7 +1370,7 @@ fn custom_extensions() { .unwrap(); ctx.add_custom_ext( 12345, ssl::ExtensionContext::CLIENT_HELLO, |_, _, _| unreachable!(), |_, _, _| -> Result<Option<&'static [u8]>, _> { unreachable!() }, |_, _, data, _| { FOUND_EXTENSION.store(data == b"hello", Ordering::SeqCst); Ok(()) } ).unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap(); Loading @@ -1381,7 +1381,7 @@ fn custom_extensions() { let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); ctx.add_custom_ext( 12345, ssl::ExtensionContext::CLIENT_HELLO, |_, _, _| Ok(Some(b"hello"[..].into())), |_, _, _| Ok(Some(b"hello")), |_, _, _, _| unreachable!() ).unwrap(); let ssl = Ssl::new(&ctx.build()).unwrap(); Loading