# msg.rs - source
Source of the Rust file `crates/tlsn/src/msg.rs`.

Skip to main content

#
tlsn/
msg.rs

    1use std::fmt;
    2
    3use semver::Version;
    4use serde::{Deserialize, Serialize};
    5
    6use tlsn_core::{
    7    config::{prove::ProveRequest, tls_commit::TlsCommitRequest},
    8    connection::{HandshakeData, ServerName},
    9    transcript::PartialTranscript,
    10};
    11
    12#[derive(Debug, Serialize, Deserialize)]
    13pub(crate) struct TlsCommitRequestMsg {
    14    pub(crate) request: TlsCommitRequest,
    15    pub(crate) version: Version,
    16}
    17
    18#[derive(Debug, Serialize, Deserialize)]
    19pub(crate) struct ProveRequestMsg {
    20    pub(crate) request: ProveRequest,
    21    pub(crate) handshake: Option<(ServerName, HandshakeData)>,
    22    pub(crate) transcript: Option<PartialTranscript>,
    23}
    24
    25#[derive(Debug, Serialize, Deserialize)]
    26pub(crate) struct Response {
    27    pub(crate) result: Result<(), RejectionReason>,
    28}
    29
    30impl Response {
    31    pub(crate) fn ok() -> Self {
    32        Self { result: Ok(()) }
    33    }
    34
    35    pub(crate) fn err(msg: Option<impl Into<String>>) -> Self {
    36        Self {
    37            result: Err(RejectionReason(msg.map(Into::into))),
    38        }
    39    }
    40}
    41
    42#[derive(Debug, Serialize, Deserialize)]
    43pub(crate) struct RejectionReason(Option<String>);
    44
    45impl fmt::Display for RejectionReason {
    46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    47        if let Some(msg) = &self.0 {
    48            write!(f, "{msg}")
    49        } else {
    50            write!(f, "no reason provided")
    51        }
    52    }
    53}
    54
    55impl std::error::Error for RejectionReason {}