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