ytls_traits/t_ctx.rs
1//! Common Context Impls
2
3use crate::{TlsLeftIn, TlsLeftOut, TlsRight};
4
5/// Marker for Handshake being complete
6#[derive(Debug, PartialEq)]
7pub struct HandshakeComplete;
8
9use crate::SecretStore;
10
11/// Implement to process handshaking part
12pub trait CtxHandshakeProcessor {
13 type Error;
14 /// Spin Handshake state forward
15 /// # Left
16 /// The Left is typically the I/O side allowing the state machine
17 /// to complete the handshake required
18 /// # Evolution
19 /// Once handshake is finished, Some(..) is given for the application
20 /// state machinery allowing de/encryption.
21 #[must_use]
22 fn spin_handshake<Li: TlsLeftIn, Lo: TlsLeftOut, Ks: SecretStore>(
23 &mut self,
24 _left_in: &mut Li,
25 _left_out: &mut Lo,
26 _ks: &mut Ks,
27 ) -> Result<Option<HandshakeComplete>, Self::Error>;
28}
29
30/// Marker for Shutdown being complete
31#[derive(Debug, PartialEq)]
32pub struct ShutdownComplete;
33
34/// Implement to process application data part
35pub trait CtxApplicationProcessor {
36 type Error;
37 /// Spin Application state forward with the given Left and Right sides.
38 /// # Left
39 /// Same as in handshake the left is typically the I/O allowing the
40 /// state machine to uphold the context alive and encrypt & decrypt
41 /// the application traffic.
42 /// # Right
43 /// Right side allows the application to both provide cleartext to the
44 /// state machinery to encrypt egress traffic as well as state machine
45 /// to provide the cleartext decrypted traffic to application.
46 /// # Evolution
47 /// Shutdown is provided when the state machinery can be shut down.
48 #[must_use]
49 fn spin_application<Li: TlsLeftIn, Lo: TlsLeftOut, R: TlsRight>(
50 &mut self,
51 _left_in: &mut Li,
52 _left_out: &mut Lo,
53 _right: &mut R,
54 ) -> Result<Option<ShutdownComplete>, Self::Error>;
55}