TlsFatalAlert.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Runtime.Serialization;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. [Serializable]
  8. public class TlsFatalAlert
  9. : TlsException
  10. {
  11. private static string GetMessage(short alertDescription, string detailMessage)
  12. {
  13. string msg = Tls.AlertDescription.GetText(alertDescription);
  14. if (null != detailMessage)
  15. {
  16. msg += "; " + detailMessage;
  17. }
  18. return msg;
  19. }
  20. protected readonly byte m_alertDescription;
  21. public TlsFatalAlert(short alertDescription)
  22. : this(alertDescription, null, null)
  23. {
  24. }
  25. public TlsFatalAlert(short alertDescription, string detailMessage)
  26. : this(alertDescription, detailMessage, null)
  27. {
  28. }
  29. public TlsFatalAlert(short alertDescription, Exception alertCause)
  30. : this(alertDescription, null, alertCause)
  31. {
  32. }
  33. public TlsFatalAlert(short alertDescription, string detailMessage, Exception alertCause)
  34. : base(GetMessage(alertDescription, detailMessage), alertCause)
  35. {
  36. if (!TlsUtilities.IsValidUint8(alertDescription))
  37. throw new ArgumentOutOfRangeException(nameof(alertDescription));
  38. m_alertDescription = (byte)alertDescription;
  39. }
  40. protected TlsFatalAlert(SerializationInfo info, StreamingContext context)
  41. : base(info, context)
  42. {
  43. m_alertDescription = info.GetByte("alertDescription");
  44. }
  45. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  46. {
  47. base.GetObjectData(info, context);
  48. info.AddValue("alertDescription", m_alertDescription);
  49. }
  50. public virtual short AlertDescription
  51. {
  52. get { return m_alertDescription; }
  53. }
  54. }
  55. }
  56. #pragma warning restore
  57. #endif