3
* (C) 2004-2006,2011 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/tls_alert.h>
9
#include <botan/exceptn.h>
15
Alert::Alert(const secure_vector<uint8_t>& buf)
18
throw Decoding_Error("Alert: Bad size " + std::to_string(buf.size()) +
19
" for alert message");
21
if(buf[0] == 1) m_fatal = false;
22
else if(buf[0] == 2) m_fatal = true;
24
throw Decoding_Error("Alert: Bad code for alert level");
26
const uint8_t dc = buf[1];
28
m_type_code = static_cast<Type>(dc);
31
std::vector<uint8_t> Alert::serialize() const
33
return std::vector<uint8_t>({
34
static_cast<uint8_t>(is_fatal() ? 2 : 1),
35
static_cast<uint8_t>(type())
39
std::string Alert::type_string() const
44
return "close_notify";
45
case UNEXPECTED_MESSAGE:
46
return "unexpected_message";
48
return "bad_record_mac";
49
case DECRYPTION_FAILED:
50
return "decryption_failed";
52
return "record_overflow";
53
case DECOMPRESSION_FAILURE:
54
return "decompression_failure";
55
case HANDSHAKE_FAILURE:
56
return "handshake_failure";
58
return "no_certificate";
60
return "bad_certificate";
61
case UNSUPPORTED_CERTIFICATE:
62
return "unsupported_certificate";
63
case CERTIFICATE_REVOKED:
64
return "certificate_revoked";
65
case CERTIFICATE_EXPIRED:
66
return "certificate_expired";
67
case CERTIFICATE_UNKNOWN:
68
return "certificate_unknown";
69
case ILLEGAL_PARAMETER:
70
return "illegal_parameter";
74
return "access_denied";
76
return "decode_error";
78
return "decrypt_error";
79
case EXPORT_RESTRICTION:
80
return "export_restriction";
81
case PROTOCOL_VERSION:
82
return "protocol_version";
83
case INSUFFICIENT_SECURITY:
84
return "insufficient_security";
86
return "internal_error";
87
case INAPPROPRIATE_FALLBACK:
88
return "inappropriate_fallback";
90
return "user_canceled";
91
case NO_RENEGOTIATION:
92
return "no_renegotiation";
94
case UNSUPPORTED_EXTENSION:
95
return "unsupported_extension";
96
case CERTIFICATE_UNOBTAINABLE:
97
return "certificate_unobtainable";
98
case UNRECOGNIZED_NAME:
99
return "unrecognized_name";
100
case BAD_CERTIFICATE_STATUS_RESPONSE:
101
return "bad_certificate_status_response";
102
case BAD_CERTIFICATE_HASH_VALUE:
103
return "bad_certificate_hash_value";
104
case UNKNOWN_PSK_IDENTITY:
105
return "unknown_psk_identity";
106
case NO_APPLICATION_PROTOCOL:
107
return "no_application_protocol";
114
* This is effectively the default case for the switch above, but we
115
* leave it out so that when an alert type is added to the enum the
116
* compiler can warn us that it is not included in the switch
119
return "unrecognized_alert_" + std::to_string(type());