Botan 2.19.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*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_TLS_PROTOCOL_VERSION_H_
9#define BOTAN_TLS_PROTOCOL_VERSION_H_
10
11#include <botan/types.h>
12#include <string>
13
14namespace Botan {
15
16namespace TLS {
17
18/**
19* TLS Protocol Version
20*/
22 {
23 public:
25 TLS_V10 = 0x0301,
26 TLS_V11 = 0x0302,
27 TLS_V12 = 0x0303,
28
29 DTLS_V10 = 0xFEFF,
30 DTLS_V12 = 0xFEFD
31 };
32
33 /**
34 * @return latest known TLS version
35 */
37 {
38 return Protocol_Version(TLS_V12);
39 }
40
41 /**
42 * @return latest known DTLS version
43 */
45 {
46 return Protocol_Version(DTLS_V12);
47 }
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 */
57 Protocol_Version(static_cast<uint16_t>(named_version)) {}
58
59 /**
60 * @param major the major version
61 * @param minor the minor version
62 */
63 Protocol_Version(uint8_t major, uint8_t minor) :
64 Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}
65
66 /**
67 * @return true if this is a valid protocol version
68 */
69 bool valid() const { return (m_version != 0); }
70
71 /**
72 * @return true if this is a protocol version we know about
73 */
74 bool known_version() const;
75
76 /**
77 * @return major version of the protocol version
78 */
79 uint8_t major_version() const { return static_cast<uint8_t>(m_version >> 8); }
80
81 /**
82 * @return minor version of the protocol version
83 */
84 uint8_t minor_version() const { return static_cast<uint8_t>(m_version & 0xFF); }
85
86 /**
87 * @return the version code
88 */
89 uint16_t version_code() const { return m_version; }
90
91 /**
92 * @return human-readable description of this version
93 */
94 std::string to_string() const;
95
96 /**
97 * @return true iff this is a DTLS version
98 */
99 bool is_datagram_protocol() const;
100
101 /**
102 * @return true if this version supports negotiable signature algorithms
103 */
104 bool supports_negotiable_signature_algorithms() const;
105
106 /**
107 * @return true if this version uses explicit IVs for block ciphers
108 */
109 bool supports_explicit_cbc_ivs() const;
110
111 /**
112 * @return true if this version uses a ciphersuite specific PRF
113 */
114 bool supports_ciphersuite_specific_prf() const;
115
116 bool supports_aead_modes() const;
117
118 /**
119 * @return if this version is equal to other
120 */
121 bool operator==(const Protocol_Version& other) const
122 {
123 return (m_version == other.m_version);
124 }
125
126 /**
127 * @return if this version is not equal to other
128 */
129 bool operator!=(const Protocol_Version& other) const
130 {
131 return (m_version != other.m_version);
132 }
133
134 /**
135 * @return if this version is later than other
136 */
137 bool operator>(const Protocol_Version& other) const;
138
139 /**
140 * @return if this version is later than or equal to other
141 */
142 bool operator>=(const Protocol_Version& other) const
143 {
144 return (*this == other || *this > other);
145 }
146
147 private:
148 uint16_t m_version;
149 };
150
151}
152
153}
154
155#endif
156
Protocol_Version(uint8_t major, uint8_t minor)
Definition: tls_version.h:63
static Protocol_Version latest_dtls_version()
Definition: tls_version.h:44
bool operator==(const Protocol_Version &other) const
Definition: tls_version.h:121
uint8_t major_version() const
Definition: tls_version.h:79
bool operator!=(const Protocol_Version &other) const
Definition: tls_version.h:129
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36
bool operator>=(const Protocol_Version &other) const
Definition: tls_version.h:142
uint16_t version_code() const
Definition: tls_version.h:89
Protocol_Version(uint16_t code)
Definition: tls_version.h:51
uint8_t minor_version() const
Definition: tls_version.h:84
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
Definition: alg_id.cpp:13
bool operator>(const ASN1_Time &, const ASN1_Time &)
Definition: asn1_time.cpp:287
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11