Skip to content

Commit ed26ff0

Browse files
committed
Merge branch 'breaks'
2 parents 9343ed2 + ae384d8 commit ed26ff0

File tree

9 files changed

+258
-154
lines changed

9 files changed

+258
-154
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ before_script:
88
- "./.travis/setup.sh"
99
script:
1010
- cargo test
11-
- cargo test --features "uuid rustc-serialize time unix_socket serde chrono"
11+
- cargo test --features "uuid rustc-serialize time unix_socket serde chrono openssl"
1212
- cargo doc --no-deps --features "unix_socket"
1313
after_success:
1414
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && test $TRAVIS_RUST_VERSION == "nightly" && ./.travis/update_docs.sh

Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ path = "tests/test.rs"
2424
phf_codegen = "0.7"
2525

2626
[dependencies]
27-
phf = "0.7"
28-
openssl = "0.6"
29-
log = "0.3"
30-
rustc-serialize = "0.3"
27+
bufstream = "0.1"
3128
byteorder = "0.3"
3229
debug-builders = "0.1"
33-
bufstream = "0.1"
34-
uuid = { version = "0.1", optional = true }
35-
unix_socket = { version = "0.3", optional = true }
36-
time = { version = "0.1.14", optional = true }
37-
serde = { version = "0.3", optional = true }
30+
log = "0.3"
31+
phf = "0.7"
32+
rust-crypto = "0.2"
33+
rustc-serialize = "0.3"
3834
chrono = { version = "0.2.14", optional = true }
35+
openssl = { version = "0.6", optional = true }
36+
serde = { version = "0.3", optional = true }
37+
time = { version = "0.1.14", optional = true }
38+
unix_socket = { version = "0.3", optional = true }
39+
uuid = { version = "0.1", optional = true }
3940

4041
[dev-dependencies]
4142
url = "0.2"

src/error.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub use ugh_privacy::DbError;
22

33
use byteorder;
4-
use openssl::ssl::error::SslError;
54
use phf;
65
use std::error;
76
use std::convert::From;
@@ -29,8 +28,8 @@ pub enum ConnectError {
2928
UnsupportedAuthentication,
3029
/// The Postgres server does not support SSL encryption.
3130
NoSslSupport,
32-
/// There was an error initializing the SSL session.
33-
SslError(SslError),
31+
/// There was an error initializing the SSL session
32+
SslError(Box<error::Error>),
3433
/// There was an error communicating with the server.
3534
IoError(io::Error),
3635
/// The server sent an unexpected response.
@@ -67,7 +66,7 @@ impl error::Error for ConnectError {
6766
fn cause(&self) -> Option<&error::Error> {
6867
match *self {
6968
ConnectError::DbError(ref err) => Some(err),
70-
ConnectError::SslError(ref err) => Some(err),
69+
ConnectError::SslError(ref err) => Some(&**err),
7170
ConnectError::IoError(ref err) => Some(err),
7271
_ => None
7372
}
@@ -86,12 +85,6 @@ impl From<DbError> for ConnectError {
8685
}
8786
}
8887

89-
impl From<SslError> for ConnectError {
90-
fn from(err: SslError) -> ConnectError {
91-
ConnectError::SslError(err)
92-
}
93-
}
94-
9588
impl From<byteorder::Error> for ConnectError {
9689
fn from(err: byteorder::Error) -> ConnectError {
9790
ConnectError::IoError(From::from(err))

src/io/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Types and traits for SSL adaptors.
2+
pub use priv_io::Stream;
3+
4+
use std::error::Error;
5+
use std::io::prelude::*;
6+
7+
#[cfg(feature = "openssl")]
8+
mod openssl;
9+
10+
/// A trait implemented by SSL adaptors.
11+
pub trait StreamWrapper: Read+Write+Send {
12+
/// Returns a reference to the underlying `Stream`.
13+
fn get_ref(&self) -> &Stream;
14+
15+
/// Returns a mutable reference to the underlying `Stream`.
16+
fn get_mut(&mut self) -> &mut Stream;
17+
}
18+
19+
/// A trait implemented by types that can negotiate SSL over a Postgres stream.
20+
pub trait NegotiateSsl {
21+
/// Negotiates an SSL session, returning a wrapper around the provided
22+
/// stream.
23+
///
24+
/// The host portion of the connection parameters is provided for hostname
25+
/// verification.
26+
fn negotiate_ssl(&self, host: &str, stream: Stream) -> Result<Box<StreamWrapper>, Box<Error>>;
27+
}

src/io/openssl.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
extern crate openssl;
2+
3+
use std::error::Error;
4+
5+
use self::openssl::ssl::{SslContext, SslStream};
6+
use io::{StreamWrapper, Stream, NegotiateSsl};
7+
8+
impl StreamWrapper for SslStream<Stream> {
9+
fn get_ref(&self) -> &Stream {
10+
self.get_ref()
11+
}
12+
13+
fn get_mut(&mut self) -> &mut Stream {
14+
self.get_mut()
15+
}
16+
}
17+
18+
impl NegotiateSsl for SslContext {
19+
fn negotiate_ssl(&self, _: &str, stream: Stream) -> Result<Box<StreamWrapper>, Box<Error>> {
20+
let stream = try!(SslStream::new(self, stream));
21+
Ok(Box::new(stream))
22+
}
23+
}

src/io_util.rs

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)