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