use std::fmt;
use crate::enums::ProtocolVersion;
#[derive(Eq, PartialEq)]
#[allow(clippy::manual_non_exhaustive)] pub struct SupportedProtocolVersion {
pub version: ProtocolVersion,
is_private: (),
}
impl fmt::Debug for SupportedProtocolVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.version.fmt(f)
}
}
#[cfg(feature = "tls12")]
pub static TLS12: SupportedProtocolVersion = SupportedProtocolVersion {
version: ProtocolVersion::TLSv1_2,
is_private: (),
};
pub static TLS13: SupportedProtocolVersion = SupportedProtocolVersion {
version: ProtocolVersion::TLSv1_3,
is_private: (),
};
pub static ALL_VERSIONS: &[&SupportedProtocolVersion] = &[
&TLS13,
#[cfg(feature = "tls12")]
&TLS12,
];
pub static DEFAULT_VERSIONS: &[&SupportedProtocolVersion] = ALL_VERSIONS;
#[derive(Clone)]
pub(crate) struct EnabledVersions {
#[cfg(feature = "tls12")]
tls12: Option<&'static SupportedProtocolVersion>,
tls13: Option<&'static SupportedProtocolVersion>,
}
impl fmt::Debug for EnabledVersions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut list = &mut f.debug_list();
#[cfg(feature = "tls12")]
if let Some(v) = self.tls12 {
list = list.entry(v);
}
if let Some(v) = self.tls13 {
list = list.entry(v);
}
list.finish()
}
}
impl EnabledVersions {
pub(crate) fn new(versions: &[&'static SupportedProtocolVersion]) -> Self {
let mut ev = Self {
#[cfg(feature = "tls12")]
tls12: None,
tls13: None,
};
for v in versions {
match v.version {
#[cfg(feature = "tls12")]
ProtocolVersion::TLSv1_2 => ev.tls12 = Some(v),
ProtocolVersion::TLSv1_3 => ev.tls13 = Some(v),
_ => {}
}
}
ev
}
pub(crate) fn contains(&self, version: ProtocolVersion) -> bool {
match version {
#[cfg(feature = "tls12")]
ProtocolVersion::TLSv1_2 => self.tls12.is_some(),
ProtocolVersion::TLSv1_3 => self.tls13.is_some(),
_ => false,
}
}
}