Botan 3.7.1
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*/
65
66/**
67* SSL/TLS Alert Message
68*/
69class BOTAN_PUBLIC_API(2, 0) Alert final {
70 public:
71 typedef AlertType Type;
72 using enum AlertType;
73
74 /**
75 * @return true iff this alert is non-empty
76 */
77 bool is_valid() const { return (m_type_code != AlertType::None); }
78
79 /**
80 * Return true if this alert is fatal. A fatal alert causes the connection
81 * to be immediately disconnected. Otherwise, the alert is a warning and
82 * the connection remains valid.
83 *
84 * Note:
85 * RFC 8446 6.
86 * In TLS 1.3, the severity is implicit in the type of alert being sent,
87 * and the "level" field can safely be ignored.
88 * Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)
89 *
90 * @return if this alert is fatal or not
91 */
92 bool is_fatal() const { return m_fatal; }
93
94 /**
95 * Returns the type of the alert as an enum
96 *
97 * @return type of alert
98 */
99 Type type() const { return m_type_code; }
100
101 /**
102 * Returns the type of the alert as a string
103 *
104 * @return type of alert
105 */
106 std::string type_string() const;
107
108 /**
109 * Serialize an alert
110 */
111 std::vector<uint8_t> serialize() const;
112
113 /**
114 * Deserialize an Alert message
115 * @param buf the serialized alert
116 */
117 explicit Alert(const secure_vector<uint8_t>& buf);
118
119 /**
120 * Create a new Alert
121 * @param type_code the type of alert
122 * @param fatal specifies if this is a fatal alert
123 */
124 Alert(Type type_code, bool fatal = false) : m_fatal(fatal), m_type_code(type_code) {}
125
126 Alert() : m_fatal(false), m_type_code(AlertType::None) {}
127
128 private:
129 bool m_fatal;
130 Type m_type_code;
131};
132
133} // namespace Botan::TLS
134
135#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
#define BOTAN_DEPRECATED(msg)
Definition api.h:59
bool is_valid() const
Definition tls_alert.h:77
AlertType Type
Definition tls_alert.h:71
Alert(Type type_code, bool fatal=false)
Definition tls_alert.h:124
Alert(const secure_vector< uint8_t > &buf)
Definition tls_alert.cpp:14
bool is_fatal() const
Definition tls_alert.h:92
Type type() const
Definition tls_alert.h:99
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61