1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package qtls
6
7import "strconv"
8
9type alert uint8
10
11// Alert is a TLS alert
12type Alert = alert
13
14const (
15	// alert level
16	alertLevelWarning = 1
17	alertLevelError   = 2
18)
19
20const (
21	alertCloseNotify                  alert = 0
22	alertUnexpectedMessage            alert = 10
23	alertBadRecordMAC                 alert = 20
24	alertDecryptionFailed             alert = 21
25	alertRecordOverflow               alert = 22
26	alertDecompressionFailure         alert = 30
27	alertHandshakeFailure             alert = 40
28	alertBadCertificate               alert = 42
29	alertUnsupportedCertificate       alert = 43
30	alertCertificateRevoked           alert = 44
31	alertCertificateExpired           alert = 45
32	alertCertificateUnknown           alert = 46
33	alertIllegalParameter             alert = 47
34	alertUnknownCA                    alert = 48
35	alertAccessDenied                 alert = 49
36	alertDecodeError                  alert = 50
37	alertDecryptError                 alert = 51
38	alertExportRestriction            alert = 60
39	alertProtocolVersion              alert = 70
40	alertInsufficientSecurity         alert = 71
41	alertInternalError                alert = 80
42	alertInappropriateFallback        alert = 86
43	alertUserCanceled                 alert = 90
44	alertNoRenegotiation              alert = 100
45	alertMissingExtension             alert = 109
46	alertUnsupportedExtension         alert = 110
47	alertCertificateUnobtainable      alert = 111
48	alertUnrecognizedName             alert = 112
49	alertBadCertificateStatusResponse alert = 113
50	alertBadCertificateHashValue      alert = 114
51	alertUnknownPSKIdentity           alert = 115
52	alertCertificateRequired          alert = 116
53	alertNoApplicationProtocol        alert = 120
54)
55
56var alertText = map[alert]string{
57	alertCloseNotify:                  "close notify",
58	alertUnexpectedMessage:            "unexpected message",
59	alertBadRecordMAC:                 "bad record MAC",
60	alertDecryptionFailed:             "decryption failed",
61	alertRecordOverflow:               "record overflow",
62	alertDecompressionFailure:         "decompression failure",
63	alertHandshakeFailure:             "handshake failure",
64	alertBadCertificate:               "bad certificate",
65	alertUnsupportedCertificate:       "unsupported certificate",
66	alertCertificateRevoked:           "revoked certificate",
67	alertCertificateExpired:           "expired certificate",
68	alertCertificateUnknown:           "unknown certificate",
69	alertIllegalParameter:             "illegal parameter",
70	alertUnknownCA:                    "unknown certificate authority",
71	alertAccessDenied:                 "access denied",
72	alertDecodeError:                  "error decoding message",
73	alertDecryptError:                 "error decrypting message",
74	alertExportRestriction:            "export restriction",
75	alertProtocolVersion:              "protocol version not supported",
76	alertInsufficientSecurity:         "insufficient security level",
77	alertInternalError:                "internal error",
78	alertInappropriateFallback:        "inappropriate fallback",
79	alertUserCanceled:                 "user canceled",
80	alertNoRenegotiation:              "no renegotiation",
81	alertMissingExtension:             "missing extension",
82	alertUnsupportedExtension:         "unsupported extension",
83	alertCertificateUnobtainable:      "certificate unobtainable",
84	alertUnrecognizedName:             "unrecognized name",
85	alertBadCertificateStatusResponse: "bad certificate status response",
86	alertBadCertificateHashValue:      "bad certificate hash value",
87	alertUnknownPSKIdentity:           "unknown PSK identity",
88	alertCertificateRequired:          "certificate required",
89	alertNoApplicationProtocol:        "no application protocol",
90}
91
92func (e alert) String() string {
93	s, ok := alertText[e]
94	if ok {
95		return "tls: " + s
96	}
97	return "tls: alert(" + strconv.Itoa(int(e)) + ")"
98}
99
100func (e alert) Error() string {
101	return e.String()
102}
103