diff options
| author | Benjamin Saunders <[email protected]> | 2018-03-10 22:30:54 -0800 |
|---|---|---|
| committer | Benjamin Saunders <[email protected]> | 2018-03-10 22:30:54 -0800 |
| commit | e02dbde2f71a3406169c58e03a6cc8b90928945f (patch) | |
| tree | 66ff1986399491797fa6d31fe4804deda69c279d /openssl/src/ssl/callbacks.rs | |
| parent | High-level API for OpenSSL 1.1.1 custom extension support (diff) | |
| download | rust-openssl-e02dbde2f71a3406169c58e03a6cc8b90928945f.tar.xz rust-openssl-e02dbde2f71a3406169c58e03a6cc8b90928945f.zip | |
Generic custom extension add fn return type
Diffstat (limited to 'openssl/src/ssl/callbacks.rs')
| -rw-r--r-- | openssl/src/ssl/callbacks.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/openssl/src/ssl/callbacks.rs b/openssl/src/ssl/callbacks.rs index ca257e13..0531274c 100644 --- a/openssl/src/ssl/callbacks.rs +++ b/openssl/src/ssl/callbacks.rs @@ -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; @@ -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, - 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 +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<T>, SslAlert> + 'static, + T: AsRef<[u8]> + 'static, { unsafe { let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl as *const _); @@ -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)) @@ -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, - _: c_uint, - _: *mut *const c_uchar, - _: *mut c_void) +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(); } } |