PkixCertPathValidatorException.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Runtime.Serialization;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Pkix
  7. {
  8. /**
  9. * An exception indicating one of a variety of problems encountered when
  10. * validating a certification path. <br />
  11. * <br />
  12. * A <code>CertPathValidatorException</code> provides support for wrapping
  13. * exceptions. The {@link #getCause getCause} method returns the throwable,
  14. * if any, that caused this exception to be thrown. <br />
  15. * <br />
  16. * A <code>CertPathValidatorException</code> may also include the
  17. * certification path that was being validated when the exception was thrown
  18. * and the index of the certificate in the certification path that caused the
  19. * exception to be thrown. Use the {@link #getCertPath getCertPath} and
  20. * {@link #getIndex getIndex} methods to retrieve this information.<br />
  21. * <br />
  22. * <b>Concurrent Access</b><br />
  23. * <br />
  24. * Unless otherwise specified, the methods defined in this class are not
  25. * thread-safe. Multiple threads that need to access a single
  26. * object concurrently should synchronize amongst themselves and
  27. * provide the necessary locking. Multiple threads each manipulating
  28. * separate objects need not synchronize.
  29. *
  30. * @see CertPathValidator
  31. **/
  32. [Serializable]
  33. public class PkixCertPathValidatorException
  34. : GeneralSecurityException
  35. {
  36. protected readonly int m_index = -1;
  37. public PkixCertPathValidatorException()
  38. : base()
  39. {
  40. }
  41. public PkixCertPathValidatorException(string message)
  42. : base(message)
  43. {
  44. }
  45. public PkixCertPathValidatorException(string message, Exception innerException)
  46. : base(message, innerException)
  47. {
  48. }
  49. /// <summary>
  50. /// Creates a <code>PkixCertPathValidatorException</code> with the specified
  51. /// detail message, cause, certification path, and index.
  52. /// </summary>
  53. /// <param name="message">the detail message (or <code>null</code> if none)</param>
  54. /// <param name="innerException">the cause (or <code>null</code> if none)</param>
  55. /// <param name="index">the index of the certificate in the certification path that</param> *
  56. public PkixCertPathValidatorException(string message, Exception innerException, int index)
  57. : base(message, innerException)
  58. {
  59. if (index < -1)
  60. throw new ArgumentException("cannot be < -1", nameof(index));
  61. m_index = index;
  62. }
  63. protected PkixCertPathValidatorException(SerializationInfo info, StreamingContext context)
  64. : base(info, context)
  65. {
  66. m_index = info.GetInt32("index");
  67. }
  68. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  69. {
  70. base.GetObjectData(info, context);
  71. info.AddValue("index", m_index);
  72. }
  73. /// <summary> eturns the index of the certificate in the certification path that caused the exception to be
  74. /// thrown.</summary>
  75. /// <remarks>
  76. /// Note that the list of certificates in a <see cref="PkixCertPath"/> is zero based. If no index has been set,
  77. /// -1 is returned.
  78. /// </remarks>
  79. /// <returns>The index that has been set, or -1 if none has been set.</returns>
  80. public int Index
  81. {
  82. get { return m_index; }
  83. }
  84. }
  85. }
  86. #pragma warning restore
  87. #endif