using System; using System.Collections.Generic; using System.Text; using Org.BouncyCastle.Security; using Org.BouncyCastle.X509; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Collections; namespace Org.BouncyCastle.Pkix { /// /// Summary description for PkixBuilderParameters. /// public class PkixBuilderParameters : PkixParameters { private int maxPathLength = 5; private HashSet excludedCerts = new HashSet(); /** * Returns an instance of PkixBuilderParameters. *

* This method can be used to get a copy from other * PKIXBuilderParameters, PKIXParameters, * and ExtendedPKIXParameters instances. *

* * @param pkixParams The PKIX parameters to create a copy of. * @return An PkixBuilderParameters instance. */ public static PkixBuilderParameters GetInstance( PkixParameters pkixParams) { PkixBuilderParameters parameters = new PkixBuilderParameters( pkixParams.GetTrustAnchors(), pkixParams.GetTargetConstraintsCert(), pkixParams.GetTargetConstraintsAttrCert()); parameters.SetParams(pkixParams); return parameters; } public PkixBuilderParameters(ISet trustAnchors, ISelector targetConstraintsCert) : this(trustAnchors, targetConstraintsCert, null) { } public PkixBuilderParameters(ISet trustAnchors, ISelector targetConstraintsCert, ISelector targetConstraintsAttrCert) : base(trustAnchors) { SetTargetConstraintsCert(targetConstraintsCert); SetTargetConstraintsAttrCert(targetConstraintsAttrCert); } public virtual int MaxPathLength { get { return maxPathLength; } set { if (value < -1) { throw new InvalidParameterException( "The maximum path length parameter can not be less than -1."); } this.maxPathLength = value; } } /// /// Excluded certificates are not used for building a certification path. /// /// the excluded certificates. public virtual ISet GetExcludedCerts() { return new HashSet(excludedCerts); } /// /// Sets the excluded certificates which are not used for building a /// certification path. If the ISet is null an /// empty set is assumed. /// /// /// The given set is cloned to protect it against subsequent modifications. /// /// The excluded certificates to set. public virtual void SetExcludedCerts(ISet excludedCerts) { if (excludedCerts == null) { this.excludedCerts = new HashSet(); } else { this.excludedCerts = new HashSet(excludedCerts); } } /** * Can alse handle ExtendedPKIXBuilderParameters and * PKIXBuilderParameters. * * @param params Parameters to set. * @see org.bouncycastle.x509.ExtendedPKIXParameters#setParams(java.security.cert.PKIXParameters) */ protected override void SetParams(PkixParameters parameters) { base.SetParams(parameters); if (parameters is PkixBuilderParameters _params) { maxPathLength = _params.maxPathLength; excludedCerts = new HashSet(_params.excludedCerts); } } /** * Makes a copy of this PKIXParameters object. Changes to the * copy will not affect the original and vice versa. * * @return a copy of this PKIXParameters object */ public override object Clone() { PkixBuilderParameters parameters = new PkixBuilderParameters( GetTrustAnchors(), GetTargetConstraintsCert(), GetTargetConstraintsAttrCert()); parameters.SetParams(this); return parameters; } public override string ToString() { StringBuilder s = new StringBuilder(); s.AppendLine("PkixBuilderParameters ["); s.Append(base.ToString()); s.Append(" Maximum Path Length: "); s.Append(MaxPathLength); s.AppendLine(); s.AppendLine("]"); return s.ToString(); } } }