Skip to main content

bornera_rustls/
server_config.rs

1//! Shared configuration and capacity-first construction failures for server sessions.
2
3use std::sync::Arc;
4
5use bornera::TransportDiagnostic;
6use calandria::RetainedBytes;
7use rustls::ServerConfig;
8
9use crate::RustlsTransportLimits;
10
11/// Shared rustls identity and exact per-session retained-memory policy.
12#[derive(Clone, Debug)]
13pub struct RustlsServerConfig {
14    server: Arc<ServerConfig>,
15    limits: RustlsTransportLimits,
16}
17
18impl RustlsServerConfig {
19    /// Creates a socket-free server-session configuration.
20    pub const fn new(server: Arc<ServerConfig>, limits: RustlsTransportLimits) -> Self {
21        Self { server, limits }
22    }
23
24    /// Returns the shared rustls server identity and protocol policy.
25    pub const fn server_config(&self) -> &Arc<ServerConfig> {
26        &self.server
27    }
28
29    /// Returns the exact per-session transport bounds.
30    pub const fn limits(&self) -> RustlsTransportLimits {
31        self.limits
32    }
33}
34
35/// Failure before one socket-free rustls server session becomes observable.
36#[derive(Debug)]
37#[non_exhaustive]
38pub enum RustlsServerSessionError {
39    /// The configured session charge exceeds its caller-supplied ceiling.
40    Capacity {
41        /// Charge required by this rustls session configuration.
42        required: RetainedBytes,
43        /// Ceiling supplied by the connection owner.
44        supplied: RetainedBytes,
45    },
46    /// Rustls's initial logical state exceeded a configured bound.
47    Transport(TransportDiagnostic),
48    /// Rustls rejected construction of the server connection.
49    Tls(rustls::Error),
50}