Coverage Report

Created: 2023-02-13 06:21

/src/botan/build/include/botan/tls_server_info.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* TLS Server Information
3
* (C) 2012 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_TLS_SERVER_INFO_H_
9
#define BOTAN_TLS_SERVER_INFO_H_
10
11
#include <botan/types.h>
12
#include <string>
13
14
namespace Botan {
15
16
namespace TLS {
17
18
/**
19
* Represents information known about a TLS server.
20
*/
21
class BOTAN_PUBLIC_API(2,0) Server_Information final
22
   {
23
   public:
24
      /**
25
      * An empty server info - nothing known
26
      */
27
22.8k
      Server_Information() : m_hostname(""), m_service(""), m_port(0) {}
28
29
      /**
30
      * @param hostname the host's DNS name, if known
31
      * @param port specifies the protocol port of the server (eg for
32
      *        TCP/UDP). Zero represents unknown.
33
      */
34
      Server_Information(const std::string& hostname,
35
                        uint16_t port = 0) :
36
8.80k
         m_hostname(hostname), m_service(""), m_port(port) {}
37
38
      /**
39
      * @param hostname the host's DNS name, if known
40
      * @param service is a text string of the service type
41
      *        (eg "https", "tor", or "git")
42
      * @param port specifies the protocol port of the server (eg for
43
      *        TCP/UDP). Zero represents unknown.
44
      */
45
      Server_Information(const std::string& hostname,
46
                        const std::string& service,
47
                        uint16_t port = 0) :
48
0
         m_hostname(hostname), m_service(service), m_port(port) {}
49
50
      /**
51
      * @return the host's DNS name, if known
52
      */
53
2.60k
      std::string hostname() const { return m_hostname; }
54
55
      /**
56
      * @return text string of the service type, e.g.,
57
      * "https", "tor", or "git"
58
      */
59
173
      std::string service() const { return m_service; }
60
61
      /**
62
      * @return the protocol port of the server, or zero if unknown
63
      */
64
173
      uint16_t port() const { return m_port; }
65
66
      /**
67
      * @return whether the hostname is known
68
      */
69
2.42k
      bool empty() const { return m_hostname.empty(); }
70
71
   private:
72
      std::string m_hostname, m_service;
73
      uint16_t m_port;
74
   };
75
76
inline bool operator==(const Server_Information& a, const Server_Information& b)
77
0
   {
78
0
   return (a.hostname() == b.hostname()) &&
79
0
          (a.service() == b.service()) &&
80
0
          (a.port() == b.port());
81
0
82
0
   }
83
84
inline bool operator!=(const Server_Information& a, const Server_Information& b)
85
0
   {
86
0
   return !(a == b);
87
0
   }
88
89
inline bool operator<(const Server_Information& a, const Server_Information& b)
90
0
   {
91
0
   if(a.hostname() != b.hostname())
92
0
      return (a.hostname() < b.hostname());
93
0
   if(a.service() != b.service())
94
0
      return (a.service() < b.service());
95
0
   if(a.port() != b.port())
96
0
      return (a.port() < b.port());
97
0
   return false; // equal
98
0
   }
99
100
}
101
102
}
103
104
#endif