Botan 3.1.1
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 {
17
18namespace TLS {
19
20enum class Version_Code : uint16_t {
21 TLS_V11 = 0x0302, // not supported by Botan
22 TLS_V12 = 0x0303,
23 TLS_V13 = 0x0304,
24 DTLS_V12 = 0xFEFD,
25 DTLS_V13 = 0xFEFC, // not supported by Botan
26};
27
28/**
29* TLS Protocol Version
30*/
32 public:
33 using enum Version_Code;
34
35 /**
36 * @return latest known TLS version
37 */
39#if defined(BOTAN_HAS_TLS_13)
41#else
43#endif
44 }
45
46 /**
47 * @return latest known DTLS version
48 */
50
51 Protocol_Version() : m_version(0) {}
52
53 explicit Protocol_Version(uint16_t code) : m_version(code) {}
54
55 /**
56 * @param named_version a specific named version of the protocol
57 */
58 Protocol_Version(Version_Code named_version) : Protocol_Version(static_cast<uint16_t>(named_version)) {}
59
60 /**
61 * @param major the major version
62 * @param minor the minor version
63 */
64 Protocol_Version(uint8_t major, uint8_t minor) :
65 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}
66
67 /**
68 * @return true if this is a valid protocol version
69 */
70 bool valid() const;
71
72 /**
73 * @return true if this is a protocol version we know about
74 */
75 bool known_version() const;
76
77 /**
78 * @return major version of the protocol version
79 */
80 uint8_t major_version() const { return static_cast<uint8_t>(m_version >> 8); }
81
82 /**
83 * @return minor version of the protocol version
84 */
85 uint8_t minor_version() const { return static_cast<uint8_t>(m_version & 0xFF); }
86
87 /**
88 * @return the version code
89 */
90 uint16_t version_code() const { return m_version; }
91
92 /**
93 * @return human-readable description of this version
94 */
95 std::string to_string() const;
96
97 /**
98 * @return true iff this is a DTLS version
99 */
100 bool is_datagram_protocol() const;
101
102 /**
103 * @return true if this version indicates (D)TLS 1.2 or older
104 */
105 bool is_pre_tls_13() const;
106
107 /**
108 * @return true if this version indicates a (D)TLS newer than 1.3
109 */
110 bool is_tls_13_or_later() const;
111
112 /**
113 * @return if this version is equal to other
114 */
115 bool operator==(const Protocol_Version& other) const { return (m_version == other.m_version); }
116
117 /**
118 * @return if this version is not equal to other
119 */
120 bool operator!=(const Protocol_Version& other) const { return (m_version != other.m_version); }
121
122 /**
123 * @return if this version is later than other
124 */
125 bool operator>(const Protocol_Version& other) const;
126
127 /**
128 * @return if this version is later than or equal to other
129 */
130 bool operator>=(const Protocol_Version& other) const { return (*this == other || *this > other); }
131
132 /**
133 * @return if this version is earlier to other
134 */
135 bool operator<(const Protocol_Version& other) const { return !(*this >= other); }
136
137 /**
138 * @return if this version is earlier than or equal to other
139 */
140 bool operator<=(const Protocol_Version& other) const { return (*this == other || *this < other); }
141
142 private:
143 uint16_t m_version;
144};
145
146} // namespace TLS
147
148} // namespace Botan
149
150#endif
Protocol_Version(uint8_t major, uint8_t minor)
Definition: tls_version.h:64
static Protocol_Version latest_dtls_version()
Definition: tls_version.h:49
bool operator==(const Protocol_Version &other) const
Definition: tls_version.h:115
uint8_t major_version() const
Definition: tls_version.h:80
bool operator!=(const Protocol_Version &other) const
Definition: tls_version.h:120
static Protocol_Version latest_tls_version()
Definition: tls_version.h:38
bool operator>=(const Protocol_Version &other) const
Definition: tls_version.h:130
uint16_t version_code() const
Definition: tls_version.h:90
bool operator<=(const Protocol_Version &other) const
Definition: tls_version.h:140
Protocol_Version(uint16_t code)
Definition: tls_version.h:53
bool operator<(const Protocol_Version &other) const
Definition: tls_version.h:135
uint8_t minor_version() const
Definition: tls_version.h:85
Protocol_Version(Version_Code named_version)
Definition: tls_version.h:58
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:20
Definition: alg_id.cpp:13
bool operator>(const ASN1_Time &, const ASN1_Time &)
Definition: asn1_time.cpp:280