# tls_commit.rs - source
Source of the Rust file `crates/core/src/config/tls_commit.rs`.

Skip to main content

#
tlsn_core/config/
tls_commit.rs

    1//! TLS commitment configuration.
    2
    3pub mod mpc;
    4
    5use serde::{Deserialize, Serialize};
    6
    7/// TLS commitment configuration.
    8#[derive(Debug, Clone, Serialize, Deserialize)]
    9pub struct TlsCommitConfig {
    10    protocol: TlsCommitProtocolConfig,
    11}
    12
    13impl TlsCommitConfig {
    14    /// Creates a new builder.
    15    pub fn builder() -> TlsCommitConfigBuilder {
    16        TlsCommitConfigBuilder::default()
    17    }
    18
    19    /// Returns the protocol configuration.
    20    pub fn protocol(&self) -> &TlsCommitProtocolConfig {
    21        &self.protocol
    22    }
    23
    24    /// Returns a TLS commitment request.
    25    pub fn to_request(&self) -> TlsCommitRequest {
    26        TlsCommitRequest {
    27            config: self.protocol.clone(),
    28        }
    29    }
    30}
    31
    32/// Builder for [`TlsCommitConfig`].
    33#[derive(Debug, Default, Clone, Serialize, Deserialize)]
    34pub struct TlsCommitConfigBuilder {
    35    protocol: Option<TlsCommitProtocolConfig>,
    36}
    37
    38impl TlsCommitConfigBuilder {
    39    /// Sets the protocol configuration.
    40    pub fn protocol<C>(mut self, protocol: C) -> Self
    41    where
    42        C: Into<TlsCommitProtocolConfig>,
    43    {
    44        self.protocol = Some(protocol.into());
    45        self
    46    }
    47
    48    /// Builds the configuration.
    49    pub fn build(self) -> Result<TlsCommitConfig, TlsCommitConfigError> {
    50        let protocol = self
    51            .protocol
    52            .ok_or(ErrorRepr::MissingField { name: "protocol" })?;
    53
    54        Ok(TlsCommitConfig { protocol })
    55    }
    56}
    57
    58/// TLS commitment protocol configuration.
    59#[derive(Debug, Clone, Serialize, Deserialize)]
    60#[non_exhaustive]
    61pub enum TlsCommitProtocolConfig {
    62    /// MPC-TLS configuration.
    63    Mpc(mpc::MpcTlsConfig),
    64}
    65
    66impl From<mpc::MpcTlsConfig> for TlsCommitProtocolConfig {
    67    fn from(config: mpc::MpcTlsConfig) -> Self {
    68        Self::Mpc(config)
    69    }
    70}
    71
    72/// TLS commitment request.
    73#[derive(Debug, Clone, Serialize, Deserialize)]
    74pub struct TlsCommitRequest {
    75    config: TlsCommitProtocolConfig,
    76}
    77
    78impl TlsCommitRequest {
    79    /// Returns the protocol configuration.
    80    pub fn protocol(&self) -> &TlsCommitProtocolConfig {
    81        &self.config
    82    }
    83}
    84
    85/// Error for [`TlsCommitConfig`].
    86#[derive(Debug, thiserror::Error)]
    87#[error(transparent)]
    88pub struct TlsCommitConfigError(#[from] ErrorRepr);
    89
    90#[derive(Debug, thiserror::Error)]
    91enum ErrorRepr {
    92    #[error("missing field: {name}")]
    93    MissingField { name: &'static str },
    94}