Expand description

SSL server listener, replacement for TcpListener that can accept SSL connections.

// BlazeListener is wrapper over tokios TcpListener
use blaze_ssl_async::{BlazeListener, BlazeServerContext};
// Tokio read write extensions used for read_exact and write_all
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use std::sync::Arc;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let context: Arc<BlazeServerContext> = Default::default();
    // Bind a listener accepts the same address values as the tokio TcpListener
    let listener = BlazeListener::bind(("0.0.0.0", 42127), context).await?;

    // Accept new connections
    loop {
        // Accept the initial TcpStream without SSL
        let accept = listener.accept().await?;
        tokio::spawn(async move {
            // Complete the SSL handshake process in a spawned task
            let (stream, addr) = accept.finish_accept()
                .await
                .expect("Failed to finish accepting stream");

            // Read and write to the stream the same as in the client example
        });
    }
}

Structs

  • Represents an stream accepting from a BlazeListener that has not yet completed its SSL handshake.
  • Listener wrapping TcpListener in order to accept SSL connections
  • Context state for a SSL server, contains the private key and certificate chain
  • DER-encoded X.509 certificate bytes representing a certificate
  • Represents a whole RSA key, public and private parts.

Traits