tlsn_verifier/
state.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! TLS Verifier state.

use tls_mpc::MpcTlsFollower;
use tlsn_common::{
    mux::{MuxControl, MuxFuture},
    Context, DEAPThread, Io, OTSender,
};
use tlsn_core::connection::{ConnectionInfo, ServerEphemKey};

/// TLS Verifier state.
pub trait VerifierState: sealed::Sealed {}

/// Initialized state.
pub struct Initialized;

opaque_debug::implement!(Initialized);

/// State after MPC setup has completed.
pub struct Setup {
    pub(crate) io: Io,
    pub(crate) mux_ctrl: MuxControl,
    pub(crate) mux_fut: MuxFuture,

    pub(crate) mpc_tls: MpcTlsFollower,
    pub(crate) vm: DEAPThread,
    pub(crate) ot_send: OTSender,
    pub(crate) ctx: Context,

    pub(crate) encoder_seed: [u8; 32],
}

/// State after the TLS connection has been closed.
pub struct Closed {
    pub(crate) io: Io,
    pub(crate) mux_ctrl: MuxControl,
    pub(crate) mux_fut: MuxFuture,

    pub(crate) vm: DEAPThread,
    pub(crate) ot_send: OTSender,
    pub(crate) ctx: Context,

    pub(crate) encoder_seed: [u8; 32],
    pub(crate) server_ephemeral_key: ServerEphemKey,
    pub(crate) connection_info: ConnectionInfo,
}

opaque_debug::implement!(Closed);

/// Notarizing state.
pub struct Notarize {
    pub(crate) io: Io,
    pub(crate) mux_ctrl: MuxControl,
    pub(crate) mux_fut: MuxFuture,

    pub(crate) vm: DEAPThread,
    pub(crate) ot_send: OTSender,
    pub(crate) ctx: Context,

    pub(crate) encoder_seed: [u8; 32],
    pub(crate) server_ephemeral_key: ServerEphemKey,
    pub(crate) connection_info: ConnectionInfo,
}

opaque_debug::implement!(Notarize);

impl From<Closed> for Notarize {
    fn from(value: Closed) -> Self {
        Self {
            io: value.io,
            mux_ctrl: value.mux_ctrl,
            mux_fut: value.mux_fut,
            vm: value.vm,
            ot_send: value.ot_send,
            ctx: value.ctx,
            encoder_seed: value.encoder_seed,
            server_ephemeral_key: value.server_ephemeral_key,
            connection_info: value.connection_info,
        }
    }
}

/// Verifying state.
pub struct Verify {
    pub(crate) io: Io,
    pub(crate) mux_ctrl: MuxControl,
    pub(crate) mux_fut: MuxFuture,

    pub(crate) vm: DEAPThread,
    pub(crate) ot_send: OTSender,
    pub(crate) ctx: Context,

    pub(crate) server_ephemeral_key: ServerEphemKey,
    pub(crate) connection_info: ConnectionInfo,
}

opaque_debug::implement!(Verify);

impl From<Closed> for Verify {
    fn from(value: Closed) -> Self {
        Self {
            io: value.io,
            mux_ctrl: value.mux_ctrl,
            mux_fut: value.mux_fut,
            vm: value.vm,
            ot_send: value.ot_send,
            ctx: value.ctx,
            server_ephemeral_key: value.server_ephemeral_key,
            connection_info: value.connection_info,
        }
    }
}

impl VerifierState for Initialized {}
impl VerifierState for Setup {}
impl VerifierState for Closed {}
impl VerifierState for Notarize {}
impl VerifierState for Verify {}

mod sealed {
    pub trait Sealed {}
    impl Sealed for super::Initialized {}
    impl Sealed for super::Setup {}
    impl Sealed for super::Closed {}
    impl Sealed for super::Notarize {}
    impl Sealed for super::Verify {}
}