Loading openssl/src/ssl/mod.rs +7 −7 Original line number Diff line number Diff line Loading @@ -899,14 +899,14 @@ impl<S: Read+Write> Read for SslStream<S> { impl<S: Read+Write> Write for SslStream<S> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { match self.in_retry_wrapper(|ssl| ssl.write(buf)) { Ok(len) => Ok(len as usize), Err(SslSessionClosed) => Ok(0), let count = match self.in_retry_wrapper(|ssl| ssl.write(buf)) { Ok(len) => len as usize, Err(SslSessionClosed) => 0, Err(StreamError(e)) => return Err(e), Err(e @ OpenSslErrors(_)) => { Err(io::Error::new(io::ErrorKind::Other, e)) } } Err(e @ OpenSslErrors(_)) => return Err(io::Error::new(io::ErrorKind::Other, e)), }; try!(self.write_through()); Ok(count) } fn flush(&mut self) -> io::Result<()> { Loading openssl/src/ssl/tests.rs +28 −3 Original line number Diff line number Diff line Loading @@ -4,9 +4,7 @@ use std::net::TcpStream; use std::io; use std::io::prelude::*; use std::path::Path; #[cfg(feature = "npn")] use std::net::TcpListener; #[cfg(feature = "npn")] use std::thread; use std::fs::File; Loading @@ -17,7 +15,6 @@ use ssl::SslMethod::Sslv23; use ssl::{SslContext, SslStream, VerifyCallback}; use ssl::SSL_VERIFY_PEER; use x509::X509StoreContext; #[cfg(feature = "npn")] use x509::X509FileType; use x509::X509; use crypto::pkey::PKey; Loading Loading @@ -237,6 +234,34 @@ run_test!(verify_callback_data, |method, stream| { } }); // Make sure every write call translates to a write call to the underlying socket. #[test] fn test_write_hits_stream() { let listener = TcpListener::bind("localhost:0").unwrap(); let addr = listener.local_addr().unwrap(); let guard = thread::spawn(move || { let ctx = SslContext::new(Sslv23).unwrap(); let stream = TcpStream::connect(addr).unwrap(); let mut stream = SslStream::new(&ctx, stream).unwrap(); stream.write_all(b"hello").unwrap(); stream }); let mut ctx = SslContext::new(Sslv23).unwrap(); ctx.set_verify(SSL_VERIFY_PEER, None); ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM).unwrap(); ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM).unwrap(); let stream = listener.accept().unwrap().0; let mut stream = SslStream::new_server(&ctx, stream).unwrap(); let mut buf = [0; 5]; assert_eq!(5, stream.read(&mut buf).unwrap()); assert_eq!(&b"hello"[..], &buf[..]); guard.join().unwrap(); } #[test] fn test_set_certificate_and_private_key() { let key_path = Path::new("test/key.pem"); Loading openssl/src/x509/tests.rs +0 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ use serialize::hex::FromHex; use std::io; use std::path::Path; use std::fs::File; use std::str; use crypto::hash::Type::{SHA256}; use x509::{X509, X509Generator}; Loading Loading
openssl/src/ssl/mod.rs +7 −7 Original line number Diff line number Diff line Loading @@ -899,14 +899,14 @@ impl<S: Read+Write> Read for SslStream<S> { impl<S: Read+Write> Write for SslStream<S> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { match self.in_retry_wrapper(|ssl| ssl.write(buf)) { Ok(len) => Ok(len as usize), Err(SslSessionClosed) => Ok(0), let count = match self.in_retry_wrapper(|ssl| ssl.write(buf)) { Ok(len) => len as usize, Err(SslSessionClosed) => 0, Err(StreamError(e)) => return Err(e), Err(e @ OpenSslErrors(_)) => { Err(io::Error::new(io::ErrorKind::Other, e)) } } Err(e @ OpenSslErrors(_)) => return Err(io::Error::new(io::ErrorKind::Other, e)), }; try!(self.write_through()); Ok(count) } fn flush(&mut self) -> io::Result<()> { Loading
openssl/src/ssl/tests.rs +28 −3 Original line number Diff line number Diff line Loading @@ -4,9 +4,7 @@ use std::net::TcpStream; use std::io; use std::io::prelude::*; use std::path::Path; #[cfg(feature = "npn")] use std::net::TcpListener; #[cfg(feature = "npn")] use std::thread; use std::fs::File; Loading @@ -17,7 +15,6 @@ use ssl::SslMethod::Sslv23; use ssl::{SslContext, SslStream, VerifyCallback}; use ssl::SSL_VERIFY_PEER; use x509::X509StoreContext; #[cfg(feature = "npn")] use x509::X509FileType; use x509::X509; use crypto::pkey::PKey; Loading Loading @@ -237,6 +234,34 @@ run_test!(verify_callback_data, |method, stream| { } }); // Make sure every write call translates to a write call to the underlying socket. #[test] fn test_write_hits_stream() { let listener = TcpListener::bind("localhost:0").unwrap(); let addr = listener.local_addr().unwrap(); let guard = thread::spawn(move || { let ctx = SslContext::new(Sslv23).unwrap(); let stream = TcpStream::connect(addr).unwrap(); let mut stream = SslStream::new(&ctx, stream).unwrap(); stream.write_all(b"hello").unwrap(); stream }); let mut ctx = SslContext::new(Sslv23).unwrap(); ctx.set_verify(SSL_VERIFY_PEER, None); ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM).unwrap(); ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM).unwrap(); let stream = listener.accept().unwrap().0; let mut stream = SslStream::new_server(&ctx, stream).unwrap(); let mut buf = [0; 5]; assert_eq!(5, stream.read(&mut buf).unwrap()); assert_eq!(&b"hello"[..], &buf[..]); guard.join().unwrap(); } #[test] fn test_set_certificate_and_private_key() { let key_path = Path::new("test/key.pem"); Loading
openssl/src/x509/tests.rs +0 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ use serialize::hex::FromHex; use std::io; use std::path::Path; use std::fs::File; use std::str; use crypto::hash::Type::{SHA256}; use x509::{X509, X509Generator}; Loading