pingora_core/protocols/tls/
mod.rs1pub mod digest;
18pub use digest::*;
19
20#[cfg(feature = "openssl_derived")]
21mod boringssl_openssl;
22
23#[cfg(feature = "openssl_derived")]
24pub use boringssl_openssl::*;
25
26#[cfg(feature = "rustls")]
27mod rustls;
28
29#[cfg(feature = "rustls")]
30pub use rustls::*;
31
32#[cfg(not(feature = "any_tls"))]
33pub mod noop_tls;
34
35#[cfg(not(feature = "any_tls"))]
36pub use noop_tls::*;
37
38#[derive(Hash, Clone, Debug)]
40pub enum ALPN {
41 H1,
43 H2,
45 H2H1,
47}
48
49impl std::fmt::Display for ALPN {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 match self {
52 ALPN::H1 => write!(f, "H1"),
53 ALPN::H2 => write!(f, "H2"),
54 ALPN::H2H1 => write!(f, "H2H1"),
55 }
56 }
57}
58
59impl ALPN {
60 pub fn new(max: u8, min: u8) -> Self {
62 if max == 1 {
63 ALPN::H1
64 } else if min == 2 {
65 ALPN::H2
66 } else {
67 ALPN::H2H1
68 }
69 }
70
71 pub fn get_max_http_version(&self) -> u8 {
73 match self {
74 ALPN::H1 => 1,
75 _ => 2,
76 }
77 }
78
79 pub fn get_min_http_version(&self) -> u8 {
81 match self {
82 ALPN::H2 => 2,
83 _ => 1,
84 }
85 }
86
87 #[cfg(feature = "openssl_derived")]
88 pub(crate) fn to_wire_preference(&self) -> &[u8] {
89 match self {
92 Self::H1 => b"\x08http/1.1",
93 Self::H2 => b"\x02h2",
94 Self::H2H1 => b"\x02h2\x08http/1.1",
95 }
96 }
97
98 #[cfg(feature = "any_tls")]
99 pub(crate) fn from_wire_selected(raw: &[u8]) -> Option<Self> {
100 match raw {
101 b"http/1.1" => Some(Self::H1),
102 b"h2" => Some(Self::H2),
103 _ => None,
104 }
105 }
106
107 #[cfg(feature = "rustls")]
108 pub(crate) fn to_wire_protocols(&self) -> Vec<Vec<u8>> {
109 match self {
110 ALPN::H1 => vec![b"http/1.1".to_vec()],
111 ALPN::H2 => vec![b"h2".to_vec()],
112 ALPN::H2H1 => vec![b"h2".to_vec(), b"http/1.1".to_vec()],
113 }
114 }
115}