Botan 3.6.1
Crypto and TLS for C&
tls_server_info.h
Go to the documentation of this file.
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
14namespace Botan::TLS {
15
16/**
17* Represents information known about a TLS server.
18*/
20 public:
21 /**
22 * An empty server info - nothing known
23 */
24 Server_Information() : m_hostname(), m_service(), m_port(0) {}
25
26 /**
27 * @param hostname the host's DNS name, if known
28 * @param port specifies the protocol port of the server (eg for
29 * TCP/UDP). Zero represents unknown.
30 */
31 Server_Information(std::string_view hostname, uint16_t port = 0) :
32 m_hostname(hostname), m_service(), m_port(port) {}
33
34 /**
35 * @param hostname the host's DNS name, if known
36 * @param service is a text string of the service type
37 * (eg "https", "tor", or "git")
38 * @param port specifies the protocol port of the server (eg for
39 * TCP/UDP). Zero represents unknown.
40 */
41 Server_Information(std::string_view hostname, std::string_view service, uint16_t port = 0) :
42 m_hostname(hostname), m_service(service), m_port(port) {}
43
44 /**
45 * @return the host's DNS name, if known
46 */
47 std::string hostname() const { return m_hostname; }
48
49 /**
50 * @return text string of the service type, e.g.,
51 * "https", "tor", or "git"
52 */
53 std::string service() const { return m_service; }
54
55 /**
56 * @return the protocol port of the server, or zero if unknown
57 */
58 uint16_t port() const { return m_port; }
59
60 /**
61 * @return whether the hostname is known
62 */
63 bool empty() const { return m_hostname.empty(); }
64
65 private:
66 std::string m_hostname, m_service;
67 uint16_t m_port;
68};
69
70inline bool operator==(const Server_Information& a, const Server_Information& b) {
71 return (a.hostname() == b.hostname()) && (a.service() == b.service()) && (a.port() == b.port());
72}
73
74inline bool operator!=(const Server_Information& a, const Server_Information& b) {
75 return !(a == b);
76}
77
78inline bool operator<(const Server_Information& a, const Server_Information& b) {
79 if(a.hostname() != b.hostname()) {
80 return (a.hostname() < b.hostname());
81 }
82 if(a.service() != b.service()) {
83 return (a.service() < b.service());
84 }
85 if(a.port() != b.port()) {
86 return (a.port() < b.port());
87 }
88 return false; // equal
89}
90
91} // namespace Botan::TLS
92
93#endif
Server_Information(std::string_view hostname, std::string_view service, uint16_t port=0)
Server_Information(std::string_view hostname, uint16_t port=0)
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
bool operator==(const Server_Information &a, const Server_Information &b)
bool operator<(const Server_Information &a, const Server_Information &b)
bool operator!=(const Server_Information &a, const Server_Information &b)
const SIMD_8x32 & b