Coverage Report

Created: 2021-05-04 09:02

/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_V12            = 0x0303,
26
         DTLS_V12           = 0xFEFD
27
      };
28
29
      /**
30
      * @return latest known TLS version
31
      */
32
      static Protocol_Version latest_tls_version()
33
0
         {
34
0
         return Protocol_Version(TLS_V12);
35
0
         }
36
37
      /**
38
      * @return latest known DTLS version
39
      */
40
      static Protocol_Version latest_dtls_version()
41
0
         {
42
0
         return Protocol_Version(DTLS_V12);
43
0
         }
44
45
95.7k
      Protocol_Version() : m_version(0) {}
46
47
392k
      explicit Protocol_Version(uint16_t code) : m_version(code) {}
48
49
      /**
50
      * @param named_version a specific named version of the protocol
51
      */
52
      Protocol_Version(Version_Code named_version) :
53
186k
         Protocol_Version(static_cast<uint16_t>(named_version)) {}
54
55
      /**
56
      * @param major the major version
57
      * @param minor the minor version
58
      */
59
      Protocol_Version(uint8_t major, uint8_t minor) :
60
198k
         Protocol_Version(static_cast<uint16_t>((static_cast<uint16_t>(major) << 8) | minor)) {}
61
62
      /**
63
      * @return true if this is a valid protocol version
64
      */
65
33.4k
      bool valid() const { return (m_version != 0); }
66
67
      /**
68
      * @return true if this is a protocol version we know about
69
      */
70
      bool known_version() const;
71
72
      /**
73
      * @return major version of the protocol version
74
      */
75
701k
      uint8_t major_version() const { return static_cast<uint8_t>(m_version >> 8); }
76
77
      /**
78
      * @return minor version of the protocol version
79
      */
80
124k
      uint8_t minor_version() const { return static_cast<uint8_t>(m_version & 0xFF); }
81
82
      /**
83
      * @return the version code
84
      */
85
0
      uint16_t version_code() const { return m_version; }
86
87
      /**
88
      * @return human-readable description of this version
89
      */
90
      std::string to_string() const;
91
92
      /**
93
      * @return true iff this is a DTLS version
94
      */
95
      bool is_datagram_protocol() const;
96
97
      /**
98
      * @return if this version is equal to other
99
      */
100
      bool operator==(const Protocol_Version& other) const
101
70.6k
         {
102
70.6k
         return (m_version == other.m_version);
103
70.6k
         }
104
105
      /**
106
      * @return if this version is not equal to other
107
      */
108
      bool operator!=(const Protocol_Version& other) const
109
11.6k
         {
110
11.6k
         return (m_version != other.m_version);
111
11.6k
         }
112
113
      /**
114
      * @return if this version is later than other
115
      */
116
      bool operator>(const Protocol_Version& other) const;
117
118
      /**
119
      * @return if this version is later than or equal to other
120
      */
121
      bool operator>=(const Protocol_Version& other) const
122
2.05k
         {
123
2.05k
         return (*this == other || *this > other);
124
2.05k
         }
125
126
   private:
127
      uint16_t m_version;
128
   };
129
130
}
131
132
}
133
134
#endif
135