Botan 3.11.0
Crypto and TLS for C&
tls_alert.h
Go to the documentation of this file.
1/*
2* Alert Message
3* (C) 2004-2006,2011,2012 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_TLS_ALERT_H_
9#define BOTAN_TLS_ALERT_H_
10
11#include <botan/secmem.h>
12#include <string>
13
14namespace Botan::TLS {
15
16/**
17* Type codes for TLS alerts
18*
19* The enumeration value matches the wire encoding
20*/
66
67/**
68* SSL/TLS Alert Message
69*/
70class BOTAN_PUBLIC_API(2, 0) Alert final {
71 public:
72 typedef AlertType Type;
73 using enum AlertType;
74
75 /**
76 * @return true iff this alert is non-empty
77 */
78 bool is_valid() const { return (m_type_code != AlertType::None); }
79
80 /**
81 * Return true if this alert is fatal. A fatal alert causes the connection
82 * to be immediately disconnected. Otherwise, the alert is a warning and
83 * the connection remains valid.
84 *
85 * Note:
86 * RFC 8446 6.
87 * In TLS 1.3, the severity is implicit in the type of alert being sent,
88 * and the "level" field can safely be ignored.
89 * Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)
90 *
91 * @return if this alert is fatal or not
92 */
93 bool is_fatal() const { return m_fatal; }
94
95 /**
96 * Returns the type of the alert as an enum
97 *
98 * @return type of alert
99 */
100 Type type() const { return m_type_code; }
101
102 /**
103 * Returns the type of the alert as a string
104 *
105 * @return type of alert
106 */
107 std::string type_string() const;
108
109 /**
110 * Serialize an alert
111 */
112 std::vector<uint8_t> serialize() const;
113
114 /**
115 * Deserialize an Alert message
116 * @param buf the serialized alert
117 */
118 explicit Alert(const secure_vector<uint8_t>& buf);
119
120 /**
121 * Create a new Alert
122 * @param type_code the type of alert
123 * @param fatal specifies if this is a fatal alert
124 */
125 Alert(Type type_code, bool fatal = false) : // NOLINT(*-explicit-conversions)
126 m_fatal(fatal), m_type_code(type_code) {}
127
128 Alert() : m_fatal(false), m_type_code(AlertType::None) {}
129
130 private:
131 bool m_fatal;
132 Type m_type_code;
133};
134
135} // namespace Botan::TLS
136
137#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
bool is_valid() const
Definition tls_alert.h:78
AlertType Type
Definition tls_alert.h:72
Alert(Type type_code, bool fatal=false)
Definition tls_alert.h:125
Alert(const secure_vector< uint8_t > &buf)
Definition tls_alert.cpp:14
bool is_fatal() const
Definition tls_alert.h:93
Type type() const
Definition tls_alert.h:100
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68