@@ -138,6 +138,35 @@ pub const AlertLevel = enum(u8) {
138
138
};
139
139
140
140
pub const AlertDescription = enum (u8 ) {
141
+ pub const Error = error {
142
+ TlsAlertUnexpectedMessage ,
143
+ TlsAlertBadRecordMac ,
144
+ TlsAlertRecordOverflow ,
145
+ TlsAlertHandshakeFailure ,
146
+ TlsAlertBadCertificate ,
147
+ TlsAlertUnsupportedCertificate ,
148
+ TlsAlertCertificateRevoked ,
149
+ TlsAlertCertificateExpired ,
150
+ TlsAlertCertificateUnknown ,
151
+ TlsAlertIllegalParameter ,
152
+ TlsAlertUnknownCa ,
153
+ TlsAlertAccessDenied ,
154
+ TlsAlertDecodeError ,
155
+ TlsAlertDecryptError ,
156
+ TlsAlertProtocolVersion ,
157
+ TlsAlertInsufficientSecurity ,
158
+ TlsAlertInternalError ,
159
+ TlsAlertInappropriateFallback ,
160
+ TlsAlertMissingExtension ,
161
+ TlsAlertUnsupportedExtension ,
162
+ TlsAlertUnrecognizedName ,
163
+ TlsAlertBadCertificateStatusResponse ,
164
+ TlsAlertUnknownPskIdentity ,
165
+ TlsAlertCertificateRequired ,
166
+ TlsAlertNoApplicationProtocol ,
167
+ TlsAlertUnknown ,
168
+ };
169
+
141
170
close_notify = 0 ,
142
171
unexpected_message = 10 ,
143
172
bad_record_mac = 20 ,
@@ -166,6 +195,39 @@ pub const AlertDescription = enum(u8) {
166
195
certificate_required = 116 ,
167
196
no_application_protocol = 120 ,
168
197
_ ,
198
+
199
+ pub fn toError (alert : AlertDescription ) Error ! void {
200
+ return switch (alert ) {
201
+ .close_notify = > {}, // not an error
202
+ .unexpected_message = > error .TlsAlertUnexpectedMessage ,
203
+ .bad_record_mac = > error .TlsAlertBadRecordMac ,
204
+ .record_overflow = > error .TlsAlertRecordOverflow ,
205
+ .handshake_failure = > error .TlsAlertHandshakeFailure ,
206
+ .bad_certificate = > error .TlsAlertBadCertificate ,
207
+ .unsupported_certificate = > error .TlsAlertUnsupportedCertificate ,
208
+ .certificate_revoked = > error .TlsAlertCertificateRevoked ,
209
+ .certificate_expired = > error .TlsAlertCertificateExpired ,
210
+ .certificate_unknown = > error .TlsAlertCertificateUnknown ,
211
+ .illegal_parameter = > error .TlsAlertIllegalParameter ,
212
+ .unknown_ca = > error .TlsAlertUnknownCa ,
213
+ .access_denied = > error .TlsAlertAccessDenied ,
214
+ .decode_error = > error .TlsAlertDecodeError ,
215
+ .decrypt_error = > error .TlsAlertDecryptError ,
216
+ .protocol_version = > error .TlsAlertProtocolVersion ,
217
+ .insufficient_security = > error .TlsAlertInsufficientSecurity ,
218
+ .internal_error = > error .TlsAlertInternalError ,
219
+ .inappropriate_fallback = > error .TlsAlertInappropriateFallback ,
220
+ .user_canceled = > {}, // not an error
221
+ .missing_extension = > error .TlsAlertMissingExtension ,
222
+ .unsupported_extension = > error .TlsAlertUnsupportedExtension ,
223
+ .unrecognized_name = > error .TlsAlertUnrecognizedName ,
224
+ .bad_certificate_status_response = > error .TlsAlertBadCertificateStatusResponse ,
225
+ .unknown_psk_identity = > error .TlsAlertUnknownPskIdentity ,
226
+ .certificate_required = > error .TlsAlertCertificateRequired ,
227
+ .no_application_protocol = > error .TlsAlertNoApplicationProtocol ,
228
+ _ = > error .TlsAlertUnknown ,
229
+ };
230
+ }
169
231
};
170
232
171
233
pub const SignatureScheme = enum (u16 ) {
0 commit comments