Botan  2.6.0
Crypto and TLS for C++11
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 */
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  */
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  /**
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>((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 
static Protocol_Version latest_dtls_version()
Definition: tls_version.h:44
bool operator==(const Protocol_Version &other) const
Definition: tls_version.h:114
uint8_t minor_version() const
Definition: tls_version.h:82
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Protocol_Version(Version_Code named_version)
Definition: tls_version.h:54
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36
bool operator!=(const Protocol_Version &other) const
Definition: tls_version.h:122
Definition: alg_id.cpp:13
Protocol_Version(uint8_t major, uint8_t minor)
Definition: tls_version.h:61
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
uint8_t major_version() const
Definition: tls_version.h:77
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39
bool operator>(const X509_Time &t1, const X509_Time &t2)
Definition: asn1_time.cpp:271
bool operator>=(const Protocol_Version &other) const
Definition: tls_version.h:135