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	alertProtocolVersion        alert = 70
39	alertInsufficientSecurity   alert = 71
40	alertInternalError          alert = 80
41	alertInappropriateFallback  alert = 86
42	alertUserCanceled           alert = 90
43	alertNoRenegotiation        alert = 100
44	alertMissingExtension       alert = 109
45	alertUnsupportedExtension   alert = 110
46	alertUnrecognizedName       alert = 112
47	alertNoApplicationProtocol  alert = 120
48)
49
50var alertText = map[alert]string{
51	alertCloseNotify:            "close notify",
52	alertUnexpectedMessage:      "unexpected message",
53	alertBadRecordMAC:           "bad record MAC",
54	alertDecryptionFailed:       "decryption failed",
55	alertRecordOverflow:         "record overflow",
56	alertDecompressionFailure:   "decompression failure",
57	alertHandshakeFailure:       "handshake failure",
58	alertBadCertificate:         "bad certificate",
59	alertUnsupportedCertificate: "unsupported certificate",
60	alertCertificateRevoked:     "revoked certificate",
61	alertCertificateExpired:     "expired certificate",
62	alertCertificateUnknown:     "unknown certificate",
63	alertIllegalParameter:       "illegal parameter",
64	alertUnknownCA:              "unknown certificate authority",
65	alertAccessDenied:           "access denied",
66	alertDecodeError:            "error decoding message",
67	alertDecryptError:           "error decrypting message",
68	alertProtocolVersion:        "protocol version not supported",
69	alertInsufficientSecurity:   "insufficient security level",
70	alertInternalError:          "internal error",
71	alertInappropriateFallback:  "inappropriate fallback",
72	alertUserCanceled:           "user canceled",
73	alertNoRenegotiation:        "no renegotiation",
74	alertMissingExtension:       "missing extension",
75	alertUnsupportedExtension:   "unsupported extension",
76	alertUnrecognizedName:       "unrecognized name",
77	alertNoApplicationProtocol:  "no application protocol",
78}
79
80func (e alert) String() string {
81	s, ok := alertText[e]
82	if ok {
83		return "tls: " + s
84	}
85	return "tls: alert(" + strconv.Itoa(int(e)) + ")"
86}
87
88func (e alert) Error() string {
89	return e.String()
90}
91