Skip to main content

bornera_rustls/
client_status.rs

1//! Data-only observations of a socket-free client session.
2
3use bornera::TransportDiagnostic;
4
5pub(crate) const STATUS_HANDSHAKING: u8 = 1 << 0;
6pub(crate) const STATUS_OPEN: u8 = 1 << 1;
7pub(crate) const STATUS_WANTS_READ: u8 = 1 << 2;
8pub(crate) const STATUS_WANTS_WRITE: u8 = 1 << 3;
9pub(crate) const STATUS_CLOSE_NOTIFY_SENT: u8 = 1 << 4;
10
11/// Exact bounded state needed by an external client transport and lifecycle owner.
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub struct RustlsClientStatus {
14    pub(crate) flags: u8,
15    pub(crate) readable_plaintext_bytes: usize,
16    pub(crate) tls_egress_bytes: usize,
17    pub(crate) peer_closure: crate::RustlsPeerClosure,
18    pub(crate) failure: Option<TransportDiagnostic>,
19}
20
21impl RustlsClientStatus {
22    /// Returns whether rustls is still negotiating the initial handshake.
23    pub const fn is_handshaking(self) -> bool {
24        self.flags & STATUS_HANDSHAKING != 0
25    }
26
27    /// Returns whether handshake completion and required egress are externally visible.
28    pub const fn is_open(self) -> bool {
29        self.flags & STATUS_OPEN != 0
30    }
31
32    /// Returns whether further encrypted peer input can progress the session.
33    pub const fn wants_read(self) -> bool {
34        self.flags & STATUS_WANTS_READ != 0
35    }
36
37    /// Returns whether [`crate::RustlsClientSession::drain_tls`] can produce output.
38    pub const fn wants_write(self) -> bool {
39        self.flags & STATUS_WANTS_WRITE != 0
40    }
41
42    /// Returns authenticated application bytes immediately available to read.
43    pub const fn readable_plaintext_bytes(self) -> usize {
44        self.readable_plaintext_bytes
45    }
46
47    /// Returns encrypted output observed by the last successful rustls transition.
48    pub const fn tls_egress_bytes(self) -> usize {
49        self.tls_egress_bytes
50    }
51
52    /// Returns the authenticated or raw peer-input termination state.
53    pub const fn peer_closure(self) -> crate::RustlsPeerClosure {
54        self.peer_closure
55    }
56
57    /// Returns whether local graceful TLS shutdown has started.
58    pub const fn close_notify_sent(self) -> bool {
59        self.flags & STATUS_CLOSE_NOTIFY_SENT != 0
60    }
61
62    /// Returns the first fatal bounded diagnostic, if progression has stopped.
63    pub const fn failure(self) -> Option<TransportDiagnostic> {
64        self.failure
65    }
66}