PkixCertPathValidatorException.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Pkix
  6. {
  7. /**
  8. * An exception indicating one of a variety of problems encountered when
  9. * validating a certification path. <br />
  10. * <br />
  11. * A <code>CertPathValidatorException</code> provides support for wrapping
  12. * exceptions. The {@link #getCause getCause} method returns the throwable,
  13. * if any, that caused this exception to be thrown. <br />
  14. * <br />
  15. * A <code>CertPathValidatorException</code> may also include the
  16. * certification path that was being validated when the exception was thrown
  17. * and the index of the certificate in the certification path that caused the
  18. * exception to be thrown. Use the {@link #getCertPath getCertPath} and
  19. * {@link #getIndex getIndex} methods to retrieve this information.<br />
  20. * <br />
  21. * <b>Concurrent Access</b><br />
  22. * <br />
  23. * Unless otherwise specified, the methods defined in this class are not
  24. * thread-safe. Multiple threads that need to access a single
  25. * object concurrently should synchronize amongst themselves and
  26. * provide the necessary locking. Multiple threads each manipulating
  27. * separate objects need not synchronize.
  28. *
  29. * @see CertPathValidator
  30. **/
  31. #if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE)
  32. [Serializable]
  33. #endif
  34. public class PkixCertPathValidatorException
  35. : GeneralSecurityException
  36. {
  37. private Exception cause;
  38. private PkixCertPath certPath;
  39. private int index = -1;
  40. public PkixCertPathValidatorException() : base() { }
  41. /// <summary>
  42. /// Creates a <code>PkixCertPathValidatorException</code> with the given detail
  43. /// message. A detail message is a <code>String</code> that describes this
  44. /// particular exception.
  45. /// </summary>
  46. /// <param name="message">the detail message</param>
  47. public PkixCertPathValidatorException(string message) : base(message) { }
  48. /// <summary>
  49. /// Creates a <code>PkixCertPathValidatorException</code> with the specified
  50. /// detail message and cause.
  51. /// </summary>
  52. /// <param name="message">the detail message</param>
  53. /// <param name="cause">the cause (which is saved for later retrieval by the
  54. /// {@link #getCause getCause()} method). (A <code>null</code>
  55. /// value is permitted, and indicates that the cause is
  56. /// nonexistent or unknown.)</param>
  57. public PkixCertPathValidatorException(string message, Exception cause) : base(message)
  58. {
  59. this.cause = cause;
  60. }
  61. /// <summary>
  62. /// Creates a <code>PkixCertPathValidatorException</code> with the specified
  63. /// detail message, cause, certification path, and index.
  64. /// </summary>
  65. /// <param name="message">the detail message (or <code>null</code> if none)</param>
  66. /// <param name="cause">the cause (or <code>null</code> if none)</param>
  67. /// <param name="certPath">the certification path that was in the process of being
  68. /// validated when the error was encountered</param>
  69. /// <param name="index">the index of the certificate in the certification path that</param> *
  70. public PkixCertPathValidatorException(
  71. string message,
  72. Exception cause,
  73. PkixCertPath certPath,
  74. int index)
  75. : base(message)
  76. {
  77. if (certPath == null && index != -1)
  78. {
  79. throw new ArgumentNullException(
  80. "certPath = null and index != -1");
  81. }
  82. if (index < -1
  83. || (certPath != null && index >= certPath.Certificates.Count))
  84. {
  85. throw new IndexOutOfRangeException(
  86. " index < -1 or out of bound of certPath.getCertificates()");
  87. }
  88. this.cause = cause;
  89. this.certPath = certPath;
  90. this.index = index;
  91. }
  92. //
  93. // Prints a stack trace to a <code>PrintWriter</code>, including the
  94. // backtrace of the cause, if any.
  95. //
  96. // @param pw
  97. // the <code>PrintWriter</code> to use for output
  98. //
  99. // public void printStackTrace(PrintWriter pw)
  100. // {
  101. // super.printStackTrace(pw);
  102. // if (getCause() != null)
  103. // {
  104. // getCause().printStackTrace(pw);
  105. // }
  106. // }
  107. //}
  108. // /**
  109. // * Creates a <code>CertPathValidatorException</code> that wraps the
  110. // * specified throwable. This allows any exception to be converted into a
  111. // * <code>CertPathValidatorException</code>, while retaining information
  112. // * about the wrapped exception, which may be useful for debugging. The
  113. // * detail message is set to (<code>cause==null ? null : cause.toString()
  114. // * </code>)
  115. // * (which typically contains the class and detail message of cause).
  116. // *
  117. // * @param cause
  118. // * the cause (which is saved for later retrieval by the
  119. // * {@link #getCause getCause()} method). (A <code>null</code>
  120. // * value is permitted, and indicates that the cause is
  121. // * nonexistent or unknown.)
  122. // */
  123. // public PkixCertPathValidatorException(Throwable cause)
  124. // {
  125. // this.cause = cause;
  126. // }
  127. //
  128. /// <summary>
  129. /// Returns the detail message for this <code>CertPathValidatorException</code>.
  130. /// </summary>
  131. /// <returns>the detail message, or <code>null</code> if neither the message nor cause were specified</returns>
  132. public override string Message
  133. {
  134. get
  135. {
  136. string message = base.Message;
  137. if (message != null)
  138. {
  139. return message;
  140. }
  141. if (cause != null)
  142. {
  143. return cause.Message;
  144. }
  145. return null;
  146. }
  147. }
  148. /**
  149. * Returns the certification path that was being validated when the
  150. * exception was thrown.
  151. *
  152. * @return the <code>CertPath</code> that was being validated when the
  153. * exception was thrown (or <code>null</code> if not specified)
  154. */
  155. public PkixCertPath CertPath
  156. {
  157. get { return certPath; }
  158. }
  159. /**
  160. * Returns the index of the certificate in the certification path that
  161. * caused the exception to be thrown. Note that the list of certificates in
  162. * a <code>CertPath</code> is zero based. If no index has been set, -1 is
  163. * returned.
  164. *
  165. * @return the index that has been set, or -1 if none has been set
  166. */
  167. public int Index
  168. {
  169. get { return index; }
  170. }
  171. // /**
  172. // * Returns the cause of this <code>CertPathValidatorException</code> or
  173. // * <code>null</code> if the cause is nonexistent or unknown.
  174. // *
  175. // * @return the cause of this throwable or <code>null</code> if the cause
  176. // * is nonexistent or unknown.
  177. // */
  178. // public Throwable getCause()
  179. // {
  180. // return cause;
  181. // }
  182. //
  183. // /**
  184. // * Returns a string describing this exception, including a description of
  185. // * the internal (wrapped) cause if there is one.
  186. // *
  187. // * @return a string representation of this
  188. // * <code>CertPathValidatorException</code>
  189. // */
  190. // public String toString()
  191. // {
  192. // StringBuffer sb = new StringBuffer();
  193. // String s = getMessage();
  194. // if (s != null)
  195. // {
  196. // sb.append(s);
  197. // }
  198. // if (getIndex() >= 0)
  199. // {
  200. // sb.append("index in certpath: ").append(getIndex()).append('\n');
  201. // sb.append(getCertPath());
  202. // }
  203. // return sb.toString();
  204. // }
  205. }
  206. }
  207. #pragma warning restore
  208. #endif