Botan 3.4.0
Crypto and TLS for C&
tls_version.h
Go to the documentation of this file.
1/*
2* TLS Protocol Version Management
3* (C) 2012 Jack Lloyd
4* 2021 Elektrobit Automotive GmbH
5* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_TLS_PROTOCOL_VERSION_H_
11#define BOTAN_TLS_PROTOCOL_VERSION_H_
12
13#include <botan/types.h>
14#include <string>
15
16namespace Botan::TLS {
17
18enum class Version_Code : uint16_t {
19 TLS_V11 = 0x0302, // not supported by Botan
20 TLS_V12 = 0x0303,
21 TLS_V13 = 0x0304,
22 DTLS_V12 = 0xFEFD,
23 DTLS_V13 = 0xFEFC, // not supported by Botan
24};
25
26/**
27* TLS Protocol Version
28*/
30 public:
31 using enum Version_Code;
32
33 /**
34 * @return latest known TLS version
35 */
37#if defined(BOTAN_HAS_TLS_13)
39#else
41#endif
42 }
43
44 /**
45 * @return latest known DTLS version
46 */
48
49 Protocol_Version() : m_version(0) {}
50
51 explicit Protocol_Version(uint16_t code) : m_version(code) {}
52
53 /**
54 * @param named_version a specific named version of the protocol
55 */
56 Protocol_Version(Version_Code named_version) : Protocol_Version(static_cast<uint16_t>(named_version)) {}
57
58 /**
59 * @param major the major version
60 * @param minor the minor version
61 */
62 Protocol_Version(uint8_t major, uint8_t minor) :
63 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}
64
65 /**
66 * @return true if this is a valid protocol version
67 */
68 bool valid() const;
69
70 /**
71 * @return true if this is a protocol version we know about
72 */
73 bool known_version() const;
74
75 /**
76 * @return major version of the protocol version
77 */
78 uint8_t major_version() const { return static_cast<uint8_t>(m_version >> 8); }
79
80 /**
81 * @return minor version of the protocol version
82 */
83 uint8_t minor_version() const { return static_cast<uint8_t>(m_version & 0xFF); }
84
85 /**
86 * @return the version code
87 */
88 uint16_t version_code() const { return m_version; }
89
90 /**
91 * @return human-readable description of this version
92 */
93 std::string to_string() const;
94
95 /**
96 * @return true iff this is a DTLS version
97 */
98 bool is_datagram_protocol() const;
99
100 /**
101 * @return true if this version indicates (D)TLS 1.2 or older
102 */
103 bool is_pre_tls_13() const;
104
105 /**
106 * @return true if this version indicates a (D)TLS newer than 1.3
107 */
108 bool is_tls_13_or_later() const;
109
110 /**
111 * @return if this version is equal to other
112 */
113 bool operator==(const Protocol_Version& other) const { return (m_version == other.m_version); }
114
115 /**
116 * @return if this version is not equal to other
117 */
118 bool operator!=(const Protocol_Version& other) const { return (m_version != other.m_version); }
119
120 /**
121 * @return if this version is later than other
122 */
123 bool operator>(const Protocol_Version& other) const;
124
125 /**
126 * @return if this version is later than or equal to other
127 */
128 bool operator>=(const Protocol_Version& other) const { return (*this == other || *this > other); }
129
130 /**
131 * @return if this version is earlier to other
132 */
133 bool operator<(const Protocol_Version& other) const { return !(*this >= other); }
134
135 /**
136 * @return if this version is earlier than or equal to other
137 */
138 bool operator<=(const Protocol_Version& other) const { return (*this == other || *this < other); }
139
140 private:
141 uint16_t m_version;
142};
143
144} // namespace Botan::TLS
145
146#endif
Protocol_Version(uint8_t major, uint8_t minor)
Definition tls_version.h:62
static Protocol_Version latest_dtls_version()
Definition tls_version.h:47
bool operator==(const Protocol_Version &other) const
uint8_t major_version() const
Definition tls_version.h:78
bool operator!=(const Protocol_Version &other) const
static Protocol_Version latest_tls_version()
Definition tls_version.h:36
bool operator>=(const Protocol_Version &other) const
uint16_t version_code() const
Definition tls_version.h:88
bool operator<=(const Protocol_Version &other) const
Protocol_Version(uint16_t code)
Definition tls_version.h:51
bool operator<(const Protocol_Version &other) const
uint8_t minor_version() const
Definition tls_version.h:83
Protocol_Version(Version_Code named_version)
Definition tls_version.h:56
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
bool operator>(const ASN1_Time &, const ASN1_Time &)