tls.rs

Overview

This file provides functionality to create and configure a TLS-enabled client configuration for network transport. It primarily exposes a single function that builds a wtransport::ClientConfig instance using TLS settings derived from client credentials and optional ALPN (Application-Layer Protocol Negotiation) preferences. The TLS configuration is assembled by delegating to an internal helper function, allowing flexible setup for both debug and production environments.

The main responsibility of this file is to abstract the process of configuring a secure client transport layer, integrating TLS parameters seamlessly with the underlying transport client configuration.

Functions

create_client_config

pub fn create_client_config(
    is_debug: bool,
    credential: &NetCredential,
    alpn_preferred: &[&str],
) -> Result<wtransport::ClientConfig, anyhow::Error>

Description

Constructs a client configuration for secure network transport using TLS. It incorporates TLS settings based on provided credentials and ALPN protocol preferences. The function supports a debug mode toggle which may influence TLS parameters (e.g., certificate verification looseness).

It internally calls client_tls_config to generate the TLS configuration, then uses that to build a wtransport::ClientConfig with default binding and custom TLS applied.

Parameters

Returns

Usage Example

let credential = NetCredential::load_from_file("client_cert.pem")?;
let alpn_protocols = vec!["h2", "http/1.1"];
let client_config = create_client_config(false, &credential, &alpn_protocols)?;

Implementation Details

Interactions with Other System Components

The file acts as a bridge between raw TLS configuration and the client transport layer setup, abstracting complexity and providing a simplified API for client configuration.

Diagram: Function Workflow

flowchart TD
A[create_client_config] --> B[client_tls_config]
B -->|Returns TLS config| C[wtransport::ClientConfig Builder]
C --> D["with_bind_default()"]
D --> E["with_custom_tls(tls_config)"]
E --> F["build()"]
F --> G[Result<ClientConfig, Error>]

This diagram illustrates the flow within the create_client_config function, showing how it calls client_tls_config, then uses the returned TLS config to build and return a client configuration object.