Skip to main content

tlsn_core/config/tls_commit/
proxy.rs

1//! Proxy-TLS commitment protocol configuration.
2
3use crate::connection::DnsName;
4use serde::{Deserialize, Serialize};
5
6/// Proxy-TLS commitment protocol configuration.
7#[derive(Clone, Debug, Deserialize, Serialize)]
8pub struct ProxyTlsConfig {
9    /// The server name.
10    server_name: DnsName,
11}
12
13impl ProxyTlsConfig {
14    /// Creates a new builder.
15    pub fn builder() -> ProxyTlsConfigBuilder {
16        ProxyTlsConfigBuilder::default()
17    }
18
19    /// Returns the server name.
20    pub fn server_name(&self) -> &DnsName {
21        &self.server_name
22    }
23}
24
25/// Builder for [`ProxyTlsConfig`].
26#[derive(Debug, Default)]
27pub struct ProxyTlsConfigBuilder {
28    server_name: Option<DnsName>,
29}
30
31impl ProxyTlsConfigBuilder {
32    /// Sets the server name.
33    pub fn server_name(mut self, server_name: DnsName) -> Self {
34        self.server_name = Some(server_name);
35        self
36    }
37
38    /// Builds the configuration.
39    pub fn build(self) -> Result<ProxyTlsConfig, ProxyTlsConfigError> {
40        let server_name = self
41            .server_name
42            .ok_or(ProxyTlsConfigError(ErrorRepr::MissingField {
43                name: "server_name",
44            }))?;
45
46        let config = ProxyTlsConfig { server_name };
47        Ok(config)
48    }
49}
50
51/// Error for [`ProxyTlsConfig`].
52#[derive(Debug, thiserror::Error)]
53#[error(transparent)]
54pub struct ProxyTlsConfigError(#[from] ErrorRepr);
55
56#[derive(Debug, thiserror::Error)]
57enum ErrorRepr {
58    #[error("missing field: {name}")]
59    MissingField { name: &'static str },
60}