[−][src]Struct async_native_tls::TlsConnector
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));
Methods
impl TlsConnector
[src]
pub fn new() -> Self
[src]
Create a new instance.
pub fn identity(self, identity: Identity) -> Self
[src]
Sets the identity to be used for client certificate authentication.
pub fn min_protocol_version(self, protocol: Option<Protocol>) -> Self
[src]
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)
.
pub fn max_protocol_version(self, protocol: Option<Protocol>) -> Self
[src]
Sets the maximum supported protocol version.
A value of None
enables support for the newest protocols supported by the
implementation. Defaults to None
.
pub fn add_root_certificate(self, cert: Certificate) -> Self
[src]
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.
pub fn danger_accept_invalid_certs(self, accept_invalid_certs: bool) -> Self
[src]
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.
pub fn use_sni(self, use_sni: bool) -> Self
[src]
Controls the use of Server Name Indication (SNI).
Defaults to true
.
pub fn danger_accept_invalid_hostnames(
self,
accept_invalid_hostnames: bool
) -> Self
[src]
self,
accept_invalid_hostnames: bool
) -> Self
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.
pub async fn connect<'_, S>(
&'_ self,
host: impl Into<Host>,
stream: S
) -> Result<TlsStream<S>> where
S: AsyncRead + AsyncWrite + Unpin,
[src]
&'_ self,
host: impl Into<Host>,
stream: S
) -> Result<TlsStream<S>> 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
impl Debug for TlsConnector
[src]
impl Default for TlsConnector
[src]
impl From<TlsConnectorBuilder> for TlsConnector
[src]
fn from(builder: TlsConnectorBuilder) -> Self
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,