Struct fluvio_future::native_tls::TlsConnector
source · [−]pub struct TlsConnector { /* private fields */ }Expand description
Connect a client to a remote server.
Examples
use async_std::prelude::*;
use async_std::net::TcpStream;
use async_native_tls::TlsConnector;
let stream = TcpStream::connect("google.com:443").await?;
let mut stream = TlsConnector::new()
.use_sni(true)
.connect("google.com", stream)
.await?;
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;
let mut res = Vec::new();
stream.read_to_end(&mut res).await?;
println!("{}", String::from_utf8_lossy(&res));Implementations
sourceimpl TlsConnector
impl TlsConnector
sourcepub fn new() -> TlsConnector
pub fn new() -> TlsConnector
Create a new instance.
sourcepub fn identity(self, identity: Identity) -> TlsConnector
pub fn identity(self, identity: Identity) -> TlsConnector
Sets the identity to be used for client certificate authentication.
sourcepub fn min_protocol_version(self, protocol: Option<Protocol>) -> TlsConnector
pub fn min_protocol_version(self, protocol: Option<Protocol>) -> TlsConnector
Sets the minimum supported protocol version.
A value of None enables support for the oldest protocols supported by the
implementation. Defaults to Some(Protocol::Tlsv10).
sourcepub fn max_protocol_version(self, protocol: Option<Protocol>) -> TlsConnector
pub fn max_protocol_version(self, protocol: Option<Protocol>) -> TlsConnector
Sets the maximum supported protocol version.
A value of None enables support for the newest protocols supported by the
implementation. Defaults to None.
sourcepub fn add_root_certificate(self, cert: Certificate) -> TlsConnector
pub fn add_root_certificate(self, cert: Certificate) -> TlsConnector
Adds a certificate to the set of roots that the connector will trust.
The connector will use the system’s trust root by default. This method can be used to add to that set when communicating with servers not trusted by the system. Defaults to an empty set.
sourcepub fn danger_accept_invalid_certs(
self,
accept_invalid_certs: bool
) -> TlsConnector
pub fn danger_accept_invalid_certs(
self,
accept_invalid_certs: bool
) -> TlsConnector
Controls the use of certificate validation.
Defaults to false.
Warning
You should think very carefully before using this method. If invalid certificates are trusted, any certificate for any site will be trusted for use. This includes expired certificates. This introduces significant vulnerabilities, and should only be used as a last resort.
sourcepub fn use_sni(self, use_sni: bool) -> TlsConnector
pub fn use_sni(self, use_sni: bool) -> TlsConnector
Controls the use of Server Name Indication (SNI).
Defaults to true.
sourcepub fn danger_accept_invalid_hostnames(
self,
accept_invalid_hostnames: bool
) -> TlsConnector
pub fn danger_accept_invalid_hostnames(
self,
accept_invalid_hostnames: bool
) -> TlsConnector
Controls the use of hostname verification.
Defaults to false.
Warning
You should think very carefully before using this method. If invalid hostnames are trusted, any valid certificate for any site will be trusted for use. This introduces significant vulnerabilities, and should only be used as a last resort.
sourcepub async fn connect<S>(
&self,
host: impl Into<Host>,
stream: S
) -> Result<TlsStream<S>, Error> where
S: AsyncRead + AsyncWrite + Unpin,
pub async fn connect<S>(
&self,
host: impl Into<Host>,
stream: S
) -> Result<TlsStream<S>, Error> where
S: AsyncRead + AsyncWrite + Unpin,
Connect to a remote server.
Examples
use async_std::prelude::*;
use async_std::net::TcpStream;
use async_native_tls::TlsConnector;
let stream = TcpStream::connect("google.com:443").await?;
let mut stream = TlsConnector::new()
.use_sni(true)
.connect("google.com", stream)
.await?;
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;
let mut res = Vec::new();
stream.read_to_end(&mut res).await?;
println!("{}", String::from_utf8_lossy(&res));Trait Implementations
sourceimpl Debug for TlsConnector
impl Debug for TlsConnector
sourceimpl Default for TlsConnector
impl Default for TlsConnector
sourcefn default() -> TlsConnector
fn default() -> TlsConnector
Returns the “default value” for a type. Read more
sourceimpl From<TlsConnector> for TlsAnonymousConnector
impl From<TlsConnector> for TlsAnonymousConnector
sourcefn from(connector: TlsConnector) -> Self
fn from(connector: TlsConnector) -> Self
Converts to this type from the input type.
sourceimpl From<TlsConnectorBuilder> for TlsConnector
impl From<TlsConnectorBuilder> for TlsConnector
sourcefn from(builder: TlsConnectorBuilder) -> TlsConnector
fn from(builder: TlsConnectorBuilder) -> TlsConnector
Converts to this type from the input type.
Auto Trait Implementations
impl RefUnwindSafe for TlsConnector
impl Send for TlsConnector
impl Sync for TlsConnector
impl Unpin for TlsConnector
impl UnwindSafe for TlsConnector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output; where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output; where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more