github.com/goproxy0/go@v0.0.0-20171111080102-49cc0c489d2c/src/crypto/tls/alert.go (about)

     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  
     5  package tls
     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  	alertEndOfEarlyData         alert = 1
    20  	alertUnexpectedMessage      alert = 10
    21  	alertBadRecordMAC           alert = 20
    22  	alertDecryptionFailed       alert = 21
    23  	alertRecordOverflow         alert = 22
    24  	alertDecompressionFailure   alert = 30
    25  	alertHandshakeFailure       alert = 40
    26  	alertBadCertificate         alert = 42
    27  	alertUnsupportedCertificate alert = 43
    28  	alertCertificateRevoked     alert = 44
    29  	alertCertificateExpired     alert = 45
    30  	alertCertificateUnknown     alert = 46
    31  	alertIllegalParameter       alert = 47
    32  	alertUnknownCA              alert = 48
    33  	alertAccessDenied           alert = 49
    34  	alertDecodeError            alert = 50
    35  	alertDecryptError           alert = 51
    36  	alertProtocolVersion        alert = 70
    37  	alertInsufficientSecurity   alert = 71
    38  	alertInternalError          alert = 80
    39  	alertInappropriateFallback  alert = 86
    40  	alertUserCanceled           alert = 90
    41  	alertNoRenegotiation        alert = 100
    42  	alertNoApplicationProtocol  alert = 120
    43  	alertSuccess                alert = 255 // dummy value returned by unmarshal functions
    44  )
    45  
    46  var alertText = map[alert]string{
    47  	alertCloseNotify:            "close notify",
    48  	alertUnexpectedMessage:      "unexpected message",
    49  	alertBadRecordMAC:           "bad record MAC",
    50  	alertDecryptionFailed:       "decryption failed",
    51  	alertRecordOverflow:         "record overflow",
    52  	alertDecompressionFailure:   "decompression failure",
    53  	alertHandshakeFailure:       "handshake failure",
    54  	alertBadCertificate:         "bad certificate",
    55  	alertUnsupportedCertificate: "unsupported certificate",
    56  	alertCertificateRevoked:     "revoked certificate",
    57  	alertCertificateExpired:     "expired certificate",
    58  	alertCertificateUnknown:     "unknown certificate",
    59  	alertIllegalParameter:       "illegal parameter",
    60  	alertUnknownCA:              "unknown certificate authority",
    61  	alertAccessDenied:           "access denied",
    62  	alertDecodeError:            "error decoding message",
    63  	alertDecryptError:           "error decrypting message",
    64  	alertProtocolVersion:        "protocol version not supported",
    65  	alertInsufficientSecurity:   "insufficient security level",
    66  	alertInternalError:          "internal error",
    67  	alertInappropriateFallback:  "inappropriate fallback",
    68  	alertUserCanceled:           "user canceled",
    69  	alertNoRenegotiation:        "no renegotiation",
    70  	alertNoApplicationProtocol:  "no application protocol",
    71  }
    72  
    73  func (e alert) String() string {
    74  	s, ok := alertText[e]
    75  	if ok {
    76  		return "tls: " + s
    77  	}
    78  	return "tls: alert(" + strconv.Itoa(int(e)) + ")"
    79  }
    80  
    81  func (e alert) Error() string {
    82  	return e.String()
    83  }