Crate tokio_libtls

Source
Expand description

Async Tls bindings for libtls.

See also libtls for more information.

Note, the API for this crate is neither finished nor documented yet.

§Example

use std::io;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio_libtls::prelude::{connect, Builder};

async fn async_https_connect(servername: String) -> io::Result<()> {
    let request = format!(
        "GET / HTTP/1.1\r\n\
         Host: {}\r\n\
         Connection: close\r\n\r\n",
        servername
    );

    let config = Builder::new().build()?;
    let mut tls = connect(&(servername + ":443"), &config, None).await?;
    tls.write_all(request.as_bytes()).await?;

    let mut buf = vec![0u8; 1024];
    tls.read_exact(&mut buf).await?;

    let ok = b"HTTP/1.1 200 OK\r\n";
    assert_eq!(&buf[..ok.len()], ok);

    Ok(())
}

Modules§

error
Error handling.
prelude
A “prelude” for crates using the tokio-libtls crate.

Structs§

AsyncTls
Async Tls struct.
Options
Configuration options for AsyncTls.
TlsStream
Wrapper for async I/O operations with Tls.

Functions§

accept
Accept a new async Tls connection.
accept_stream
Accept a new async Tls connection on an established client connection.
connect
Connect a new async Tls connection.
connect_stream
Upgrade a TCP stream to a new async Tls connection.

Type Aliases§

AsyncTlsOptionsDeprecated
Configuration options for AsyncTls.
AsyncTlsStream
Pollable wrapper for async I/O operations with Tls.