Coverage Report

Created: 2020-11-21 08:34

/src/botan/build/include/botan/tls_version.h
Line
Count
Source (jump to first uncovered line)
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
14
namespace Botan {
15
16
namespace TLS {
17
18
/**
19
* TLS Protocol Version
20
*/
21
class BOTAN_PUBLIC_API(2,0) Protocol_Version final
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
0
         {
38
0
         return Protocol_Version(TLS_V12);
39
0
         }
40
41
      /**
42
      * @return latest known DTLS version
43
      */
44
      static Protocol_Version latest_dtls_version()
45
0
         {
46
0
         return Protocol_Version(DTLS_V12);
47
0
         }
48
49
105k
      Protocol_Version() : m_version(0) {}
50
51
491k
      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) :
57
307k
         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
179k
         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
32.6k
      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
841k
      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
161k
      uint8_t minor_version() const { return static_cast<uint8_t>(m_version & 0xFF); }
85
86
      /**
87
      * @return the version code
88
      */
89
0
      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
164k
         {
123
164k
         return (m_version == other.m_version);
124
164k
         }
125
126
      /**
127
      * @return if this version is not equal to other
128
      */
129
      bool operator!=(const Protocol_Version& other) const
130
10.4k
         {
131
10.4k
         return (m_version != other.m_version);
132
10.4k
         }
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
18.0k
         {
144
18.0k
         return (*this == other || *this > other);
145
18.0k
         }
146
147
   private:
148
      uint16_t m_version;
149
   };
150
151
}
152
153
}
154
155
#endif
156