Docs for connectors

This commit is contained in:
Steven Fackler 2016-10-29 15:00:46 -07:00
parent 57d10ebbc3
commit e72533c058
2 changed files with 42 additions and 0 deletions

View File

@ -40,9 +40,13 @@ fn ctx(method: SslMethod) -> Result<SslContextBuilder, ErrorStack> {
Ok(ctx) Ok(ctx)
} }
/// A builder for `ClientConnector`s.
pub struct ClientConnectorBuilder(SslContextBuilder); pub struct ClientConnectorBuilder(SslContextBuilder);
impl ClientConnectorBuilder { impl ClientConnectorBuilder {
/// Creates a new builder for TLS connections.
///
/// The default configuration is based off of libcurl's and is subject to change.
pub fn tls() -> Result<ClientConnectorBuilder, ErrorStack> { pub fn tls() -> Result<ClientConnectorBuilder, ErrorStack> {
ClientConnectorBuilder::new(SslMethod::tls()) ClientConnectorBuilder::new(SslMethod::tls())
} }
@ -55,22 +59,35 @@ impl ClientConnectorBuilder {
Ok(ClientConnectorBuilder(ctx)) Ok(ClientConnectorBuilder(ctx))
} }
/// Returns a shared reference to the inner `SslContextBuilder`.
pub fn context(&self) -> &SslContextBuilder { pub fn context(&self) -> &SslContextBuilder {
&self.0 &self.0
} }
/// Returns a mutable reference to the inner `SslContextBuilder`.
pub fn context_mut(&mut self) -> &mut SslContextBuilder { pub fn context_mut(&mut self) -> &mut SslContextBuilder {
&mut self.0 &mut self.0
} }
/// Consumes the builder, returning a `ClientConnector`.
pub fn build(self) -> ClientConnector { pub fn build(self) -> ClientConnector {
ClientConnector(self.0.build()) ClientConnector(self.0.build())
} }
} }
/// A type which wraps client-side streams in a TLS session.
///
/// OpenSSL's default configuration is highly insecure. This connector manages the OpenSSL
/// structures, configuring cipher suites, session options, hostname verification, and more.
///
/// OpenSSL's built in hostname verification is used when linking against OpenSSL 1.0.2 or 1.1.0,
/// and a custom implementation is used when linking against OpenSSL 1.0.1.
pub struct ClientConnector(SslContext); pub struct ClientConnector(SslContext);
impl ClientConnector { impl ClientConnector {
/// Initiates a client-side TLS session on a stream.
///
/// The domain is used for SNI and hostname verification.
pub fn connect<S>(&self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>> pub fn connect<S>(&self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where S: Read + Write where S: Read + Write
{ {
@ -82,9 +99,14 @@ impl ClientConnector {
} }
} }
/// A builder for `ServerConnector`s.
pub struct ServerConnectorBuilder(SslContextBuilder); pub struct ServerConnectorBuilder(SslContextBuilder);
impl ServerConnectorBuilder { impl ServerConnectorBuilder {
/// Creates a new builder for server-side TLS connections.
///
/// The default configuration is based off of the intermediate profile of Mozilla's SSL
/// Configuration Generator, and is subject to change.
pub fn tls<I, T>(private_key: &PKeyRef, pub fn tls<I, T>(private_key: &PKeyRef,
certificate: &X509Ref, certificate: &X509Ref,
chain: I) chain: I)
@ -127,22 +149,30 @@ impl ServerConnectorBuilder {
Ok(ServerConnectorBuilder(ctx)) Ok(ServerConnectorBuilder(ctx))
} }
/// Returns a shared reference to the inner `SslContextBuilder`.
pub fn context(&self) -> &SslContextBuilder { pub fn context(&self) -> &SslContextBuilder {
&self.0 &self.0
} }
/// Returns a mutable reference to the inner `SslContextBuilder`.
pub fn context_mut(&mut self) -> &mut SslContextBuilder { pub fn context_mut(&mut self) -> &mut SslContextBuilder {
&mut self.0 &mut self.0
} }
/// Consumes the builder, returning a `ServerConnector`.
pub fn build(self) -> ServerConnector { pub fn build(self) -> ServerConnector {
ServerConnector(self.0.build()) ServerConnector(self.0.build())
} }
} }
/// A type which wraps server-side streams in a TLS session.
///
/// OpenSSL's default configuration is highly insecure. This connector manages the OpenSSL
/// structures, configuring cipher suites, session options, and more.
pub struct ServerConnector(SslContext); pub struct ServerConnector(SslContext);
impl ServerConnector { impl ServerConnector {
/// Initiates a server-side TLS session on a stream.
pub fn connect<S>(&self, stream: S) -> Result<SslStream<S>, HandshakeError<S>> pub fn connect<S>(&self, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where S: Read + Write where S: Read + Write
{ {

View File

@ -342,6 +342,7 @@ pub enum SniError {
NoAck, NoAck,
} }
/// A builder for `SslContext`s.
pub struct SslContextBuilder(*mut ffi::SSL_CTX); pub struct SslContextBuilder(*mut ffi::SSL_CTX);
impl Drop for SslContextBuilder { impl Drop for SslContextBuilder {
@ -793,6 +794,7 @@ impl SslCipherRef {
} }
} }
/// A reference to an `Ssl`.
pub struct SslRef(Opaque); pub struct SslRef(Opaque);
unsafe impl Send for SslRef {} unsafe impl Send for SslRef {}
@ -1104,6 +1106,11 @@ impl Ssl {
} }
/// Creates an SSL/TLS client operating over the provided stream. /// Creates an SSL/TLS client operating over the provided stream.
///
/// # Warning
///
/// OpenSSL's default configuration is insecure. It is highly recommended to use
/// `ClientConnector` rather than `Ssl` directly, as it manages that configuration.
pub fn connect<S>(self, stream: S) -> Result<SslStream<S>, HandshakeError<S>> pub fn connect<S>(self, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where S: Read + Write where S: Read + Write
{ {
@ -1131,6 +1138,11 @@ impl Ssl {
} }
/// Creates an SSL/TLS server operating over the provided stream. /// Creates an SSL/TLS server operating over the provided stream.
///
/// # Warning
///
/// OpenSSL's default configuration is insecure. It is highly recommended to use
/// `ServerConnector` rather than `Ssl` directly, as it manages that configuration.
pub fn accept<S>(self, stream: S) -> Result<SslStream<S>, HandshakeError<S>> pub fn accept<S>(self, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where S: Read + Write where S: Read + Write
{ {