using System; using Org.BouncyCastle.Security; namespace Org.BouncyCastle.Pkix { /** * An exception indicating one of a variety of problems encountered when * validating a certification path.
*
* A CertPathValidatorException provides support for wrapping * exceptions. The {@link #getCause getCause} method returns the throwable, * if any, that caused this exception to be thrown.
*
* A CertPathValidatorException may also include the * certification path that was being validated when the exception was thrown * and the index of the certificate in the certification path that caused the * exception to be thrown. Use the {@link #getCertPath getCertPath} and * {@link #getIndex getIndex} methods to retrieve this information.
*
* Concurrent Access
*
* Unless otherwise specified, the methods defined in this class are not * thread-safe. Multiple threads that need to access a single * object concurrently should synchronize amongst themselves and * provide the necessary locking. Multiple threads each manipulating * separate objects need not synchronize. * * @see CertPathValidator **/ #if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE) [Serializable] #endif public class PkixCertPathValidatorException : GeneralSecurityException { private Exception cause; private PkixCertPath certPath; private int index = -1; public PkixCertPathValidatorException() : base() { } /// /// Creates a PkixCertPathValidatorException with the given detail /// message. A detail message is a String that describes this /// particular exception. /// /// the detail message public PkixCertPathValidatorException(string message) : base(message) { } /// /// Creates a PkixCertPathValidatorException with the specified /// detail message and cause. /// /// the detail message /// the cause (which is saved for later retrieval by the /// {@link #getCause getCause()} method). (A null /// value is permitted, and indicates that the cause is /// nonexistent or unknown.) public PkixCertPathValidatorException(string message, Exception cause) : base(message) { this.cause = cause; } /// /// Creates a PkixCertPathValidatorException with the specified /// detail message, cause, certification path, and index. /// /// the detail message (or null if none) /// the cause (or null if none) /// the certification path that was in the process of being /// validated when the error was encountered /// the index of the certificate in the certification path that * public PkixCertPathValidatorException( string message, Exception cause, PkixCertPath certPath, int index) : base(message) { if (certPath == null && index != -1) { throw new ArgumentNullException( "certPath = null and index != -1"); } if (index < -1 || (certPath != null && index >= certPath.Certificates.Count)) { throw new IndexOutOfRangeException( " index < -1 or out of bound of certPath.getCertificates()"); } this.cause = cause; this.certPath = certPath; this.index = index; } // // Prints a stack trace to a PrintWriter, including the // backtrace of the cause, if any. // // @param pw // the PrintWriter to use for output // // public void printStackTrace(PrintWriter pw) // { // super.printStackTrace(pw); // if (getCause() != null) // { // getCause().printStackTrace(pw); // } // } //} // /** // * Creates a CertPathValidatorException that wraps the // * specified throwable. This allows any exception to be converted into a // * CertPathValidatorException, while retaining information // * about the wrapped exception, which may be useful for debugging. The // * detail message is set to (cause==null ? null : cause.toString() // * ) // * (which typically contains the class and detail message of cause). // * // * @param cause // * the cause (which is saved for later retrieval by the // * {@link #getCause getCause()} method). (A null // * value is permitted, and indicates that the cause is // * nonexistent or unknown.) // */ // public PkixCertPathValidatorException(Throwable cause) // { // this.cause = cause; // } // /// /// Returns the detail message for this CertPathValidatorException. /// /// the detail message, or null if neither the message nor cause were specified public override string Message { get { string message = base.Message; if (message != null) { return message; } if (cause != null) { return cause.Message; } return null; } } /** * Returns the certification path that was being validated when the * exception was thrown. * * @return the CertPath that was being validated when the * exception was thrown (or null if not specified) */ public PkixCertPath CertPath { get { return certPath; } } /** * Returns the index of the certificate in the certification path that * caused the exception to be thrown. Note that the list of certificates in * a CertPath is zero based. If no index has been set, -1 is * returned. * * @return the index that has been set, or -1 if none has been set */ public int Index { get { return index; } } // /** // * Returns the cause of this CertPathValidatorException or // * null if the cause is nonexistent or unknown. // * // * @return the cause of this throwable or null if the cause // * is nonexistent or unknown. // */ // public Throwable getCause() // { // return cause; // } // // /** // * Returns a string describing this exception, including a description of // * the internal (wrapped) cause if there is one. // * // * @return a string representation of this // * CertPathValidatorException // */ // public String toString() // { // StringBuffer sb = new StringBuffer(); // String s = getMessage(); // if (s != null) // { // sb.append(s); // } // if (getIndex() >= 0) // { // sb.append("index in certpath: ").append(getIndex()).append('\n'); // sb.append(getCertPath()); // } // return sb.toString(); // } } }