Skip to content

Commit

Permalink
Merge branch 'release-v0.13.0' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 6, 2016
2 parents 6529336 + 88aff10 commit 69477cd
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 46 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "postgres"
version = "0.12.0"
version = "0.13.0"
authors = ["Steven Fackler <[email protected]>"]
license = "MIT"
description = "A native PostgreSQL driver"
repository = "https://github.com/sfackler/rust-postgres"
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.12.0/postgres"
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.13.0/postgres"
readme = "README.md"
keywords = ["database", "postgres", "postgresql", "sql"]
include = ["src/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
Expand All @@ -24,7 +24,7 @@ path = "tests/test.rs"
with-bit-vec = ["bit-vec"]
with-chrono = ["chrono"]
with-eui48 = ["eui48"]
with-openssl = ["openssl", "openssl-verify"]
with-openssl = ["openssl"]
with-rustc-serialize = ["rustc-serialize"]
with-security-framework = ["security-framework"]
with-serde_json = ["serde_json"]
Expand All @@ -36,13 +36,12 @@ bufstream = "0.1"
fallible-iterator = "0.1.3"
hex = "0.2"
log = "0.3"
phf = "=0.7.15"
phf = "=0.7.19"
postgres-protocol = "0.1"
bit-vec = { version = "0.4", optional = true }
chrono = { version = "0.2.14", optional = true }
eui48 = { version = "0.1", optional = true }
openssl-verify = { version = "0.2", optional = true }
openssl = { version = "0.8", optional = true }
openssl = { version = "0.9", optional = true }
rustc-serialize = { version = "0.3", optional = true }
security-framework = { version = "0.1.2", optional = true }
serde_json = { version = ">= 0.6, < 0.9", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Rust-Postgres
A native PostgreSQL driver for Rust.

[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.12.0/postgres)
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.13.0/postgres)

[![Build Status](https://travis-ci.org/sfackler/rust-postgres.png?branch=master)](https://travis-ci.org/sfackler/rust-postgres) [![Latest Version](https://img.shields.io/crates/v/postgres.svg)](https://crates.io/crates/postgres)

You can integrate Rust-Postgres into your project through the [releases on crates.io](https://crates.io/crates/postgres):
```toml
[dependencies]
postgres = "0.12"
postgres = "0.13"
```

## Overview
Expand Down
9 changes: 4 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#![feature(test)]
extern crate test;
extern crate postgres;

use test::Bencher;

use postgres::{Connection, SslMode};
use postgres::{Connection, TlsMode};

#[bench]
fn bench_naiive_execute(b: &mut test::Bencher) {
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]).unwrap();

b.iter(|| {
Expand All @@ -20,7 +19,7 @@ fn bench_naiive_execute(b: &mut test::Bencher) {

#[bench]
fn bench_execute(b: &mut test::Bencher) {
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]).unwrap();

b.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
authors = ["Steven Fackler <[email protected]>"]

[dependencies]
phf_codegen = "=0.7.15"
phf_codegen = "=0.7.19"
regex = "0.1"
marksman_escape = "0.1"
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@
//! # #[cfg(feature = "with-openssl")]
//! fn main() {
//! let openssl = OpenSsl::new().unwrap();
//! // Configure the `SslContext` with the `.context()` and `.context_mut()` methods
//!
//! let conn = Connection::connect("postgres://postgres@localhost", TlsMode::Require(&openssl))
//! .unwrap();
//! }
//! ```
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.12.0")]
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.13.0")]
#![warn(missing_docs)]
#![allow(unknown_lints, needless_lifetimes, doc_markdown)] // for clippy

Expand Down Expand Up @@ -905,6 +903,7 @@ impl Connection {
/// # Examples
///
/// To connect over TCP:
///
/// ```rust,no_run
/// use postgres::{Connection, TlsMode};
///
Expand All @@ -913,6 +912,7 @@ impl Connection {
/// ```
///
/// To connect over a Unix socket located in `/run/postgres`:
///
/// ```rust,no_run
/// use postgres::{Connection, TlsMode};
///
Expand All @@ -921,6 +921,7 @@ impl Connection {
/// ```
///
/// To connect with a manually constructed `ConnectParams`:
///
/// ```rust,no_run
/// use postgres::{Connection, TlsMode};
/// use postgres::params::{UserInfo, ConnectParams, ConnectTarget};
Expand Down
6 changes: 6 additions & 0 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl<'a> IntoConnectParams for &'a str {
}
}

impl IntoConnectParams for String {
fn into_connect_params(self) -> Result<ConnectParams, Box<Error + Sync + Send>> {
self.as_str().into_connect_params()
}
}

impl IntoConnectParams for Url {
fn into_connect_params(self) -> Result<ConnectParams, Box<Error + Sync + Send>> {
let Url { host, port, user, path: url::Path { mut path, query: options, .. }, .. } = self;
Expand Down
45 changes: 20 additions & 25 deletions src/tls/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! OpenSSL support.
extern crate openssl;
extern crate openssl_verify;

use std::error::Error;
use std::fmt;

use self::openssl::error::ErrorStack;
use self::openssl::ssl::{IntoSsl, SslContext, SslStream, SslMethod, SSL_VERIFY_PEER,
SSL_OP_NO_SSLV2, SSL_OP_NO_SSLV3, SSL_OP_NO_COMPRESSION};
use self::openssl_verify::verify_callback;
use self::openssl::ssl::{SslMethod, SslConnector, SslConnectorBuilder, SslStream};
use tls::{TlsStream, Stream, TlsHandshake};

impl TlsStream for SslStream<Stream> {
Expand All @@ -23,35 +21,35 @@ impl TlsStream for SslStream<Stream> {
/// A `TlsHandshake` implementation that uses OpenSSL.
///
/// Requires the `with-openssl` feature.
#[derive(Debug)]
pub struct OpenSsl(SslContext);
pub struct OpenSsl(SslConnector);

impl fmt::Debug for OpenSsl {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("OpenSsl").finish()
}
}

impl OpenSsl {
/// Creates a `OpenSsl` with a reasonable default configuration.
///
/// The configuration is modeled after libcurl's and is subject to change.
/// Creates a `OpenSsl` with `SslConnector`'s default configuration.
pub fn new() -> Result<OpenSsl, ErrorStack> {
let mut ctx = try!(SslContext::new(SslMethod::Sslv23));
try!(ctx.set_default_verify_paths());
ctx.set_options(SSL_OP_NO_SSLV2 | SSL_OP_NO_SSLV3 | SSL_OP_NO_COMPRESSION);
try!(ctx.set_cipher_list("ALL!EXPORT!EXPORT40!EXPORT56!aNULL!LOW!RC4@STRENGTH"));
Ok(ctx.into())
let connector = try!(SslConnectorBuilder::new(SslMethod::tls())).build();
Ok(OpenSsl(connector))
}

/// Returns a reference to the associated `SslContext`.
pub fn context(&self) -> &SslContext {
/// Returns a reference to the inner `SslConnector`.
pub fn connector(&self) -> &SslConnector {
&self.0
}

/// Returns a mutable reference to the associated `SslContext`.
pub fn context_mut(&mut self) -> &mut SslContext {
/// Returns a mutable reference to the inner `SslConnector`.
pub fn connector_mut(&mut self) -> &mut SslConnector {
&mut self.0
}
}

impl From<SslContext> for OpenSsl {
fn from(ctx: SslContext) -> OpenSsl {
OpenSsl(ctx)
impl From<SslConnector> for OpenSsl {
fn from(connector: SslConnector) -> OpenSsl {
OpenSsl(connector)
}
}

Expand All @@ -60,10 +58,7 @@ impl TlsHandshake for OpenSsl {
domain: &str,
stream: Stream)
-> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
let domain = domain.to_owned();
let mut ssl = try!(self.0.into_ssl());
ssl.set_verify_callback(SSL_VERIFY_PEER, move |p, x| verify_callback(&domain, p, x));
let stream = try!(SslStream::connect(ssl, stream));
let stream = try!(self.0.connect(domain, stream));
Ok(Box::new(stream))
}
}
12 changes: 8 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,12 @@ fn test_cancel_query() {
#[test]
#[cfg(feature = "with-openssl")]
fn test_require_ssl_conn() {
use openssl::ssl::{SslMethod, SslConnectorBuilder};
use postgres::tls::openssl::OpenSsl;

let mut negotiator = OpenSsl::new().unwrap();
negotiator.context_mut().set_CA_file(".travis/server.crt").unwrap();
let mut builder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
builder.builder_mut().set_ca_file(".travis/server.crt").unwrap();
let negotiator = OpenSsl::from(builder.build());
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
TlsMode::Require(&negotiator)));
or_panic!(conn.execute("SELECT 1::VARCHAR", &[]));
Expand All @@ -676,10 +678,12 @@ fn test_require_ssl_conn() {
#[test]
#[cfg(feature = "with-openssl")]
fn test_prefer_ssl_conn() {
use openssl::ssl::{SslMethod, SslConnectorBuilder};
use postgres::tls::openssl::OpenSsl;

let mut negotiator = OpenSsl::new().unwrap();
negotiator.context_mut().set_CA_file(".travis/server.crt").unwrap();
let mut builder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
builder.builder_mut().set_ca_file(".travis/server.crt").unwrap();
let negotiator = OpenSsl::from(builder.build());
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
TlsMode::Require(&negotiator)));
or_panic!(conn.execute("SELECT 1::VARCHAR", &[]));
Expand Down

0 comments on commit 69477cd

Please sign in to comment.