Skip to content

Commit b270696

Browse files
committed
Document TLS usage
1 parent cfa1971 commit b270696

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@
3838
//! }
3939
//! }
4040
//! ```
41+
//!
42+
//! # SSL/TLS
43+
//!
44+
//! This crate supports TLS secured connections. The `TlsMode` enum is passed to connection methods
45+
//! and indicates if the connection will not, may not, or must be secured by TLS. The TLS
46+
//! implementation is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL and
47+
//! OSX's Secure Transport are provided behing the `with-openssl` and `with-security-framework`
48+
//! feature flags respectively.
49+
//!
50+
//! ## Examples
51+
//!
52+
//! Connecting using OpenSSL:
53+
//!
54+
//! ```no_run
55+
//! extern crate postgres;
56+
//!
57+
//! use postgres::{Connection, TlsMode};
58+
//! # #[cfg(feature = "with-openssl")]
59+
//! use postgres::io::openssl::OpenSsl;
60+
//!
61+
//! # #[cfg(not(feature = "with-openssl"))] fn main() {}
62+
//! # #[cfg(feature = "with-openssl")]
63+
//! fn main() {
64+
//! let openssl = OpenSsl::new().unwrap();
65+
//! // Configure the `SslContext` with the `.context()` and `.context_mut()` methods
66+
//!
67+
//! let conn = Connection::connect("postgres://postgres@localhost", TlsMode::Require(&openssl))
68+
//! .unwrap();
69+
//! }
70+
//! ```
4171
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.11")]
4272
#![warn(missing_docs)]
4373
#![allow(unknown_lints, needless_lifetimes, doc_markdown)] // for clippy
@@ -878,20 +908,23 @@ impl Connection {
878908
///
879909
/// # Examples
880910
///
911+
/// To connect over TCP:
881912
/// ```rust,no_run
882913
/// use postgres::{Connection, TlsMode};
883914
///
884915
/// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
885916
/// let conn = Connection::connect(url, TlsMode::None).unwrap();
886917
/// ```
887918
///
919+
/// To connect over a Unix socket located in `/run/postgres`:
888920
/// ```rust,no_run
889921
/// use postgres::{Connection, TlsMode};
890922
///
891923
/// let url = "postgresql://postgres@%2Frun%2Fpostgres";
892924
/// let conn = Connection::connect(url, TlsMode::None).unwrap();
893925
/// ```
894926
///
927+
/// To connect building a `ConnectParams` struct manually:
895928
/// ```rust,no_run
896929
/// use postgres::{Connection, TlsMode};
897930
/// use postgres::params::{UserInfo, ConnectParams, ConnectTarget};

0 commit comments

Comments
 (0)