Skip to content

Commit

Permalink
refactor(ssl): use openssl::DirectStreams
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 23, 2015
1 parent da817ba commit 71db6a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -29,7 +29,7 @@ version = "0.1"
default-features = false

[dependencies.openssl]
version = "0.6"
version = "0.6.4"
optional = true

[dependencies.solicit]
Expand Down
21 changes: 16 additions & 5 deletions src/net.rs
Expand Up @@ -202,6 +202,20 @@ impl Write for HttpStream {
}
}

#[cfg(windows)]
impl ::std::os::windows::io::AsRawSocket for HttpStream {
fn as_raw_socket(&self) -> ::std::os::windows::io::RawSocket {
self.0.as_raw_socket()
}
}

#[cfg(unix)]
impl ::std::os::unix::io::AsRawFd for HttpStream {
fn as_raw_fd(&self) -> i32 {
self.0.as_raw_fd()
}
}

impl NetworkStream for HttpStream {
#[inline]
fn peer_addr(&mut self) -> io::Result<SocketAddr> {
Expand Down Expand Up @@ -439,16 +453,13 @@ mod openssl {
type Stream = SslStream<HttpStream>;

fn wrap_client(&self, stream: HttpStream, host: &str) -> ::Result<Self::Stream> {
//if let Some(ref verifier) = self.verifier {
// verifier(&mut context);
//}
let ssl = try!(Ssl::new(&self.context));
try!(ssl.set_hostname(host));
SslStream::new_from(ssl, stream).map_err(From::from)
SslStream::connect(ssl, stream).map_err(From::from)
}

fn wrap_server(&self, stream: HttpStream) -> ::Result<Self::Stream> {
match SslStream::new_server(&self.context, stream) {
match SslStream::accept(&*self.context, stream) {
Ok(ssl_stream) => Ok(ssl_stream),
Err(SslIoError(e)) => {
Err(io::Error::new(io::ErrorKind::ConnectionAborted, e).into())
Expand Down

0 comments on commit 71db6a4

Please sign in to comment.