Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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/loadstor.h>
12 #include <string>
13
14 namespace Botan {
15
16 namespace TLS {
17
18 /**
19 * TLS Protocol Version
20 */
21 class BOTAN_DLL Protocol_Version
22 {
23 public:
24 enum Version_Code {
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 */
36 static Protocol_Version latest_tls_version()
37 {
38 return Protocol_Version(TLS_V12);
39 }
40
41 /**
42 * @return latest known DTLS version
43 */
44 static Protocol_Version latest_dtls_version()
45 {
46 return Protocol_Version(DTLS_V12);
47 }
48
49 Protocol_Version() : m_version(0) {}
50
51 /**
52 * @param named_version a specific named version of the protocol
53 */
54 Protocol_Version(Version_Code named_version) :
55 m_version(static_cast<uint16_t>(named_version)) {}
56
57 /**
58 * @param major the major version
59 * @param minor the minor version
60 */
61 Protocol_Version(uint8_t major, uint8_t minor) :
62 m_version((static_cast<uint16_t>(major) << 8) | minor) {}
63
64 /**
65 * @return true if this is a valid protocol version
66 */
67 bool valid() const { return (m_version != 0); }
68
69 /**
70 * @return true if this is a protocol version we know about
71 */
72 bool known_version() const;
73
74 /**
75 * @return major version of the protocol version
76 */
77 uint8_t major_version() const { return get_byte(0, m_version); }
78
79 /**
80 * @return minor version of the protocol version
81 */
82 uint8_t minor_version() const { return get_byte(1, m_version); }
83
84 /**
85 * @return human-readable description of this version
86 */
87 std::string to_string() const;
88
89 /**
90 * @return true iff this is a DTLS version
91 */
92 bool is_datagram_protocol() const;
93
94 /**
95 * @return true if this version supports negotiable signature algorithms
96 */
97 bool supports_negotiable_signature_algorithms() const;
98
99 /**
100 * @return true if this version uses explicit IVs for block ciphers
101 */
102 bool supports_explicit_cbc_ivs() const;
103
104 /**
105 * @return true if this version uses a ciphersuite specific PRF
106 */
107 bool supports_ciphersuite_specific_prf() const;
108
109 bool supports_aead_modes() const;
110
111 /**
112 * @return if this version is equal to other
113 */
114 bool operator==(const Protocol_Version& other) const
115 {
116 return (m_version == other.m_version);
117 }
118
119 /**
120 * @return if this version is not equal to other
121 */
122 bool operator!=(const Protocol_Version& other) const
123 {
124 return (m_version != other.m_version);
125 }
126
127 /**
128 * @return if this version is later than other
129 */
130 bool operator>(const Protocol_Version& other) const;
131
132 /**
133 * @return if this version is later than or equal to other
134 */
135 bool operator>=(const Protocol_Version& other) const
136 {
137 return (*this == other || *this > other);
138 }
139
140 private:
141 uint16_t m_version;
142 };
143
144 }
145
146 }
147
148 #endif
149
Botan::TLS::Protocol_Version::minor_version
uint8_t minor_version() const
Definition: tls_version.h:82
Botan::TLS::Protocol_Version::valid
bool valid() const
Definition: tls_version.h:67
Botan::operator>
bool operator>(const X509_Time &t1, const X509_Time &t2)
Definition: asn1_time.cpp:273
Botan::TLS::Protocol_Version::latest_dtls_version
static Protocol_Version latest_dtls_version()
Definition: tls_version.h:44
Botan::TLS::Protocol_Version::operator==
bool operator==(const Protocol_Version &other) const
Definition: tls_version.h:114
Botan::TLS::Protocol_Version::Protocol_Version
Protocol_Version(Version_Code named_version)
Definition: tls_version.h:54
Botan::TLS::Protocol_Version::latest_tls_version
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36
Botan::TLS::Protocol_Version
Definition: tls_version.h:21
Botan::TLS::Protocol_Version::major_version
uint8_t major_version() const
Definition: tls_version.h:77
Botan::TLS::Protocol_Version::operator!=
bool operator!=(const Protocol_Version &other) const
Definition: tls_version.h:122
Botan::TLS::Protocol_Version::Version_Code
Version_Code
Definition: tls_version.h:24
Botan
Definition: alg_id.cpp:13
Botan::TLS::Protocol_Version::Protocol_Version
Protocol_Version(uint8_t major, uint8_t minor)
Definition: tls_version.h:61
Botan::TLS::Protocol_Version::Protocol_Version
Protocol_Version()
Definition: tls_version.h:49
Botan::to_string
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
Botan::TLS::Protocol_Version::operator>=
bool operator>=(const Protocol_Version &other) const
Definition: tls_version.h:135
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47