tlspuffin/tls/rustls/
versions.rs1use crate::tls::rustls::msgs::enums::ProtocolVersion;
2
3#[derive(Debug, PartialEq)]
9#[non_exhaustive]
10pub struct SupportedProtocolVersion {
11 pub version: ProtocolVersion,
13}
14
15pub static TLS12: SupportedProtocolVersion = SupportedProtocolVersion {
17 version: ProtocolVersion::TLSv1_2,
18};
19
20pub static TLS13: SupportedProtocolVersion = SupportedProtocolVersion {
22 version: ProtocolVersion::TLSv1_3,
23};
24
25pub static ALL_VERSIONS: &[&SupportedProtocolVersion] = &[&TLS13, &TLS12];
27
28pub static DEFAULT_VERSIONS: &[&SupportedProtocolVersion] = ALL_VERSIONS;
34
35#[derive(Debug, Clone)]
36pub struct EnabledVersions {
37 tls12: Option<&'static SupportedProtocolVersion>,
38 tls13: Option<&'static SupportedProtocolVersion>,
39}
40
41impl EnabledVersions {
42 pub fn new(versions: &[&'static SupportedProtocolVersion]) -> Self {
43 let mut ev = Self {
44 tls12: None,
45 tls13: None,
46 };
47
48 for v in versions {
49 match v.version {
50 ProtocolVersion::TLSv1_2 => ev.tls12 = Some(v),
51 ProtocolVersion::TLSv1_3 => ev.tls13 = Some(v),
52 _ => {}
53 }
54 }
55
56 ev
57 }
58
59 pub fn contains(&self, version: ProtocolVersion) -> bool {
60 match version {
61 ProtocolVersion::TLSv1_2 => self.tls12.is_some(),
62 ProtocolVersion::TLSv1_3 => self.tls13.is_some(),
63 _ => false,
64 }
65 }
66}