Org.BouncyCastle.Pkix.PkixNameConstraintValidator.Equals C# (CSharp) Method

Equals() public method

public Equals ( Object o ) : bool
o Object
return bool
		public override bool Equals(Object o)
		{
			if (!(o is PkixNameConstraintValidator))
				return false;

			PkixNameConstraintValidator constraintValidator = (PkixNameConstraintValidator)o;

			return CollectionsAreEqual(constraintValidator.excludedSubtreesDN, excludedSubtreesDN)
				&& CollectionsAreEqual(constraintValidator.excludedSubtreesDNS, excludedSubtreesDNS)
				&& CollectionsAreEqual(constraintValidator.excludedSubtreesEmail, excludedSubtreesEmail)
				&& CollectionsAreEqual(constraintValidator.excludedSubtreesIP, excludedSubtreesIP)
				&& CollectionsAreEqual(constraintValidator.excludedSubtreesURI, excludedSubtreesURI)
				&& CollectionsAreEqual(constraintValidator.permittedSubtreesDN, permittedSubtreesDN)
				&& CollectionsAreEqual(constraintValidator.permittedSubtreesDNS, permittedSubtreesDNS)
				&& CollectionsAreEqual(constraintValidator.permittedSubtreesEmail, permittedSubtreesEmail)
				&& CollectionsAreEqual(constraintValidator.permittedSubtreesIP, permittedSubtreesIP)
				&& CollectionsAreEqual(constraintValidator.permittedSubtreesURI, permittedSubtreesURI);
		}

Usage Example

		/**
		 * Tests byte array based GeneralNames for inclusion or exclusion.
		 * 
		 * @param nameType The {@link GeneralName} type to test.
		 * @param testName The name to test.
		 * @param testNameIsConstraint The names where <code>testName</code> must
		 *            be included and excluded.
		 * @param testNameIsNotConstraint The names where <code>testName</code>
		 *            must not be excluded and included.
		 * @param testNames1 Operand 1 of test names to use for union and
		 *            intersection testing.
		 * @param testNames2 Operand 2 of test names to use for union and
		 *            intersection testing.
		 * @param testUnion The union results.
		 * @param testInterSection The intersection results.
		 * @throws Exception If an unexpected exception occurs.
		 */
		private void TestConstraints(
			int nameType,
			byte[] testName,
			byte[][] testNameIsConstraint,
			byte[][] testNameIsNotConstraint,
			byte[][] testNames1,
			byte[][] testNames2,
			byte[][][] testUnion,
			byte[][] testInterSection)
		{
			for (int i = 0; i < testNameIsConstraint.Length; i++)
			{
				PkixNameConstraintValidator constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.IntersectPermittedSubtree(new DerSequence(new GeneralSubtree(
					new GeneralName(nameType, new DerOctetString(
					testNameIsConstraint[i])))));
				constraintValidator.checkPermitted(new GeneralName(nameType,
					new DerOctetString(testName)));
			}
			for (int i = 0; i < testNameIsNotConstraint.Length; i++)
			{
				PkixNameConstraintValidator constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.IntersectPermittedSubtree(new DerSequence(new GeneralSubtree(
					new GeneralName(nameType, new DerOctetString(
					testNameIsNotConstraint[i])))));
				try
				{
					constraintValidator.checkPermitted(new GeneralName(nameType,
						new DerOctetString(testName)));
					Fail("not permitted name allowed: " + nameType);
				}
				catch (PkixNameConstraintValidatorException)
				{
					// expected
				}
			}
			for (int i = 0; i < testNameIsConstraint.Length; i++)
			{
				PkixNameConstraintValidator constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.AddExcludedSubtree(new GeneralSubtree(new GeneralName(
					nameType, new DerOctetString(testNameIsConstraint[i]))));
				try
				{
					constraintValidator.checkExcluded(new GeneralName(nameType,
						new DerOctetString(testName)));
					Fail("excluded name missed: " + nameType);
				}
				catch (PkixNameConstraintValidatorException)
				{
					// expected
				}
			}
			for (int i = 0; i < testNameIsNotConstraint.Length; i++)
			{
				PkixNameConstraintValidator constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.AddExcludedSubtree(new GeneralSubtree(new GeneralName(
					nameType, new DerOctetString(testNameIsNotConstraint[i]))));
				constraintValidator.checkExcluded(new GeneralName(nameType,
					new DerOctetString(testName)));
			}
			for (int i = 0; i < testNames1.Length; i++)
			{
				PkixNameConstraintValidator constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.AddExcludedSubtree(new GeneralSubtree(new GeneralName(
					nameType, new DerOctetString(testNames1[i]))));
				constraintValidator.AddExcludedSubtree(new GeneralSubtree(new GeneralName(
					nameType, new DerOctetString(testNames2[i]))));
				PkixNameConstraintValidator constraints2 = new PkixNameConstraintValidator();
				for (int j = 0; j < testUnion[i].Length; j++)
				{
					constraints2.AddExcludedSubtree(new GeneralSubtree(
						new GeneralName(nameType, new DerOctetString(
						testUnion[i][j]))));
				}
				if (!constraints2.Equals(constraintValidator))
				{
					Fail("union wrong: " + nameType);
				}
				constraintValidator = new PkixNameConstraintValidator();
				constraintValidator.IntersectPermittedSubtree(new DerSequence(new GeneralSubtree(
					new GeneralName(nameType, new DerOctetString(testNames1[i])))));
				constraintValidator.IntersectPermittedSubtree(new DerSequence(new GeneralSubtree(
					new GeneralName(nameType, new DerOctetString(testNames2[i])))));
				constraints2 = new PkixNameConstraintValidator();
				if (testInterSection[i] != null)
				{
					constraints2.IntersectPermittedSubtree(new DerSequence(new GeneralSubtree(
						new GeneralName(nameType, new DerOctetString(
						testInterSection[i])))));
				}
				else
				{
					constraints2.IntersectEmptyPermittedSubtree(nameType);
				}

				if (!constraints2.Equals(constraintValidator))
				{
					Fail("intersection wrong: " + nameType);
				}
			}
		}