Skip to content

Commit 2e25862

Browse files
committed
Rename ssl stuff
1 parent e0b1eee commit 2e25862

6 files changed

Lines changed: 51 additions & 51 deletions

File tree

src/io/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Types and traits for SSL adaptors.
1+
//! Types and traits for TLS adaptors.
22
pub use priv_io::Stream;
33

44
use std::error::Error;
@@ -13,24 +13,24 @@ pub mod security_framework;
1313
#[cfg(all(feature = "openssl", not(feature = "with-openssl")))]
1414
const _CHECK: OpensslFeatureRenamedSeeDocs = "";
1515

16-
/// A trait implemented by SSL adaptors.
17-
pub trait StreamWrapper: fmt::Debug + Read + Write + Send {
16+
/// A trait implemented by TLS adaptors.
17+
pub trait TlsStream: fmt::Debug + Read + Write + Send {
1818
/// Returns a reference to the underlying `Stream`.
1919
fn get_ref(&self) -> &Stream;
2020

2121
/// Returns a mutable reference to the underlying `Stream`.
2222
fn get_mut(&mut self) -> &mut Stream;
2323
}
2424

25-
/// A trait implemented by types that can negotiate SSL over a Postgres stream.
26-
pub trait NegotiateSsl: fmt::Debug {
27-
/// Negotiates an SSL session, returning a wrapper around the provided
28-
/// stream.
25+
/// A trait implemented by types that can negotiate TLS over a Postgres stream.
26+
pub trait TlsHandshake: fmt::Debug {
27+
/// Performs a client-side TLS handshake, returning a wrapper around the
28+
/// provided stream.
2929
///
3030
/// The host portion of the connection parameters is provided for hostname
3131
/// verification.
32-
fn negotiate_ssl(&self,
32+
fn tls_handshake(&self,
3333
host: &str,
3434
stream: Stream)
35-
-> Result<Box<StreamWrapper>, Box<Error + Sync + Send>>;
35+
-> Result<Box<TlsStream>, Box<Error + Sync + Send>>;
3636
}

src/io/openssl.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use self::openssl::ssl::{IntoSsl, SslContext, SslStream, SslMethod, SSL_VERIFY_P
88
SSL_OP_NO_SSLV2, SSL_OP_NO_SSLV3, SSL_OP_NO_COMPRESSION};
99
use self::openssl::ssl::error::SslError;
1010
use self::openssl_verify::verify_callback;
11-
use io::{StreamWrapper, Stream, NegotiateSsl};
11+
use io::{TlsStream, Stream, TlsHandshake};
1212

13-
impl StreamWrapper for SslStream<Stream> {
13+
impl TlsStream for SslStream<Stream> {
1414
fn get_ref(&self) -> &Stream {
1515
self.get_ref()
1616
}
@@ -20,17 +20,17 @@ impl StreamWrapper for SslStream<Stream> {
2020
}
2121
}
2222

23-
/// A `NegotiateSsl` implementation that uses OpenSSL.
23+
/// A `TlsHandshake` implementation that uses OpenSSL.
2424
///
2525
/// Requires the `with-openssl` feature.
2626
#[derive(Debug)]
27-
pub struct Negotiator(SslContext);
27+
pub struct OpenSsl(SslContext);
2828

29-
impl Negotiator {
30-
/// Creates a `Negotiator` with a reasonable default configuration.
29+
impl OpenSsl {
30+
/// Creates a `OpenSsl` with a reasonable default configuration.
3131
///
3232
/// The configuration is modeled after libcurl's and is subject to change.
33-
pub fn new() -> Result<Negotiator, SslError> {
33+
pub fn new() -> Result<OpenSsl, SslError> {
3434
let mut ctx = try!(SslContext::new(SslMethod::Sslv23));
3535
try!(ctx.set_default_verify_paths());
3636
ctx.set_options(SSL_OP_NO_SSLV2 | SSL_OP_NO_SSLV3 | SSL_OP_NO_COMPRESSION);
@@ -49,17 +49,17 @@ impl Negotiator {
4949
}
5050
}
5151

52-
impl From<SslContext> for Negotiator {
53-
fn from(ctx: SslContext) -> Negotiator {
54-
Negotiator(ctx)
52+
impl From<SslContext> for OpenSsl {
53+
fn from(ctx: SslContext) -> OpenSsl {
54+
OpenSsl(ctx)
5555
}
5656
}
5757

58-
impl NegotiateSsl for Negotiator {
59-
fn negotiate_ssl(&self,
58+
impl TlsHandshake for OpenSsl {
59+
fn tls_handshake(&self,
6060
domain: &str,
6161
stream: Stream)
62-
-> Result<Box<StreamWrapper>, Box<Error + Send + Sync>> {
62+
-> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
6363
let domain = domain.to_owned();
6464
let mut ssl = try!(self.0.into_ssl());
6565
ssl.set_verify_callback(SSL_VERIFY_PEER, move |p, x| verify_callback(&domain, p, x));

src/io/security_framework.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
extern crate security_framework;
33

44
use self::security_framework::secure_transport::{SslStream, ClientBuilder};
5-
use io::{Stream, StreamWrapper, NegotiateSsl};
5+
use io::{Stream, TlsStream, TlsHandshake};
66
use std::error::Error;
77

8-
impl StreamWrapper for SslStream<Stream> {
8+
impl TlsStream for SslStream<Stream> {
99
fn get_ref(&self) -> &Stream {
1010
self.get_ref()
1111
}
@@ -15,15 +15,15 @@ impl StreamWrapper for SslStream<Stream> {
1515
}
1616
}
1717

18-
/// A `NegotiateSsl` implementation that uses Security Framework.
18+
/// A `TlsHandshake` implementation that uses the Security Framework.
1919
///
2020
/// Requires the `security-framework` feature.
2121
#[derive(Debug)]
22-
pub struct Negotiator(ClientBuilder);
22+
pub struct SecurityFramework(ClientBuilder);
2323

24-
impl Negotiator {
25-
/// Returns a new `Negotiator` with default settings.
26-
pub fn new() -> Negotiator {
24+
impl SecurityFramework {
25+
/// Returns a new `SecurityFramework` with default settings.
26+
pub fn new() -> SecurityFramework {
2727
ClientBuilder::new().into()
2828
}
2929

@@ -38,17 +38,17 @@ impl Negotiator {
3838
}
3939
}
4040

41-
impl From<ClientBuilder> for Negotiator {
42-
fn from(b: ClientBuilder) -> Negotiator {
43-
Negotiator(b)
41+
impl From<ClientBuilder> for SecurityFramework {
42+
fn from(b: ClientBuilder) -> SecurityFramework {
43+
SecurityFramework(b)
4444
}
4545
}
4646

47-
impl NegotiateSsl for Negotiator {
48-
fn negotiate_ssl(&self,
47+
impl TlsHandshake for SecurityFramework {
48+
fn tls_handshake(&self,
4949
domain: &str,
5050
stream: Stream)
51-
-> Result<Box<StreamWrapper>, Box<Error + Send + Sync>> {
51+
-> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
5252
let stream = try!(self.0.handshake(domain, stream));
5353
Ok(Box::new(stream))
5454
}

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use std::time::Duration;
6868
use std::path::PathBuf;
6969

7070
use error::{Error, ConnectError, SqlState, DbError};
71-
use io::{StreamWrapper, NegotiateSsl};
71+
use io::{TlsStream, TlsHandshake};
7272
use message::{Frontend, Backend, RowDescriptionEntry};
7373
use message::{WriteMessage, ReadMessage};
7474
use notification::{Notifications, Notification};
@@ -305,9 +305,9 @@ pub enum SslMode<'a> {
305305
/// The connection will not use SSL.
306306
None,
307307
/// The connection will use SSL if the backend supports it.
308-
Prefer(&'a NegotiateSsl),
308+
Prefer(&'a TlsHandshake),
309309
/// The connection must use SSL.
310-
Require(&'a NegotiateSsl),
310+
Require(&'a TlsHandshake),
311311
}
312312

313313
struct StatementInfo {
@@ -317,7 +317,7 @@ struct StatementInfo {
317317
}
318318

319319
struct InnerConnection {
320-
stream: BufStream<Box<StreamWrapper>>,
320+
stream: BufStream<Box<TlsStream>>,
321321
notice_handler: Box<HandleNotice>,
322322
notifications: VecDeque<Notification>,
323323
cancel_data: CancelData,

src/priv_io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::os::windows::io::{AsRawSocket, RawSocket};
1717

1818
use {SslMode, ConnectParams, ConnectTarget};
1919
use error::ConnectError;
20-
use io::StreamWrapper;
20+
use io::TlsStream;
2121
use message::{self, WriteMessage};
2222
use message::Frontend;
2323

@@ -29,7 +29,7 @@ pub trait StreamOptions {
2929
fn set_nonblocking(&self, nonblock: bool) -> io::Result<()>;
3030
}
3131

32-
impl StreamOptions for BufStream<Box<StreamWrapper>> {
32+
impl StreamOptions for BufStream<Box<TlsStream>> {
3333
fn set_read_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
3434
match self.get_ref().get_ref().0 {
3535
InternalStream::Tcp(ref s) => s.set_read_timeout(timeout),
@@ -49,7 +49,7 @@ impl StreamOptions for BufStream<Box<StreamWrapper>> {
4949

5050
/// A connection to the Postgres server.
5151
///
52-
/// It implements `Read`, `Write` and `StreamWrapper`, as well as `AsRawFd` on
52+
/// It implements `Read`, `Write` and `TlsStream`, as well as `AsRawFd` on
5353
/// Unix platforms and `AsRawSocket` on Windows platforms.
5454
pub struct Stream(InternalStream);
5555

@@ -79,7 +79,7 @@ impl Write for Stream {
7979
}
8080
}
8181

82-
impl StreamWrapper for Stream {
82+
impl TlsStream for Stream {
8383
fn get_ref(&self) -> &Stream {
8484
self
8585
}
@@ -160,7 +160,7 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
160160

161161
pub fn initialize_stream(params: &ConnectParams,
162162
ssl: SslMode)
163-
-> Result<Box<StreamWrapper>, ConnectError> {
163+
-> Result<Box<TlsStream>, ConnectError> {
164164
let mut socket = Stream(try!(open_socket(params)));
165165

166166
let (ssl_required, negotiator) = match ssl {
@@ -188,5 +188,5 @@ pub fn initialize_stream(params: &ConnectParams,
188188
ConnectTarget::Unix(_) => return Err(ConnectError::Io(::bad_response())),
189189
};
190190

191-
negotiator.negotiate_ssl(host, socket).map_err(ConnectError::Ssl)
191+
negotiator.tls_handshake(host, socket).map_err(ConnectError::Ssl)
192192
}

tests/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,9 @@ fn test_cancel_query() {
663663
#[test]
664664
#[cfg(feature = "with-openssl")]
665665
fn test_require_ssl_conn() {
666-
use postgres::io::openssl::Negotiator;
666+
use postgres::io::openssl::OpenSsl;
667667

668-
let mut negotiator = Negotiator::new().unwrap();
668+
let mut negotiator = OpenSsl::new().unwrap();
669669
negotiator.context_mut().set_CA_file(".travis/server.crt").unwrap();
670670
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
671671
SslMode::Require(&negotiator)));
@@ -675,9 +675,9 @@ fn test_require_ssl_conn() {
675675
#[test]
676676
#[cfg(feature = "with-openssl")]
677677
fn test_prefer_ssl_conn() {
678-
use postgres::io::openssl::Negotiator;
678+
use postgres::io::openssl::OpenSsl;
679679

680-
let mut negotiator = Negotiator::new().unwrap();
680+
let mut negotiator = OpenSsl::new().unwrap();
681681
negotiator.context_mut().set_CA_file(".travis/server.crt").unwrap();
682682
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
683683
SslMode::Require(&negotiator)));
@@ -687,12 +687,12 @@ fn test_prefer_ssl_conn() {
687687
#[test]
688688
#[cfg(feature = "security-framework")]
689689
fn security_framework_ssl() {
690-
use postgres::io::security_framework::Negotiator;
690+
use postgres::io::security_framework::SecurityFramework;
691691
use security_framework::certificate::SecCertificate;
692692

693693
let certificate = include_bytes!("../.travis/server.der");
694694
let certificate = or_panic!(SecCertificate::from_der(certificate));
695-
let mut negotiator = Negotiator::new();
695+
let mut negotiator = SecurityFramework::new();
696696
negotiator.builder_mut().anchor_certificates(&[certificate]);
697697
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
698698
SslMode::Require(&negotiator)));

0 commit comments

Comments
 (0)