| 6 |
| 7 | import "strconv" |
| 8 |
| 9 | type alert uint8 |
| 10 |
| 11 | const ( |
| 12 | // alert level |
| 13 | alertLevelWarning = 1 |
| 14 | alertLevelError = 2 |
| 15 | ) |
| 16 |
| 17 | const ( |
| 18 | alertCloseNotify alert = 0 |
| 19 | alertUnexpectedMessage alert = 10 |
| 20 | alertBadRecordMAC alert = 20 |
| 21 | alertDecryptionFailed alert = 21 |
| 22 | alertRecordOverflow alert = 22 |
| 23 | alertDecompressionFailure alert = 30 |
| 24 | alertHandshakeFailure alert = 40 |
| 25 | alertBadCertificate alert = 42 |
| 26 | alertUnsupportedCertificate alert = 43 |
| 27 | alertCertificateRevoked alert = 44 |
| 28 | alertCertificateExpired alert = 45 |
| 29 | alertCertificateUnknown alert = 46 |
| 30 | alertIllegalParameter alert = 47 |
| 31 | alertUnknownCA alert = 48 |
| 32 | alertAccessDenied alert = 49 |
| 33 | alertDecodeError alert = 50 |
| 34 | alertDecryptError alert = 51 |
| 35 | alertProtocolVersion alert = 70 |
| 36 | alertInsufficientSecurity alert = 71 |
| 37 | alertInternalError alert = 80 |
| 38 | alertInappropriateFallback alert = 86 |
| 39 | alertUserCanceled alert = 90 |
| 40 | alertNoRenegotiation alert = 100 |
| 41 | alertMissingExtension alert = 109 |
| 42 | alertUnsupportedExtension alert = 110 |
| 43 | alertUnrecognizedName alert = 112 |
| 44 | alertBadCertificateStatusResponse alert = 113 |
| 45 | alertUnknownPSKIdentity alert = 115 |
| 46 | alertCertificateRequired alert = 116 |
| 47 | alertNoApplicationProtocol alert = 120 |
| 48 | alertECHRequired alert = 121 |
| 49 | ) |
| 50 |
| 51 | var alertText = map[alert]string{ |
| 52 | alertCloseNotify: "close notify", |
| 53 | alertUnexpectedMessage: "unexpected message", |
| 54 | alertBadRecordMAC: "bad record MAC", |
| 55 | alertDecryptionFailed: "decryption failed", |
| 56 | alertRecordOverflow: "record overflow", |
| 57 | alertDecompressionFailure: "decompression failure", |
| 58 | alertHandshakeFailure: "handshake failure", |
| 59 | alertBadCertificate: "bad certificate", |
| 60 | alertUnsupportedCertificate: "unsupported certificate", |
| 61 | alertCertificateRevoked: "revoked certificate", |
| 62 | alertCertificateExpired: "expired certificate", |
| 63 | alertCertificateUnknown: "unknown certificate", |
| 64 | alertIllegalParameter: "illegal parameter", |
| 65 | alertUnknownCA: "unknown certificate authority", |
| 66 | alertAccessDenied: "access denied", |
| 67 | alertDecodeError: "error decoding message", |
| 68 | alertDecryptError: "error decrypting message", |
| 69 | alertProtocolVersion: "protocol version not supported", |
| 70 | alertInsufficientSecurity: "insufficient security level", |
| 71 | alertInternalError: "internal error", |
| 72 | alertInappropriateFallback: "inappropriate fallback", |
| 73 | alertUserCanceled: "user canceled", |
| 74 | alertNoRenegotiation: "no renegotiation", |
| 75 | alertMissingExtension: "missing extension", |
| 76 | alertUnsupportedExtension: "unsupported extension", |
| 77 | alertBadCertificateStatusResponse: "bad certificate status response", |
| 78 | alertUnrecognizedName: "unrecognized name", |
| 79 | alertUnknownPSKIdentity: "unknown PSK identity", |
| 80 | alertCertificateRequired: "certificate required", |
| 81 | alertNoApplicationProtocol: "no application protocol", |
| 82 | alertECHRequired: "ECH required", |
| 83 | } |
| 84 |
| 85 | func (e alert) String() string { |
| 86 | s, ok := alertText[e] |
| 87 | if ok { |
| 88 | return s |
| 89 | } |
| 90 | return "alert(" + strconv.Itoa(int(e)) + ")" |
| 91 | } |
| 92 |
| 93 | func (e alert) Error() string { |
| 94 | return e.String() |
| 95 | } |
| 96 |