Struct async_native_tls::TlsConnector[][src]

pub struct TlsConnector { /* fields omitted */ }
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

Create a new instance.

Sets the identity to be used for client certificate authentication.

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).

Sets the maximum supported protocol version.

A value of None enables support for the newest protocols supported by the implementation. Defaults to None.

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.

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.

Controls the use of Server Name Indication (SNI).

Defaults to true.

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.

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.