lib/quic/src/tls/alert.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 
 3 pub const Alert = enum(u8) {
 4     unexpected_message = 10,
 5     handshake_failure = 40,
 6     bad_certificate = 42,
 7     unsupported_certificate = 43,
 8     illegal_parameter = 47,
 9     decode_error = 50,
10     decrypt_error = 51,
11     protocol_version = 70,
12     internal_error = 80,
13     missing_extension = 109,
14     unsupported_extension = 110,
15     unrecognized_name = 112,
16     certificate_required = 116,
17     no_application_protocol = 120,
18 
19     /// Returns the QUIC transport error code for one TLS alert. A connection closing after a
20     /// handshake failure calls it to get the code it puts in the CONNECTION_CLOSE frame. RFC 9001
21     /// section 4.8 forms the code by adding the alert number to 0x0100. Distinct alerts give
22     /// distinct codes, so the peer learns which check failed.
23     pub fn quicError(self: Alert) u16 {
24         return 0x0100 + @as(u16, @backingInt(self));
25     }
26 };
27 
28 test "RFC 9001 section 4.8 maps TLS alerts into QUIC errors" {
29     try std.testing.expectEqual(@as(u16, 0x012a), Alert.bad_certificate.quicError());
30     try std.testing.expectEqual(@as(u16, 0x0178), Alert.no_application_protocol.quicError());
31 }