bornera_rustls/
server_status.rs1use 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#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13#[non_exhaustive]
14pub enum RustlsPeerClosure {
15 Open,
17 Clean,
19 Truncated,
21}
22
23#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub struct RustlsServerStatus {
26 pub(crate) flags: u8,
27 pub(crate) readable_plaintext_bytes: usize,
28 pub(crate) tls_egress_bytes: usize,
29 pub(crate) peer_closure: RustlsPeerClosure,
30 pub(crate) failure: Option<TransportDiagnostic>,
31}
32
33impl RustlsServerStatus {
34 pub const fn is_handshaking(self) -> bool {
36 self.flags & STATUS_HANDSHAKING != 0
37 }
38
39 pub const fn is_handshake_complete(self) -> bool {
41 !self.is_handshaking()
42 }
43
44 pub const fn is_open(self) -> bool {
46 self.flags & STATUS_OPEN != 0
47 }
48
49 pub const fn wants_read(self) -> bool {
51 self.flags & STATUS_WANTS_READ != 0
52 }
53
54 pub const fn wants_write(self) -> bool {
56 self.flags & STATUS_WANTS_WRITE != 0
57 }
58
59 pub const fn readable_plaintext_bytes(self) -> usize {
61 self.readable_plaintext_bytes
62 }
63
64 pub const fn tls_egress_bytes(self) -> usize {
66 self.tls_egress_bytes
67 }
68
69 pub const fn peer_closure(self) -> RustlsPeerClosure {
71 self.peer_closure
72 }
73
74 pub const fn close_notify_sent(self) -> bool {
76 self.flags & STATUS_CLOSE_NOTIFY_SENT != 0
77 }
78
79 pub const fn failure(self) -> Option<TransportDiagnostic> {
81 self.failure
82 }
83}