Module tls_rustls

Source
Available on crate feature tls-rustls only.
Expand description

Tls implementation using rustls.

§Example

use axum::{routing::get, Router};
use hyper_server::tls_rustls::RustlsConfig;
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    let config = RustlsConfig::from_pem_file(
        "examples/self-signed-certs/cert.pem",
        "examples/self-signed-certs/key.pem",
    )
    .await
    .unwrap();

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening on {}", addr);
    hyper_server::bind_rustls(addr, config)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

Modules§

future
Module containing futures specific to the rustls TLS acceptor for the server.

Structs§

RustlsAcceptor
A TLS acceptor implementation using the rustls library.
RustlsConfig
Represents the rustls configuration for the server.

Functions§

bind_rustls
Helper function to create a TLS server bound to a provided address.
from_tcp_rustls
Helper function to create a TLS server from an existing std::net::TcpListener.