rustls/
versions.rs

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