summary refs log tree commit diff
path: root/crypto/test/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 17:09:32 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 17:09:32 +0700
commit12d3743c290abc58c509312b0ec46994a2811002 (patch)
tree8cf011f381b40602c48cf6f24a363d2f7c87d6ad /crypto/test/src
parentGenerics migration in Pkcs (diff)
downloadBouncyCastle.NET-ed25519-12d3743c290abc58c509312b0ec46994a2811002.tar.xz
Generics migration in Pkix
Diffstat (limited to 'crypto/test/src')
-rw-r--r--crypto/test/src/asn1/test/X509NameTest.cs28
-rw-r--r--crypto/test/src/test/CertPathTest.cs7
-rw-r--r--crypto/test/src/test/CertPathValidatorTest.cs12
-rw-r--r--crypto/test/src/test/CertTest.cs48
4 files changed, 41 insertions, 54 deletions
diff --git a/crypto/test/src/asn1/test/X509NameTest.cs b/crypto/test/src/asn1/test/X509NameTest.cs
index 0df3a020e..c6de1b1db 100644
--- a/crypto/test/src/asn1/test/X509NameTest.cs
+++ b/crypto/test/src/asn1/test/X509NameTest.cs
@@ -1,6 +1,6 @@
 using System;
 using System.Collections;
-using System.IO;
+using System.Collections.Generic;
 
 using NUnit.Framework;
 
@@ -170,7 +170,7 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("Failed same name test - in Order");
             }
 
-            IList ord1 = new ArrayList();
+            var ord1 = new List<DerObjectIdentifier>();
 
             ord1.Add(X509Name.C);
             ord1.Add(X509Name.O);
@@ -178,7 +178,7 @@ namespace Org.BouncyCastle.Asn1.Tests
             ord1.Add(X509Name.ST);
             ord1.Add(X509Name.E);
 
-            IList ord2 = new ArrayList();
+            var ord2 = new List<DerObjectIdentifier>();
 
             ord2.Add(X509Name.E);
             ord2.Add(X509Name.ST);
@@ -210,13 +210,13 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("Failed reverse name test - in Order false");
             }
 
-            IList oids = name1.GetOidList();
+            var oids = name1.GetOidList();
             if (!CompareVectors(oids, ord1))
             {
                 Fail("oid comparison test");
             }
 
-            IList val1 = new ArrayList();
+            var val1 = new List<string>();
 
             val1.Add("AU");
             val1.Add("The Legion of the Bouncy Castle");
@@ -226,13 +226,13 @@ namespace Org.BouncyCastle.Asn1.Tests
 
             name1 = new X509Name(ord1, val1);
 
-            IList values = name1.GetValueList();
+            var values = name1.GetValueList();
             if (!CompareVectors(values, val1))
             {
                 Fail("value comparison test");
             }
 
-            ord2 = new ArrayList();
+            ord2 = new List<DerObjectIdentifier>();
 
             ord2.Add(X509Name.ST);
             ord2.Add(X509Name.ST);
@@ -248,7 +248,7 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("Failed different name test");
             }
 
-            ord2 = new ArrayList();
+            ord2 = new List<DerObjectIdentifier>();
 
             ord2.Add(X509Name.ST);
             ord2.Add(X509Name.L);
@@ -270,14 +270,14 @@ namespace Org.BouncyCastle.Asn1.Tests
             //
             // getValues test
             //
-            IList v1 = name1.GetValueList(X509Name.O);
+            var v1 = name1.GetValueList(X509Name.O);
 
             if (v1.Count != 1 || !v1[0].Equals("The Legion of the Bouncy Castle"))
             {
                 Fail("O test failed");
             }
 
-            IList v2 = name1.GetValueList(X509Name.L);
+            var v2 = name1.GetValueList(X509Name.L);
 
             if (v2.Count != 1 || !v2[0].Equals("Melbourne"))
             {
@@ -505,7 +505,7 @@ namespace Org.BouncyCastle.Asn1.Tests
                 Fail("# string not properly escaped.");
             }
 
-            IList vls = n.GetValueList(X509Name.CN);
+            var vls = n.GetValueList(X509Name.CN);
             if (vls.Count != 1 || !vls[0].Equals("#nothex#string"))
             {
                 Fail("Escaped # not reduced properly");
@@ -633,16 +633,14 @@ namespace Org.BouncyCastle.Asn1.Tests
             }
         }
 
-        private bool CompareVectors(
-            IList	one,
-            IList	two)
+        private bool CompareVectors<T>(IList<T> one, IList<T> two)
         {
             if (one.Count != two.Count)
                 return false;
 
             for (int i = 0; i < one.Count; ++i)
             {
-                if (!one[i].Equals(two[i]))
+                if (!Equals(one[i], two[i]))
                     return false;
             }
 
diff --git a/crypto/test/src/test/CertPathTest.cs b/crypto/test/src/test/CertPathTest.cs
index e254e0c41..869ffd6a0 100644
--- a/crypto/test/src/test/CertPathTest.cs
+++ b/crypto/test/src/test/CertPathTest.cs
@@ -173,9 +173,8 @@ namespace Org.BouncyCastle.Tests
 			X509Certificate finalCert = cf.ReadCertificate(finalCertBin);
 
 			//Testing CertPath generation from List
-			IList list = new ArrayList();
+			var list = new List<X509Certificate>();
 			list.Add(interCert);
-//			CertPath certPath1 = cf.generateCertPath(list);
 			PkixCertPath certPath1 = new PkixCertPath(list);
 
 			//Testing CertPath encoding as PkiPath
@@ -183,7 +182,6 @@ namespace Org.BouncyCastle.Tests
 
 			//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
@@ -221,9 +219,8 @@ namespace Org.BouncyCastle.Tests
 			//
 			// empty list test
 			//
-			list = new ArrayList();
+			list = new List<X509Certificate>();
 
-//			CertPath certPath = CertificateFactory.GetInstance("X.509","BC").generateCertPath(list);
 			PkixCertPath certPath = new PkixCertPath(list);
 			if (certPath.Certificates.Count != 0)
 			{
diff --git a/crypto/test/src/test/CertPathValidatorTest.cs b/crypto/test/src/test/CertPathValidatorTest.cs
index b4d5d7773..88ffe7938 100644
--- a/crypto/test/src/test/CertPathValidatorTest.cs
+++ b/crypto/test/src/test/CertPathValidatorTest.cs
@@ -154,16 +154,14 @@ namespace Org.BouncyCastle.Tests
             DateTime validDate = new DateTime(2008, 9, 4, 5, 49, 10);
 
             //validating path
-            IList certchain = new ArrayList();
+            var certchain = new List<X509Certificate>();
             certchain.Add(finalCert);
             certchain.Add(interCert);
 
-//			CertPath cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain);
             PkixCertPath cp = new PkixCertPath(certchain);
             var trust = new HashSet<TrustAnchor>();
             trust.Add(new TrustAnchor(rootCert, null));
 
-//			CertPathValidator cpv = CertPathValidator.GetInstance("PKIX");
             PkixCertPathValidator cpv = new PkixCertPathValidator();
             PkixParameters param = new PkixParameters(trust);
             param.AddStoreCert(x509CertStore);
@@ -172,7 +170,7 @@ namespace Org.BouncyCastle.Tests
             MyChecker checker = new MyChecker();
             param.AddCertPathChecker(checker);
 
-            PkixCertPathValidatorResult result = (PkixCertPathValidatorResult)cpv.Validate(cp, param);
+            PkixCertPathValidatorResult result = cpv.Validate(cp, param);
             PkixPolicyNode policyTree = result.PolicyTree;
             AsymmetricKeyParameter subjectPublicKey = result.SubjectPublicKey;
 
@@ -230,23 +228,21 @@ namespace Org.BouncyCastle.Tests
                 validDate = new DateTime(2004, 3, 20, 19, 21, 10);
 
                 //validating path
-                certchain = new ArrayList();
+                certchain = new List<X509Certificate>();
                 certchain.Add(finalCert);
                 certchain.Add(interCert);
 
-//				cp = CertificateFactory.GetInstance("X.509").GenerateCertPath(certchain);
                 cp = new PkixCertPath(certchain);
                 trust = new HashSet<TrustAnchor>();
                 trust.Add(new TrustAnchor(rootCert, null));
 
-//				cpv = CertPathValidator.GetInstance("PKIX");
                 cpv = new PkixCertPathValidator();
                 param = new PkixParameters(trust);
                 param.AddStoreCert(x509CertStore);
                 param.IsRevocationEnabled = false;
                 param.Date = new DateTimeObject(validDate);
 
-                result =(PkixCertPathValidatorResult) cpv.Validate(cp, param);
+                result = cpv.Validate(cp, param);
                 policyTree = result.PolicyTree;
                 subjectPublicKey = result.SubjectPublicKey;
 
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index 5fc23d861..0e1cf1d70 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1137,7 +1137,7 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
@@ -1215,8 +1215,8 @@ namespace Org.BouncyCastle.Tests
                 Fail("error generating cert - key usage wrong.");
             }
 
-            IList l = cert.GetExtendedKeyUsage();
-            if (!l[0].Equals(KeyPurposeID.AnyExtendedKeyUsage.Id))
+            var ekus = cert.GetExtendedKeyUsage();
+            if (ekus.Count < 1 || !KeyPurposeID.AnyExtendedKeyUsage.Equals(ekus[0]))
             {
                 Fail("failed extended key usage test");
             }
@@ -1291,7 +1291,7 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
@@ -1312,7 +1312,7 @@ namespace Org.BouncyCastle.Tests
             //
             // create the certificate - version 3
             //
-            X509V3CertificateGenerator  certGen = new X509V3CertificateGenerator();
+            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
 
             certGen.SetSerialNumber(BigInteger.One);
             certGen.SetIssuerDN(new X509Name(ord, values));
@@ -1967,9 +1967,7 @@ namespace Org.BouncyCastle.Tests
                 Fail("crl not returned!");
             }
 
-//			ICollection col = cFact.generateCRLs(new ByteArrayInputStream(newCrl.getEncoded()));
-            ICollection col = new X509CrlParser().ReadCrls(newCrl.GetEncoded());
-
+            var col = new X509CrlParser().ReadCrls(newCrl.GetEncoded());
             if (col.Count != 1)
             {
                 Fail("wrong number of CRLs found in collection");
@@ -2090,7 +2088,7 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
@@ -2230,15 +2228,13 @@ namespace Org.BouncyCastle.Tests
             {
                 Fail("PEM crl not read");
             }
-            ArrayList col = new ArrayList(
-                new X509CertificateParser().ReadCertificates(Encoding.ASCII.GetBytes(PemData.CERTIFICATE_2)));
-            if (col.Count != 1 || !col.Contains(cert))
+            var certList = new X509CertificateParser().ReadCertificates(Encoding.ASCII.GetBytes(PemData.CERTIFICATE_2));
+            if (certList.Count != 1 || !certList.Contains(cert))
             {
                 Fail("PEM cert collection not right");
             }
-            col = new ArrayList(
-                new X509CrlParser().ReadCrls(Encoding.ASCII.GetBytes(PemData.CRL_2)));
-            if (col.Count != 1 || !col.Contains(crl))
+            var crlList = new X509CrlParser().ReadCrls(Encoding.ASCII.GetBytes(PemData.CRL_2));
+            if (crlList.Count != 1 || !crlList.Contains(crl))
             {
                 Fail("PEM crl collection not right");
             }
@@ -2279,13 +2275,13 @@ namespace Org.BouncyCastle.Tests
             {
                 Fail("PKCS7 crl not read");
             }
-            ArrayList col = new ArrayList(certParser.ReadCertificates(info.GetEncoded()));
-            if (col.Count != 1 || !col.Contains(cert))
+            var certList = certParser.ReadCertificates(info.GetEncoded());
+            if (certList.Count != 1 || !certList.Contains(cert))
             {
                 Fail("PKCS7 cert collection not right");
             }
-            col = new ArrayList(crlParser.ReadCrls(info.GetEncoded()));
-            if (col.Count != 1 || !col.Contains(crl))
+            var crlList = crlParser.ReadCrls(info.GetEncoded());
+            if (crlList.Count != 1 || !crlList.Contains(crl))
             {
                 Fail("PKCS7 crl collection not right");
             }
@@ -2327,8 +2323,8 @@ namespace Org.BouncyCastle.Tests
             //
             // sample message
             //
-            ICollection certCol = certParser.ReadCertificates(pkcs7CrlProblem);
-            ICollection crlCol = crlParser.ReadCrls(pkcs7CrlProblem);
+            var certCol = certParser.ReadCertificates(pkcs7CrlProblem);
+            var crlCol = crlParser.ReadCrls(pkcs7CrlProblem);
 
             if (crlCol.Count != 0)
             {
@@ -2352,7 +2348,7 @@ namespace Org.BouncyCastle.Tests
             //
             // distinguished name table.
             //
-            IList ord = new ArrayList();
+            var ord = new List<DerObjectIdentifier>();
             ord.Add(X509Name.C);
             ord.Add(X509Name.O);
             ord.Add(X509Name.L);
@@ -2474,7 +2470,7 @@ namespace Org.BouncyCastle.Tests
         {
             X509CertificateParser fact = new X509CertificateParser();
 
-            ICollection certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain.data"));
+            var certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain.data"));
             IsTrue("certs wrong <cr><nl>", 2 == certs1.Count);
 
             MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain.data")), false);
@@ -2501,10 +2497,10 @@ namespace Org.BouncyCastle.Tests
         {
             X509CrlParser crlParser = new X509CrlParser();
 
-            ICollection crls = crlParser.ReadCrls(GetTestDataAsStream("cert_chain.data"));
+            var crls = crlParser.ReadCrls(GetTestDataAsStream("cert_chain.data"));
             IsTrue("multi crl", crls.Count == 0);
 
-            X509Crl crl = crlParser.ReadCrl(GetTestDataAsStream("cert_chain.data"));
+            var crl = crlParser.ReadCrl(GetTestDataAsStream("cert_chain.data"));
             IsTrue("single crl", crl == null);
         }
 
@@ -2512,7 +2508,7 @@ namespace Org.BouncyCastle.Tests
         {
             X509CertificateParser fact = new X509CertificateParser();
 
-            ICollection certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain_nl.data"));
+            var certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain_nl.data"));
             IsTrue("certs wrong <nl>", 2 == certs1.Count);
 
             MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain_nl.data")), false);