pub mod digest;
pub use digest::*;
#[cfg(feature = "openssl_derived")]
mod boringssl_openssl;
#[cfg(feature = "openssl_derived")]
pub use boringssl_openssl::*;
#[cfg(feature = "rustls")]
mod rustls;
#[cfg(feature = "rustls")]
pub use rustls::*;
#[cfg(not(feature = "any_tls"))]
pub mod noop_tls;
#[cfg(not(feature = "any_tls"))]
pub use noop_tls::*;
#[derive(Hash, Clone, Debug)]
pub enum ALPN {
H1,
H2,
H2H1,
}
impl std::fmt::Display for ALPN {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ALPN::H1 => write!(f, "H1"),
ALPN::H2 => write!(f, "H2"),
ALPN::H2H1 => write!(f, "H2H1"),
}
}
}
impl ALPN {
pub fn new(max: u8, min: u8) -> Self {
if max == 1 {
ALPN::H1
} else if min == 2 {
ALPN::H2
} else {
ALPN::H2H1
}
}
pub fn get_max_http_version(&self) -> u8 {
match self {
ALPN::H1 => 1,
_ => 2,
}
}
pub fn get_min_http_version(&self) -> u8 {
match self {
ALPN::H2 => 2,
_ => 1,
}
}
#[cfg(feature = "openssl_derived")]
pub(crate) fn to_wire_preference(&self) -> &[u8] {
match self {
Self::H1 => b"\x08http/1.1",
Self::H2 => b"\x02h2",
Self::H2H1 => b"\x02h2\x08http/1.1",
}
}
#[cfg(feature = "any_tls")]
pub(crate) fn from_wire_selected(raw: &[u8]) -> Option<Self> {
match raw {
b"http/1.1" => Some(Self::H1),
b"h2" => Some(Self::H2),
_ => None,
}
}
#[cfg(feature = "rustls")]
pub(crate) fn to_wire_protocols(&self) -> Vec<Vec<u8>> {
match self {
ALPN::H1 => vec![b"http/1.1".to_vec()],
ALPN::H2 => vec![b"h2".to_vec()],
ALPN::H2H1 => vec![b"h2".to_vec(), b"http/1.1".to_vec()],
}
}
}