Botan 3.6.1
Crypto and TLS for C&
Botan::TLS::Alert Class Referencefinal

#include <tls_alert.h>

Public Types

typedef AlertType Type
 

Public Member Functions

 Alert ()
 
 Alert (const secure_vector< uint8_t > &buf)
 
 Alert (Type type_code, bool fatal=false)
 
bool is_fatal () const
 
bool is_valid () const
 
std::vector< uint8_t > serialize () const
 
Type type () const
 
std::string type_string () const
 

Detailed Description

SSL/TLS Alert Message

Definition at line 69 of file tls_alert.h.

Member Typedef Documentation

◆ Type

Definition at line 71 of file tls_alert.h.

Constructor & Destructor Documentation

◆ Alert() [1/3]

Botan::TLS::Alert::Alert ( const secure_vector< uint8_t > & buf)
explicit

Deserialize an Alert message

Parameters
bufthe serialized alert

Definition at line 14 of file tls_alert.cpp.

14 {
15 if(buf.size() != 2) {
16 throw Decoding_Error("Bad size (" + std::to_string(buf.size()) + ") for TLS alert message");
17 }
18
19 if(buf[0] == 1) {
20 m_fatal = false;
21 } else if(buf[0] == 2) {
22 m_fatal = true;
23 } else {
24 throw TLS_Exception(Alert::IllegalParameter, "Bad code for TLS alert level");
25 }
26
27 const uint8_t dc = buf[1];
28
29 m_type_code = static_cast<Type>(dc);
30}
AlertType Type
Definition tls_alert.h:71

◆ Alert() [2/3]

Botan::TLS::Alert::Alert ( Type type_code,
bool fatal = false )
inline

Create a new Alert

Parameters
type_codethe type of alert
fatalspecifies if this is a fatal alert

Definition at line 124 of file tls_alert.h.

124: m_fatal(fatal), m_type_code(type_code) {}

◆ Alert() [3/3]

Botan::TLS::Alert::Alert ( )
inline

Definition at line 126 of file tls_alert.h.

126: m_fatal(false), m_type_code(AlertType::None) {}

Member Function Documentation

◆ is_fatal()

bool Botan::TLS::Alert::is_fatal ( ) const
inline

Return true if this alert is fatal. A fatal alert causes the connection to be immediately disconnected. Otherwise, the alert is a warning and the connection remains valid.

Note: RFC 8446 6. In TLS 1.3, the severity is implicit in the type of alert being sent, and the "level" field can safely be ignored. Everything is considered fatal except for UserCanceled and CloseNotify (RFC 8446 6.1)

Returns
if this alert is fatal or not

Definition at line 92 of file tls_alert.h.

92{ return m_fatal; }

Referenced by Botan::TLS::Channel_Impl_12::send_alert(), and serialize().

◆ is_valid()

bool Botan::TLS::Alert::is_valid ( ) const
inline
Returns
true iff this alert is non-empty

Definition at line 77 of file tls_alert.h.

77{ return (m_type_code != AlertType::None); }

Referenced by Botan::TLS::Channel_Impl_12::send_alert(), and Botan::TLS::Channel_Impl_13::send_alert().

◆ serialize()

std::vector< uint8_t > Botan::TLS::Alert::serialize ( ) const

Serialize an alert

Definition at line 32 of file tls_alert.cpp.

32 {
33 return std::vector<uint8_t>({static_cast<uint8_t>(is_fatal() ? 2 : 1), static_cast<uint8_t>(type())});
34}
bool is_fatal() const
Definition tls_alert.h:92
Type type() const
Definition tls_alert.h:99

References is_fatal(), and type().

Referenced by Botan::TLS::Channel_Impl_12::send_alert(), and Botan::TLS::Channel_Impl_13::send_alert().

◆ type()

Type Botan::TLS::Alert::type ( ) const
inline

Returns the type of the alert as an enum

Returns
type of alert

Definition at line 99 of file tls_alert.h.

99{ return m_type_code; }

Referenced by Botan::TLS::Channel_Impl_12::send_alert(), serialize(), and type_string().

◆ type_string()

std::string Botan::TLS::Alert::type_string ( ) const

Returns the type of the alert as a string

Returns
type of alert

Definition at line 118 of file tls_alert.cpp.

118 {
119 if(const char* known_alert = alert_type_to_string(type())) {
120 return std::string(known_alert);
121 }
122
123 return "unrecognized_alert_" + std::to_string(static_cast<size_t>(type()));
124}

References type().


The documentation for this class was generated from the following files: