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

Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
		public override bool Equals(
			object obj)
		{
			if (this == obj)
				return true;

			PkixCertPath other = obj as PkixCertPath;
			if (other == null)
				return false;

//			if (!this.Type.Equals(other.Type))
//				return false;

			//return this.Certificates.Equals(other.Certificates);

			// TODO Extract this to a utility class
			IList thisCerts = this.Certificates;
			IList otherCerts = other.Certificates;

			if (thisCerts.Count != otherCerts.Count)
				return false;

			IEnumerator e1 = thisCerts.GetEnumerator();
			IEnumerator e2 = thisCerts.GetEnumerator();

			while (e1.MoveNext())
			{
				e2.MoveNext();

				if (!Platform.Equals(e1.Current, e2.Current))
					return false;
			}

			return true;
		}

Usage Example

示例#1
0
		public override void PerformTest()
		{
			X509CertificateParser cf = new X509CertificateParser();

			X509Certificate rootCert = cf.ReadCertificate(rootCertBin);
			X509Certificate interCert = cf.ReadCertificate(interCertBin);
			X509Certificate finalCert = cf.ReadCertificate(finalCertBin);

			//Testing CertPath generation from List
			IList list = new ArrayList();
			list.Add(interCert);
//			CertPath certPath1 = cf.generateCertPath(list);
			PkixCertPath certPath1 = new PkixCertPath(list);

			//Testing CertPath encoding as PkiPath
			byte[] encoded = certPath1.GetEncoded("PkiPath");

			//Testing CertPath generation from InputStream
			MemoryStream inStream = new MemoryStream(encoded, false);
//			CertPath certPath2 = cf.generateCertPath(inStream, "PkiPath");
			PkixCertPath certPath2 = new PkixCertPath(inStream, "PkiPath");

			//Comparing both CertPathes
			if (!certPath2.Equals(certPath1))
			{
				Fail("CertPath differ after encoding and decoding.");
			}

			encoded = certPath1.GetEncoded("PKCS7");

			//Testing CertPath generation from InputStream
			inStream = new MemoryStream(encoded, false);
//			certPath2 = cf.generateCertPath(inStream, "PKCS7");
			certPath2 = new PkixCertPath(inStream, "PKCS7");

			//Comparing both CertPathes
			if (!certPath2.Equals(certPath1))
			{
				Fail("CertPath differ after encoding and decoding.");
			}

			encoded = certPath1.GetEncoded("PEM");

			//Testing CertPath generation from InputStream
			inStream = new MemoryStream(encoded, false);
//			certPath2 = cf.generateCertPath(inStream, "PEM");
			certPath2 = new PkixCertPath(inStream, "PEM");

			//Comparing both CertPathes
			if (!certPath2.Equals(certPath1))
			{
				Fail("CertPath differ after encoding and decoding.");
			}

			//
			// empty list test
			//
			list = new ArrayList();

//			CertPath certPath = CertificateFactory.GetInstance("X.509","BC").generateCertPath(list);
			PkixCertPath certPath = new PkixCertPath(list);
			if (certPath.Certificates.Count != 0)
			{
				Fail("list wrong size.");
			}

			//
			// exception tests
			//
			doTestExceptions();
		}