rustls/
versions.rs

1use crate::enums::ProtocolVersion;
2
3/// A TLS protocol version supported by rustls.
4///
5/// All possible values of this enum are provided by the library in
6/// the [`ALL_VERSIONS`] array, as well as individually as [`TLS12`]
7/// and [`TLS13`].
8#[non_exhaustive]
9#[derive(Debug)]
10pub enum SupportedProtocolVersion {
11    /// The TLS1.2 protocol version.
12    TLS12(&'static Tls12Version),
13    /// The TLS1.3 protocol version.
14    TLS13(&'static Tls13Version),
15}
16
17impl SupportedProtocolVersion {
18    /// The TLS enumeration naming this version.
19    pub const fn version(&self) -> ProtocolVersion {
20        match self {
21            Self::TLS12(_) => ProtocolVersion::TLSv1_2,
22            Self::TLS13(_) => ProtocolVersion::TLSv1_3,
23        }
24    }
25}
26
27impl PartialEq for SupportedProtocolVersion {
28    fn eq(&self, other: &Self) -> bool {
29        matches!(
30            (self, other),
31            (Self::TLS12(_), Self::TLS12(_)) | (Self::TLS13(_), Self::TLS13(_))
32        )
33    }
34}
35
36impl Eq for SupportedProtocolVersion {}
37
38/// TLS1.2
39pub static TLS12: SupportedProtocolVersion = SupportedProtocolVersion::TLS12(TLS12_VERSION);
40
41/// TLS1.3
42pub static TLS13: SupportedProtocolVersion = SupportedProtocolVersion::TLS13(TLS13_VERSION);
43
44/// A list of all the protocol versions supported by rustls.
45pub static ALL_VERSIONS: &[&SupportedProtocolVersion] = &[&TLS13, &TLS12];
46
47/// The version configuration that an application should use by default.
48///
49/// This will be [`ALL_VERSIONS`] for now, but gives space in the future
50/// to remove a version from here and require users to opt-in to older
51/// versions.
52pub static DEFAULT_VERSIONS: &[&SupportedProtocolVersion] = ALL_VERSIONS;
53
54/// Internal data for handling the TLS1.2 protocol.
55///
56/// This value refers to TLS1.2 protocol handling code.  This means
57/// that if your program does not refer to this value, all that code
58/// can be removed by the linker.
59pub static TLS12_VERSION: &Tls12Version = &Tls12Version {
60    client: crate::client::TLS12_HANDLER,
61    server: crate::server::TLS12_HANDLER,
62};
63
64/// Internal data for handling the TLS1.3 protocol.
65///
66/// This value refers to TLS1.3 protocol handling code.  This means
67/// that if your program does not refer to this value, all that code
68/// can be removed by the linker.
69pub static TLS13_VERSION: &Tls13Version = &Tls13Version {
70    client: crate::client::TLS13_HANDLER,
71    server: crate::server::TLS13_HANDLER,
72};
73
74/// Internal data for handling the TLS1.2 protocol.
75///
76/// There is one value of this type.  It is `TLS12_VERSION`.
77#[non_exhaustive]
78#[derive(Debug)]
79pub struct Tls12Version {
80    pub(crate) client: &'static dyn crate::client::Tls12Handler,
81    pub(crate) server: &'static dyn crate::server::Tls12Handler,
82}
83
84/// Internal data for handling the TLS1.3 protocol.
85///
86/// There is one value of this type.  It is `TLS13_VERSION`.
87#[non_exhaustive]
88#[derive(Debug)]
89pub struct Tls13Version {
90    pub(crate) client: &'static dyn crate::client::Tls13Handler,
91    pub(crate) server: &'static dyn crate::server::Tls13Handler,
92}