alert.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. package mint
  5. import "strconv"
  6. type Alert uint8
  7. const (
  8. // alert level
  9. AlertLevelWarning = 1
  10. AlertLevelError = 2
  11. )
  12. const (
  13. AlertCloseNotify Alert = 0
  14. AlertUnexpectedMessage Alert = 10
  15. AlertBadRecordMAC Alert = 20
  16. AlertDecryptionFailed Alert = 21
  17. AlertRecordOverflow Alert = 22
  18. AlertDecompressionFailure Alert = 30
  19. AlertHandshakeFailure Alert = 40
  20. AlertBadCertificate Alert = 42
  21. AlertUnsupportedCertificate Alert = 43
  22. AlertCertificateRevoked Alert = 44
  23. AlertCertificateExpired Alert = 45
  24. AlertCertificateUnknown Alert = 46
  25. AlertIllegalParameter Alert = 47
  26. AlertUnknownCA Alert = 48
  27. AlertAccessDenied Alert = 49
  28. AlertDecodeError Alert = 50
  29. AlertDecryptError Alert = 51
  30. AlertProtocolVersion Alert = 70
  31. AlertInsufficientSecurity Alert = 71
  32. AlertInternalError Alert = 80
  33. AlertInappropriateFallback Alert = 86
  34. AlertUserCanceled Alert = 90
  35. AlertNoRenegotiation Alert = 100
  36. AlertMissingExtension Alert = 109
  37. AlertUnsupportedExtension Alert = 110
  38. AlertCertificateUnobtainable Alert = 111
  39. AlertUnrecognizedName Alert = 112
  40. AlertBadCertificateStatsResponse Alert = 113
  41. AlertBadCertificateHashValue Alert = 114
  42. AlertUnknownPSKIdentity Alert = 115
  43. AlertNoApplicationProtocol Alert = 120
  44. AlertStatelessRetry Alert = 253
  45. AlertWouldBlock Alert = 254
  46. AlertNoAlert Alert = 255
  47. )
  48. var alertText = map[Alert]string{
  49. AlertCloseNotify: "close notify",
  50. AlertUnexpectedMessage: "unexpected message",
  51. AlertBadRecordMAC: "bad record MAC",
  52. AlertDecryptionFailed: "decryption failed",
  53. AlertRecordOverflow: "record overflow",
  54. AlertDecompressionFailure: "decompression failure",
  55. AlertHandshakeFailure: "handshake failure",
  56. AlertBadCertificate: "bad certificate",
  57. AlertUnsupportedCertificate: "unsupported certificate",
  58. AlertCertificateRevoked: "revoked certificate",
  59. AlertCertificateExpired: "expired certificate",
  60. AlertCertificateUnknown: "unknown certificate",
  61. AlertIllegalParameter: "illegal parameter",
  62. AlertUnknownCA: "unknown certificate authority",
  63. AlertAccessDenied: "access denied",
  64. AlertDecodeError: "error decoding message",
  65. AlertDecryptError: "error decrypting message",
  66. AlertProtocolVersion: "protocol version not supported",
  67. AlertInsufficientSecurity: "insufficient security level",
  68. AlertInternalError: "internal error",
  69. AlertInappropriateFallback: "inappropriate fallback",
  70. AlertUserCanceled: "user canceled",
  71. AlertMissingExtension: "missing extension",
  72. AlertUnsupportedExtension: "unsupported extension",
  73. AlertCertificateUnobtainable: "certificate unobtainable",
  74. AlertUnrecognizedName: "unrecognized name",
  75. AlertBadCertificateStatsResponse: "bad certificate status response",
  76. AlertBadCertificateHashValue: "bad certificate hash value",
  77. AlertUnknownPSKIdentity: "unknown PSK identity",
  78. AlertNoApplicationProtocol: "no application protocol",
  79. AlertNoRenegotiation: "no renegotiation",
  80. AlertStatelessRetry: "stateless retry",
  81. AlertWouldBlock: "would have blocked",
  82. AlertNoAlert: "no alert",
  83. }
  84. func (e Alert) String() string {
  85. s, ok := alertText[e]
  86. if ok {
  87. return s
  88. }
  89. return "alert(" + strconv.Itoa(int(e)) + ")"
  90. }
  91. func (e Alert) Error() string {
  92. return e.String()
  93. }