From 6d4bfaa490af285443a7e8413040e58b889d2993 Mon Sep 17 00:00:00 2001 From: Leon Anavi Date: Tue, 22 Mar 2016 00:16:56 +0200 Subject: Cast correctly c_char raw pointers (fixes build on ARM #363) Fix error caused by mismatched types while building crate openssl for Raspberry Pi 2 and other ARM devices. Signed-off-by: Leon Anavi --- openssl/src/ssl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openssl/src/ssl') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 38527dc6..ebaffb18 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -827,7 +827,7 @@ impl <'a> SslCipher<'a> { let desc_ptr = ffi::SSL_CIPHER_description(self.cipher, buf.as_mut_ptr(), 128); if !desc_ptr.is_null() { - String::from_utf8(CStr::from_ptr(desc_ptr).to_bytes().to_vec()).ok() + String::from_utf8(CStr::from_ptr(desc_ptr as *const _).to_bytes().to_vec()).ok() } else { None } -- cgit v1.2.3 From c4187638a888f13d61ec1ce6a90840ed2f4777d3 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 27 Mar 2016 13:29:24 -0700 Subject: Update for nightly changes --- openssl/src/ssl/bio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openssl/src/ssl') diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 8d295928..26c23d4c 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -72,7 +72,7 @@ unsafe fn state<'a, S: 'a>(bio: *mut BIO) -> &'a mut StreamState { #[cfg(feature = "nightly")] fn recover(f: F) -> Result> where F: FnOnce() -> T { - ::std::panic::recover(::std::panic::AssertRecoverSafe::new(f)) + ::std::panic::recover(::std::panic::AssertRecoverSafe(f)) } #[cfg(not(feature = "nightly"))] -- cgit v1.2.3 From 02f114faae1f829b799afccdd8b0e370923f4178 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 27 Mar 2016 13:37:00 -0700 Subject: Cleanup --- openssl/src/ssl/bio.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'openssl/src/ssl') diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 26c23d4c..5accb3e5 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -86,9 +86,7 @@ unsafe extern "C" fn bwrite(bio: *mut BIO, buf: *const c_char, len: c_ let state = state::(bio); let buf = slice::from_raw_parts(buf as *const _, len as usize); - let result = recover(|| state.stream.write(buf)); - - match result { + match recover(|| state.stream.write(buf)) { Ok(Ok(len)) => len as c_int, Ok(Err(err)) => { if retriable_error(&err) { @@ -110,9 +108,7 @@ unsafe extern "C" fn bread(bio: *mut BIO, buf: *mut c_char, len: c_int) let state = state::(bio); let buf = slice::from_raw_parts_mut(buf as *mut _, len as usize); - let result = recover(|| state.stream.read(buf)); - - match result { + match recover(|| state.stream.read(buf)) { Ok(Ok(len)) => len as c_int, Ok(Err(err)) => { if retriable_error(&err) { @@ -146,9 +142,8 @@ unsafe extern "C" fn ctrl(bio: *mut BIO, -> c_long { if cmd == BIO_CTRL_FLUSH { let state = state::(bio); - let result = recover(|| state.stream.flush()); - match result { + match recover(|| state.stream.flush()) { Ok(Ok(())) => 1, Ok(Err(err)) => { state.error = Some(err); -- cgit v1.2.3 From c4b7b85d99b3e9ca154ba03be67bd6281825973c Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 4 Apr 2016 15:20:13 -0700 Subject: Add safe wrapper BioMethod for ffi::BIO_METHOD Adds a wrapper for ffi::BIO_METHOD located at ssl::bio::BioMethod. This enables SslStream to be Send without doing an unsafe impl on the ffi struct. --- openssl/src/ssl/bio.rs | 41 ++++++++++++++++++++++++++--------------- openssl/src/ssl/mod.rs | 6 +++--- 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'openssl/src/ssl') diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 5accb3e5..4adbfbe2 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -1,5 +1,5 @@ use libc::{c_char, c_int, c_long, c_void, strlen}; -use ffi::{BIO, BIO_METHOD, BIO_CTRL_FLUSH, BIO_TYPE_NONE, BIO_new}; +use ffi::{self, BIO, BIO_CTRL_FLUSH, BIO_TYPE_NONE, BIO_new}; use ffi_extras::{BIO_clear_retry_flags, BIO_set_retry_read, BIO_set_retry_write}; use std::any::Any; use std::io; @@ -17,19 +17,30 @@ pub struct StreamState { pub panic: Option>, } -pub fn new(stream: S) -> Result<(*mut BIO, Arc), SslError> { - let method = Arc::new(BIO_METHOD { - type_: BIO_TYPE_NONE, - name: b"rust\0".as_ptr() as *const _, - bwrite: Some(bwrite::), - bread: Some(bread::), - bputs: Some(bputs::), - bgets: None, - ctrl: Some(ctrl::), - create: Some(create), - destroy: Some(destroy::), - callback_ctrl: None, - }); +/// Safe wrapper for BIO_METHOD +pub struct BioMethod(ffi::BIO_METHOD); + +impl BioMethod { + pub fn new() -> BioMethod { + BioMethod(ffi::BIO_METHOD { + type_: BIO_TYPE_NONE, + name: b"rust\0".as_ptr() as *const _, + bwrite: Some(bwrite::), + bread: Some(bread::), + bputs: Some(bputs::), + bgets: None, + ctrl: Some(ctrl::), + create: Some(create), + destroy: Some(destroy::), + callback_ctrl: None, + }) + } +} + +unsafe impl Send for BioMethod {} + +pub fn new(stream: S) -> Result<(*mut BIO, Arc), SslError> { + let method = Arc::new(BioMethod::new::()); let state = Box::new(StreamState { stream: stream, @@ -38,7 +49,7 @@ pub fn new(stream: S) -> Result<(*mut BIO, Arc), Ss }); unsafe { - let bio = try_ssl_null!(BIO_new(&*method)); + let bio = try_ssl_null!(BIO_new(&method.0)); (*bio).ptr = Box::into_raw(state) as *mut _; (*bio).init = 1; diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index ebaffb18..7b5cf492 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -35,6 +35,8 @@ mod bio; #[cfg(test)] mod tests; +use self::bio::BioMethod; + #[doc(inline)] pub use ssl::error::Error; @@ -1117,12 +1119,10 @@ make_LibSslError! { /// A stream wrapper which handles SSL encryption for an underlying stream. pub struct SslStream { ssl: Ssl, - _method: Arc, // NOTE: this *must* be after the Ssl field so things drop right + _method: Arc, // NOTE: this *must* be after the Ssl field so things drop right _p: PhantomData, } -unsafe impl Send for SslStream {} - /// # Deprecated /// /// This method does not behave as expected and will be removed in a future -- cgit v1.2.3