diff --git a/crypto/test/src/asn1/test/AttributeTableUnitTest.cs b/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
index c6d69fa2b..d5f49f0a8 100644
--- a/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
+++ b/crypto/test/src/asn1/test/AttributeTableUnitTest.cs
@@ -1,9 +1,7 @@
using System;
-using System.Collections;
using NUnit.Framework;
-using Org.BouncyCastle.Asn1;
using Asn1Cms = Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Utilities.Test;
diff --git a/crypto/test/src/asn1/test/X509NameTest.cs b/crypto/test/src/asn1/test/X509NameTest.cs
index c344042a2..bafec3226 100644
--- a/crypto/test/src/asn1/test/X509NameTest.cs
+++ b/crypto/test/src/asn1/test/X509NameTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
diff --git a/crypto/test/src/cmp/test/ProtectedMessageTest.cs b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
index 98bae77ee..4c242d48a 100644
--- a/crypto/test/src/cmp/test/ProtectedMessageTest.cs
+++ b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
@@ -324,7 +323,7 @@ namespace Org.BouncyCastle.Cmp.Tests
{
IDictionary<DerObjectIdentifier, string> attrs = new Dictionary<DerObjectIdentifier, string>();
IList<DerObjectIdentifier> ord = new List<DerObjectIdentifier>();
- IList values = new ArrayList();
+ IList<string> values = new List<string>();
private DateTime notBefore, notAfter;
private AsymmetricKeyParameter publicKey;
diff --git a/crypto/test/src/cms/test/CMSTestUtil.cs b/crypto/test/src/cms/test/CMSTestUtil.cs
index b6818bb8a..016260625 100644
--- a/crypto/test/src/cms/test/CMSTestUtil.cs
+++ b/crypto/test/src/cms/test/CMSTestUtil.cs
@@ -213,7 +213,7 @@ namespace Org.BouncyCastle.Cms.Tests
{
buf.Append(Encoding.ASCII.GetString(data, i, data.Length - i));
}
- buf.Append('\n');
+ buf.AppendLine();
}
return buf.ToString();
diff --git a/crypto/test/src/crmf/test/CrmfTest.cs b/crypto/test/src/crmf/test/CrmfTest.cs
index 7a5349db1..f900e0879 100644
--- a/crypto/test/src/crmf/test/CrmfTest.cs
+++ b/crypto/test/src/crmf/test/CrmfTest.cs
@@ -1,10 +1,7 @@
using System;
-using System.Collections;
using NUnit.Framework;
-using Org.BouncyCastle.Asn1;
-using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Pkcs;
@@ -156,7 +153,7 @@ namespace Org.BouncyCastle.Crmf.Tests
IsTrue(archiveControl.EnvelopedData);
RecipientInformationStore recips = archiveControl.GetEnvelopedData().GetRecipientInfos();
- IList collection = (IList)recips.GetRecipients();
+ var collection = recips.GetRecipients();
IsTrue(collection.Count == 1);
KeyTransRecipientInformation info = (KeyTransRecipientInformation)collection[0];
diff --git a/crypto/test/src/crypto/prng/test/DrbgTestVector.cs b/crypto/test/src/crypto/prng/test/DrbgTestVector.cs
index b3f17e458..ca64dfa5b 100644
--- a/crypto/test/src/crypto/prng/test/DrbgTestVector.cs
+++ b/crypto/test/src/crypto/prng/test/DrbgTestVector.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using Org.BouncyCastle.Utilities.Encoders;
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Crypto.Prng.Test
private string _personalisation;
private int _ss;
private string[] _ev;
- private IList _ai = new ArrayList();
+ private IList<string> _ai = new List<string>();
public DrbgTestVector(IDigest digest, IEntropySource eSource, bool predictionResistance, string nonce,
int securityStrength, string[] expected)
diff --git a/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs b/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
index 4b48eab4f..3f3e04f7a 100644
--- a/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
+++ b/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
@@ -1,13 +1,10 @@
using System;
-using System.Collections;
using NUnit.Framework;
-using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Crypto.Parameters;
-using Org.BouncyCastle.Crypto.Tests;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Encoders;
diff --git a/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs b/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
index 7b4c0273a..bad1742ef 100644
--- a/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
+++ b/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using NUnit.Framework;
diff --git a/crypto/test/src/crypto/test/NistEccTest.cs b/crypto/test/src/crypto/test/NistEccTest.cs
index aaf4f666b..4269ef55d 100644
--- a/crypto/test/src/crypto/test/NistEccTest.cs
+++ b/crypto/test/src/crypto/test/NistEccTest.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
@@ -33,9 +33,9 @@ namespace Org.BouncyCastle.Crypto.Tests
}
}
- public IEnumerable CollectTestVectors()
+ public IEnumerable<object[]> CollectTestVectors()
{
- ArrayList testVectors = new ArrayList();
+ var testVectors = new List<object[]>();
string curve = null;
BigInteger k = null;
BigInteger x = null;
@@ -72,7 +72,7 @@ namespace Org.BouncyCastle.Crypto.Tests
if (null != curve && null != k && null != x && null != y)
{
- testVectors.Add(new object[] {curve, k, x, y});
+ testVectors.Add(new object[]{curve, k, x, y});
k = null;
x = null;
y = null;
diff --git a/crypto/test/src/crypto/test/cavp/CavpReader.cs b/crypto/test/src/crypto/test/cavp/CavpReader.cs
index dc32e0ff8..cbdaca155 100644
--- a/crypto/test/src/crypto/test/cavp/CavpReader.cs
+++ b/crypto/test/src/crypto/test/cavp/CavpReader.cs
@@ -1,31 +1,23 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
-using Org.BouncyCastle.Crypto.Digests;
-using Org.BouncyCastle.Crypto.Engines;
-using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.Utilities.Encoders;
using Org.BouncyCastle.Utilities.Test;
namespace Org.BouncyCastle.Crypto.Tests.Cavp
{
- internal class Vector : Hashtable
+ internal class Vector : Dictionary<string, object>
{
- private Hashtable mHeader = null;
+ private IDictionary<string, string> mHeader = null;
- public Vector(Hashtable header)
+ public Vector(IDictionary<string, string> header)
{
this.mHeader = header;
}
- public Hashtable Header
- {
- get { return mHeader; }
- set { this.mHeader = value; }
- }
-
public string ValueAsString(string name)
{
return this[name] as string;
@@ -33,7 +25,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
public string HeaderAsString(string name)
{
- return Header[name] as string;
+ return CollectionUtilities.GetValueOrNull(mHeader, name);
}
public byte[] ValueAsBytes(string name)
@@ -49,13 +41,8 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
public byte[] HeaderAsBytes(string name)
{
- string value = Header[name] as string;
- if (value != null)
- {
- return Hex.Decode(value);
- }
-
- return null;
+ string value = HeaderAsString(name);
+ return value == null ? null : Hex.Decode(value);
}
public int ValueAsInt(string name)
@@ -79,10 +66,10 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
internal class CavpReader
{
- public static ArrayList ReadVectorFile(string name)
+ public static IList<Vector> ReadVectorFile(string name)
{
- ArrayList vectors = new ArrayList();
- Hashtable header = null;
+ var vectors = new List<Vector>();
+ IDictionary<string, string> header = null;
Vector currentVector = null;
int headerState = 0;
@@ -148,7 +135,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
//
if (headerState == 0 && line.StartsWith("[") && line.EndsWith("]"))
{
- header = new Hashtable();
+ header = new Dictionary<string, string>();
headerState = 1;
}
diff --git a/crypto/test/src/crypto/test/cavp/KDFCounterTests.cs b/crypto/test/src/crypto/test/cavp/KDFCounterTests.cs
index 4cd20a93b..bce4c9516 100644
--- a/crypto/test/src/crypto/test/cavp/KDFCounterTests.cs
+++ b/crypto/test/src/crypto/test/cavp/KDFCounterTests.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using NUnit.Framework;
@@ -26,11 +26,11 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
public override void PerformTest()
{
string file = "KDFCTR_gen.rsp";
- ArrayList vectors = CavpReader.ReadVectorFile(file);
+ var vectors = CavpReader.ReadVectorFile(file);
ProcessVectors(file, vectors);
}
- private void ProcessVectors(string name, ArrayList vectors)
+ private void ProcessVectors(string name, IList<Vector> vectors)
{
foreach (Vector vector in vectors)
{
diff --git a/crypto/test/src/crypto/test/cavp/KDFDoublePipelineTests.cs b/crypto/test/src/crypto/test/cavp/KDFDoublePipelineTests.cs
index 7d1558ce9..a995db884 100644
--- a/crypto/test/src/crypto/test/cavp/KDFDoublePipelineTests.cs
+++ b/crypto/test/src/crypto/test/cavp/KDFDoublePipelineTests.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using NUnit.Framework;
@@ -28,7 +27,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
private void KdfDblPipelineNoCounterTest()
{
string file = "KDFDblPipelineNoCounter_gen.rsp";
- ArrayList vectors = CavpReader.ReadVectorFile(file);
+ var vectors = CavpReader.ReadVectorFile(file);
foreach (Vector vector in vectors)
{
@@ -53,7 +52,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
private void KdfDblPipelineCounterTest()
{
string file = "KDFDblPipelineCounter_gen.rsp";
- ArrayList vectors = CavpReader.ReadVectorFile(file);
+ var vectors = CavpReader.ReadVectorFile(file);
foreach (Vector vector in vectors)
{
diff --git a/crypto/test/src/crypto/test/cavp/KDFFeedbackCounterTests.cs b/crypto/test/src/crypto/test/cavp/KDFFeedbackCounterTests.cs
index 26789bf28..e734c99f0 100644
--- a/crypto/test/src/crypto/test/cavp/KDFFeedbackCounterTests.cs
+++ b/crypto/test/src/crypto/test/cavp/KDFFeedbackCounterTests.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using NUnit.Framework;
@@ -28,7 +27,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
private void KdfFeedbackNoCounterTest()
{
string file = "KDFFeedbackNoCounter_gen.rsp";
- ArrayList vectors = CavpReader.ReadVectorFile(file);
+ var vectors = CavpReader.ReadVectorFile(file);
foreach (Vector vector in vectors)
{
@@ -54,7 +53,7 @@ namespace Org.BouncyCastle.Crypto.Tests.Cavp
private void KdfFeedbackCounterTest()
{
string file = "KDFFeedbackCounter_gen.rsp";
- ArrayList vectors = CavpReader.ReadVectorFile(file);
+ var vectors = CavpReader.ReadVectorFile(file);
foreach (Vector vector in vectors)
{
diff --git a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
index dbbd0a328..419b022a7 100644
--- a/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
+++ b/crypto/test/src/math/ec/test/ECAlgorithmsTest.cs
@@ -1,12 +1,11 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using NUnit.Framework;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.EC;
using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities.Collections;
namespace Org.BouncyCastle.Math.EC.Tests
{
@@ -128,12 +127,12 @@ namespace Org.BouncyCastle.Math.EC.Tests
return new BigInteger(x9.N.BitLength, Random);
}
- private IList GetTestCurves()
+ private IList<X9ECParameters> GetTestCurves()
{
- ArrayList x9s = new ArrayList();
- ISet names = new HashSet(ECNamedCurveTable.Names);
- names.AddAll(CustomNamedCurves.Names);
+ var names = new HashSet<string>(ECNamedCurveTable.Names);
+ names.UnionWith(CustomNamedCurves.Names);
+ var x9s = new List<X9ECParameters>();
foreach (string name in names)
{
X9ECParameters x9 = ECNamedCurveTable.GetByName(name);
@@ -151,7 +150,7 @@ namespace Org.BouncyCastle.Math.EC.Tests
return x9s;
}
- private void AddTestCurves(IList x9s, X9ECParameters x9)
+ private void AddTestCurves(IList<X9ECParameters> x9s, X9ECParameters x9)
{
ECCurve curve = x9.Curve;
diff --git a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
index 059416427..18051226b 100644
--- a/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
+++ b/crypto/test/src/math/ec/test/ECPointPerformanceTest.cs
@@ -179,7 +179,7 @@ namespace Org.BouncyCastle.Math.EC.Tests
names.Sort();
- ISet oids = new HashSet();
+ var oids = new HashSet<DerObjectIdentifier>();
foreach (string name in names)
{
DerObjectIdentifier oid = ECNamedCurveTable.GetOid(name);
diff --git a/crypto/test/src/math/ec/test/ECPointTest.cs b/crypto/test/src/math/ec/test/ECPointTest.cs
index 4e3fc5832..7a833a413 100644
--- a/crypto/test/src/math/ec/test/ECPointTest.cs
+++ b/crypto/test/src/math/ec/test/ECPointTest.cs
@@ -7,7 +7,6 @@ using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.EC;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.Utilities.Encoders;
namespace Org.BouncyCastle.Math.EC.Tests
@@ -538,7 +537,7 @@ namespace Org.BouncyCastle.Math.EC.Tests
names.AddRange(ECNamedCurveTable.Names);
names.AddRange(CustomNamedCurves.Names);
- ISet uniqNames = new HashSet(names);
+ var uniqNames = new HashSet<string>(names);
foreach (string name in uniqNames)
{
diff --git a/crypto/test/src/math/ec/test/FixedPointTest.cs b/crypto/test/src/math/ec/test/FixedPointTest.cs
index 433f956da..bc90bdfc3 100644
--- a/crypto/test/src/math/ec/test/FixedPointTest.cs
+++ b/crypto/test/src/math/ec/test/FixedPointTest.cs
@@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Math.EC.Tests
names.AddRange(ECNamedCurveTable.Names);
names.AddRange(CustomNamedCurves.Names);
- ISet uniqNames = new HashSet(names);
+ var uniqNames = new HashSet<string>(names);
foreach (string name in uniqNames)
{
diff --git a/crypto/test/src/openpgp/test/IgnoreMarkerPacketInCertificatesTest.cs b/crypto/test/src/openpgp/test/IgnoreMarkerPacketInCertificatesTest.cs
index 7b845d077..71196edae 100644
--- a/crypto/test/src/openpgp/test/IgnoreMarkerPacketInCertificatesTest.cs
+++ b/crypto/test/src/openpgp/test/IgnoreMarkerPacketInCertificatesTest.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -71,12 +71,12 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
PgpPublicKeyRing certificate = (PgpPublicKeyRing)objectFactory.NextPgpObject();
IsEquals("Bob Babbage <bob@openpgp.example>", First(certificate.GetPublicKey().GetUserIds()));
- IEnumerable publicKeys = certificate.GetPublicKeys();
- IEnumerator publicKeyEnum = publicKeys.GetEnumerator();
+ var publicKeys = certificate.GetPublicKeys();
+ var publicKeyEnum = publicKeys.GetEnumerator();
IsTrue(publicKeyEnum.MoveNext());
PgpPublicKey primaryKey = (PgpPublicKey)publicKeyEnum.Current;
IsEquals(new BigInteger("FBFCC82A015E7330", 16).LongValue, primaryKey.KeyId);
- IEnumerable signatures = primaryKey.GetSignatures();
+ var signatures = primaryKey.GetSignatures();
IsEquals(1, Count(signatures));
IsTrue(publicKeyEnum.MoveNext());
@@ -94,19 +94,19 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
Assert.AreEqual(Name + ": Okay", resultText);
}
- private int Count(IEnumerable e)
+ private int Count<T>(IEnumerable<T> e)
{
int count = 0;
- foreach (object o in e)
+ foreach (T t in e)
{
++count;
}
return count;
}
- private object First(IEnumerable e)
+ private T First<T>(IEnumerable<T> e)
{
- IEnumerator enumerator = e.GetEnumerator();
+ var enumerator = e.GetEnumerator();
IsTrue(enumerator.MoveNext());
return enumerator.Current;
}
diff --git a/crypto/test/src/openpgp/test/PGPClearSignedSignatureTest.cs b/crypto/test/src/openpgp/test/PGPClearSignedSignatureTest.cs
index 98762fab1..a6f03c06f 100644
--- a/crypto/test/src/openpgp/test/PGPClearSignedSignatureTest.cs
+++ b/crypto/test/src/openpgp/test/PGPClearSignedSignatureTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.IO;
using System.Text;
@@ -264,10 +263,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
sGen.InitSign(PgpSignature.CanonicalTextDocument, pgpPrivKey);
- IEnumerator it = pgpSecKey.PublicKey.GetUserIds().GetEnumerator();
- if (it.MoveNext())
+ foreach (var userId in pgpSecKey.PublicKey.GetUserIds())
{
- spGen.SetSignerUserId(false, (string)it.Current);
+ spGen.SetSignerUserId(false, userId);
sGen.SetHashedSubpackets(spGen.Generate());
}
diff --git a/crypto/test/src/openpgp/test/PGPDSATest.cs b/crypto/test/src/openpgp/test/PGPDSATest.cs
index 104f5d494..d5ef8b5e9 100644
--- a/crypto/test/src/openpgp/test/PGPDSATest.cs
+++ b/crypto/test/src/openpgp/test/PGPDSATest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.IO;
using System.Text;
@@ -289,9 +288,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
PgpSignatureSubpacketGenerator spGen = new PgpSignatureSubpacketGenerator();
- IEnumerator enumerator = sKey.GetSecretKey().PublicKey.GetUserIds().GetEnumerator();
+ var enumerator = sKey.GetSecretKey().PublicKey.GetUserIds().GetEnumerator();
enumerator.MoveNext();
- string primaryUserId = (string) enumerator.Current;
+ string primaryUserId = enumerator.Current;
spGen.SetSignerUserId(true, primaryUserId);
diff --git a/crypto/test/src/openpgp/test/PGPRSATest.cs b/crypto/test/src/openpgp/test/PGPRSATest.cs
index 534fb8c5d..9d1dedd95 100644
--- a/crypto/test/src/openpgp/test/PGPRSATest.cs
+++ b/crypto/test/src/openpgp/test/PGPRSATest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.IO;
using System.Text;
@@ -539,14 +538,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
AsymmetricKeyParameter pubKey = pgpPub.GetPublicKey().GetKey();
- IEnumerator enumerator = pgpPub.GetPublicKey().GetUserIds().GetEnumerator();
- enumerator.MoveNext();
- string uid = (string) enumerator.Current;
+ var enumerator1= pgpPub.GetPublicKey().GetUserIds().GetEnumerator();
+ enumerator1.MoveNext();
+ string uid = enumerator1.Current;
- enumerator = pgpPub.GetPublicKey().GetSignaturesForId(uid).GetEnumerator();
- enumerator.MoveNext();
- PgpSignature sig = (PgpSignature) enumerator.Current;
+ var enumerator2 = pgpPub.GetPublicKey().GetSignaturesForId(uid).GetEnumerator();
+ enumerator2.MoveNext();
+ PgpSignature sig = enumerator2.Current;
sig.InitVerify(pgpPub.GetPublicKey());
@@ -830,14 +829,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
PgpPublicKey key = secretKey.PublicKey;
- enumerator = key.GetUserIds().GetEnumerator();
- enumerator.MoveNext();
- uid = (string) enumerator.Current;
+ var enumerator3 = key.GetUserIds().GetEnumerator();
+ enumerator3.MoveNext();
+ uid = enumerator3.Current;
- enumerator = key.GetSignaturesForId(uid).GetEnumerator();
- enumerator.MoveNext();
- sig = (PgpSignature) enumerator.Current;
+ var enumerator4 = key.GetSignaturesForId(uid).GetEnumerator();
+ enumerator4.MoveNext();
+ sig = enumerator4.Current;
sig.InitVerify(key);
@@ -875,9 +874,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
key = tmpRing.GetPublicKey();
- IEnumerator sgEnum = key.GetSignaturesOfType(PgpSignature.KeyRevocation).GetEnumerator();
+ var sgEnum = key.GetSignaturesOfType(PgpSignature.KeyRevocation).GetEnumerator();
sgEnum.MoveNext();
- sig = (PgpSignature) sgEnum.Current;
+ sig = sgEnum.Current;
sig.InitVerify(key);
@@ -926,14 +925,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
key.Encode(new UncloseableMemoryStream());
- enumerator = key.GetUserIds().GetEnumerator();
- enumerator.MoveNext();
- uid = (string) enumerator.Current;
+ var enumerator5 = key.GetUserIds().GetEnumerator();
+ enumerator5.MoveNext();
+ uid = enumerator5.Current;
- enumerator = key.GetSignaturesForId(uid).GetEnumerator();
- enumerator.MoveNext();
- sig = (PgpSignature) enumerator.Current;
+ var enumerator6 = key.GetSignaturesForId(uid).GetEnumerator();
+ enumerator6.MoveNext();
+ sig = enumerator6.Current;
sig.InitVerify(key);
diff --git a/crypto/test/src/openpgp/test/PgpECDHTest.cs b/crypto/test/src/openpgp/test/PgpECDHTest.cs
index 711d917a7..aa4fc2117 100644
--- a/crypto/test/src/openpgp/test/PgpECDHTest.cs
+++ b/crypto/test/src/openpgp/test/PgpECDHTest.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -249,9 +249,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
}
}
- private static object First(IEnumerable e)
+ private static T First<T>(IEnumerable<T> e)
{
- IEnumerator n = e.GetEnumerator();
+ var n = e.GetEnumerator();
Assert.IsTrue(n.MoveNext());
return n.Current;
}
diff --git a/crypto/test/src/openpgp/test/PgpECDsaTest.cs b/crypto/test/src/openpgp/test/PgpECDsaTest.cs
index 35e9a2332..c3611d5aa 100644
--- a/crypto/test/src/openpgp/test/PgpECDsaTest.cs
+++ b/crypto/test/src/openpgp/test/PgpECDsaTest.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -176,9 +176,9 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
}
}
- private static object First(IEnumerable e)
+ private static T First<T>(IEnumerable<T> e)
{
- IEnumerator n = e.GetEnumerator();
+ var n = e.GetEnumerator();
Assert.IsTrue(n.MoveNext());
return n.Current;
}
diff --git a/crypto/test/src/openpgp/test/PgpKeyRingTest.cs b/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
index efc47f881..a5dc4963b 100644
--- a/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
+++ b/crypto/test/src/openpgp/test/PgpKeyRingTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.IO;
using NUnit.Framework;
@@ -2511,7 +2510,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
foreach (PgpSecretKeyRing ring in secCol.GetKeyRings())
{
- IEnumerator e = ring.GetExtraPublicKeys().GetEnumerator();
+ var e = ring.GetExtraPublicKeys().GetEnumerator();
while (e.MoveNext())
{
++count;
@@ -2528,13 +2527,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests
byte[] keyRing)
{
PgpPublicKeyRing pubRing = new PgpPublicKeyRing(keyRing);
- IEnumerator en = pubRing.GetPublicKeys().GetEnumerator();
+ var en = pubRing.GetPublicKeys().GetEnumerator();
if (en.MoveNext())
{
PgpPublicKey key = (PgpPublicKey) en.Current;
- IEnumerator sEn = key.GetSignatures().GetEnumerator();
+ var sEn = key.GetSignatures().GetEnumerator();
if (sEn.MoveNext())
{
diff --git a/crypto/test/src/openpgp/test/PgpSignatureInvalidVersionIgnoredTest.cs b/crypto/test/src/openpgp/test/PgpSignatureInvalidVersionIgnoredTest.cs
index 1cd1385ba..ef64a464a 100644
--- a/crypto/test/src/openpgp/test/PgpSignatureInvalidVersionIgnoredTest.cs
+++ b/crypto/test/src/openpgp/test/PgpSignatureInvalidVersionIgnoredTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.IO;
using System.Text;
diff --git a/crypto/test/src/pkcs/test/PKCS10Test.cs b/crypto/test/src/pkcs/test/PKCS10Test.cs
index 39b33e1b5..949045c8a 100644
--- a/crypto/test/src/pkcs/test/PKCS10Test.cs
+++ b/crypto/test/src/pkcs/test/PKCS10Test.cs
@@ -1,4 +1,4 @@
-using System.Collections;
+using System;
using System.Collections.Generic;
using NUnit.Framework;
diff --git a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
index a500e5e63..731070c08 100644
--- a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
+++ b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
diff --git a/crypto/test/src/security/test/TestDotNetUtil.cs b/crypto/test/src/security/test/TestDotNetUtil.cs
index e2bb783ef..82cad46f1 100644
--- a/crypto/test/src/security/test/TestDotNetUtil.cs
+++ b/crypto/test/src/security/test/TestDotNetUtil.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using SystemX509 = System.Security.Cryptography.X509Certificates;
diff --git a/crypto/test/src/security/test/TestEncodings.cs b/crypto/test/src/security/test/TestEncodings.cs
index d83b2dda5..330054e84 100644
--- a/crypto/test/src/security/test/TestEncodings.cs
+++ b/crypto/test/src/security/test/TestEncodings.cs
@@ -1,15 +1,11 @@
using System;
-using System.Collections;
-using System.Text;
using NUnit.Framework;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
-using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Pkcs;
diff --git a/crypto/test/src/security/test/TestSignerUtil.cs b/crypto/test/src/security/test/TestSignerUtil.cs
index f075526b0..2c569d030 100644
--- a/crypto/test/src/security/test/TestSignerUtil.cs
+++ b/crypto/test/src/security/test/TestSignerUtil.cs
@@ -1,20 +1,13 @@
using System;
-using System.Collections;
-using System.Globalization;
-using System.Text;
using NUnit.Framework;
using Org.BouncyCastle.Asn1.CryptoPro;
-using Org.BouncyCastle.Asn1.Pkcs;
-using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
-using Org.BouncyCastle.Crypto.Signers;
-using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Encoders;
namespace Org.BouncyCastle.Security.Tests
@@ -142,11 +135,8 @@ namespace Org.BouncyCastle.Security.Tests
{
ISigner signer = SignerUtilities.GetSigner(algorithm);
-#if PORTABLE
string upper = algorithm.ToUpperInvariant();
-#else
- string upper = algorithm.ToUpper(CultureInfo.InvariantCulture);
-#endif
+
int withPos = upper.LastIndexOf("WITH");
string cipherName = withPos < 0
diff --git a/crypto/test/src/test/BlockCipherTest.cs b/crypto/test/src/test/BlockCipherTest.cs
index ff6f45e74..b57d62d94 100644
--- a/crypto/test/src/test/BlockCipherTest.cs
+++ b/crypto/test/src/test/BlockCipherTest.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
@@ -9,8 +10,6 @@ using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Collections;
using Org.BouncyCastle.Utilities.Encoders;
using Org.BouncyCastle.Utilities.Test;
@@ -24,8 +23,8 @@ namespace Org.BouncyCastle.Tests
public class BlockCipherTest
: SimpleTest
{
- private static readonly ISet validModes = CollectionUtilities.ReadOnly(
- new HashSet(new string[]{ "CBC", "CCM", "CFB", "CTR", "CTS", "EAX", "ECB", "GCM", "OCB", "OFB" }));
+ private static readonly ISet<string> ValidModes =
+ new HashSet<string>(){ "CBC", "CCM", "CFB", "CTR", "CTS", "EAX", "ECB", "GCM", "OCB", "OFB" };
private static readonly string[] cipherTests1 =
{
@@ -436,7 +435,7 @@ namespace Org.BouncyCastle.Tests
int pos = mode.IndexOfAny(new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
string baseMode = pos < 0 ? mode : mode.Substring(0, pos);
- if (!validModes.Contains(baseMode))
+ if (!ValidModes.Contains(baseMode))
throw new Exception("Unhandled mode: " + mode);
if (baseMode == "CCM")
diff --git a/crypto/test/src/test/CertPathTest.cs b/crypto/test/src/test/CertPathTest.cs
index 869ffd6a0..be1df89a7 100644
--- a/crypto/test/src/test/CertPathTest.cs
+++ b/crypto/test/src/test/CertPathTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
diff --git a/crypto/test/src/test/CertPathValidatorTest.cs b/crypto/test/src/test/CertPathValidatorTest.cs
index 88ffe7938..3c4577d59 100644
--- a/crypto/test/src/test/CertPathValidatorTest.cs
+++ b/crypto/test/src/test/CertPathValidatorTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index 7fb2c89c1..b286263a7 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -2485,7 +2484,7 @@ namespace Org.BouncyCastle.Tests
MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain.data")), false);
- ISet certs2 = new HashSet();
+ var certs2 = new HashSet<X509Certificate>();
while (input.Position < input.Length)
{
X509Certificate c = fact.ReadCertificate(input);
@@ -2499,7 +2498,7 @@ namespace Org.BouncyCastle.Tests
}
IsTrue("certs size <cr><nl>", certs1.Count == certs2.Count);
- certs2.RemoveAll(certs1);
+ certs2.ExceptWith(certs1);
IsTrue("collection not empty", certs2.Count == 0);
}
@@ -2523,7 +2522,7 @@ namespace Org.BouncyCastle.Tests
MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain_nl.data")), false);
- ISet certs2 = new HashSet();
+ var certs2 = new HashSet<X509Certificate>();
while (input.Position < input.Length)
{
X509Certificate c = fact.ReadCertificate(input);
@@ -2537,7 +2536,7 @@ namespace Org.BouncyCastle.Tests
}
IsTrue("certs size <nl>", certs1.Count == certs2.Count);
- certs2.RemoveAll(certs1);
+ certs2.ExceptWith(certs1);
IsTrue("collection not empty", certs2.Count == 0);
}
diff --git a/crypto/test/src/test/NamedCurveTest.cs b/crypto/test/src/test/NamedCurveTest.cs
index c5c3ca74e..7f5332adf 100644
--- a/crypto/test/src/test/NamedCurveTest.cs
+++ b/crypto/test/src/test/NamedCurveTest.cs
@@ -22,8 +22,10 @@ namespace Org.BouncyCastle.Tests
public class NamedCurveTest
: SimpleTest
{
-// private static readonly Hashtable CurveNames = new Hashtable();
-// private static readonly Hashtable CurveAliases = new Hashtable();
+// private static readonly Dictionary<string, sring> CurveNames =
+// new Dictionary<string, sring>(StringComparer.OrdinalIgnoreCase);
+// private static readonly Dictionary<string, sring> CurveAliases =
+// new Dictionary<string, sring>(StringComparer.OrdinalIgnoreCase);
//
// static NamedCurveTest()
// {
diff --git a/crypto/test/src/test/NistCertPathTest.cs b/crypto/test/src/test/NistCertPathTest.cs
index 42f9895e8..f859ada0a 100644
--- a/crypto/test/src/test/NistCertPathTest.cs
+++ b/crypto/test/src/test/NistCertPathTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Text;
@@ -72,7 +71,7 @@ namespace Org.BouncyCastle.Tests
private X509Crl trustedCRL;
private ISet<TrustAnchor> trustedSet;
private int testCount;
- private IList testFail;
+ private IList<string> testFail;
private StringBuilder resultBuf;
public override string Name
@@ -268,7 +267,7 @@ namespace Org.BouncyCastle.Tests
trustedSet.Add(new TrustAnchor(trustedCert, _ncBytes));
testCount = 0;
- testFail = new ArrayList();
+ testFail = new List<string>();
resultBuf = new StringBuilder("\n");
}
catch (Exception ex)
diff --git a/crypto/test/src/test/PKCS10CertRequestTest.cs b/crypto/test/src/test/PKCS10CertRequestTest.cs
index fb913d7de..1ec7c904e 100644
--- a/crypto/test/src/test/PKCS10CertRequestTest.cs
+++ b/crypto/test/src/test/PKCS10CertRequestTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
diff --git a/crypto/test/src/test/PkixPolicyMappingTest.cs b/crypto/test/src/test/PkixPolicyMappingTest.cs
index 5ca33bf6a..4dbfe0ad5 100644
--- a/crypto/test/src/test/PkixPolicyMappingTest.cs
+++ b/crypto/test/src/test/PkixPolicyMappingTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
diff --git a/crypto/test/src/test/PkixTest.cs b/crypto/test/src/test/PkixTest.cs
index 554d4c64f..5f321022c 100644
--- a/crypto/test/src/test/PkixTest.cs
+++ b/crypto/test/src/test/PkixTest.cs
@@ -1,7 +1,4 @@
using System;
-using System.IO;
-using System.Collections;
-using System.Text;
using NUnit.Framework;
diff --git a/crypto/test/src/test/X509StoreTest.cs b/crypto/test/src/test/X509StoreTest.cs
index 0a5fff6f1..aada53e4e 100644
--- a/crypto/test/src/test/X509StoreTest.cs
+++ b/crypto/test/src/test/X509StoreTest.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.IO;
using NUnit.Framework;
@@ -137,7 +135,7 @@ namespace Org.BouncyCastle.Tests
X509CrlStoreSelector targetConstraintsCRL = new X509CrlStoreSelector();
- ArrayList issuers = new ArrayList();
+ var issuers = new List<X509Name>();
issuers.Add(rootCrl.IssuerDN);
targetConstraintsCRL.Issuers = issuers;
diff --git a/crypto/test/src/test/nist/NistCertPathTest.cs b/crypto/test/src/test/nist/NistCertPathTest.cs
index 89565217c..4a6391e8f 100644
--- a/crypto/test/src/test/nist/NistCertPathTest.cs
+++ b/crypto/test/src/test/nist/NistCertPathTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -35,8 +34,8 @@ namespace Org.BouncyCastle.Tests.Nist
private static readonly string NIST_TEST_POLICY_2 = "2.16.840.1.101.3.2.1.48.2";
private static readonly string NIST_TEST_POLICY_3 = "2.16.840.1.101.3.2.1.48.3";
- private static readonly IDictionary certs = new Hashtable();
- private static readonly IDictionary crls = new Hashtable();
+ private static readonly Dictionary<string, X509Certificate> Certs = new Dictionary<string, X509Certificate>();
+ private static readonly Dictionary<string, X509Crl> Crls = new Dictionary<string, X509Crl>();
private static readonly HashSet<string> noPolicies = new HashSet<string>();
private static readonly HashSet<string> anyPolicy = new HashSet<string>();
@@ -758,52 +757,28 @@ namespace Org.BouncyCastle.Tests.Nist
private X509Certificate LoadCert(string certName)
{
- X509Certificate cert = (X509Certificate)certs[certName];
- if (null != cert)
- return cert;
+ if (Certs.TryGetValue(certName, out var cachedCert))
+ return cachedCert;
- Stream fs = null;
-
- try
- {
- fs = SimpleTest.GetTestDataAsStream("PKITS.certs." + certName + ".crt");
- cert = new X509CertificateParser().ReadCertificate(fs);
- certs[certName] = cert;
- return cert;
- }
- catch (Exception e)
- {
- throw new InvalidOperationException("exception loading certificate " + certName + ": " + e);
- }
- finally
+ using (Stream fs = SimpleTest.GetTestDataAsStream("PKITS.certs." + certName + ".crt"))
{
- fs.Close();
- }
+ var cert = new X509CertificateParser().ReadCertificate(fs);
+ Certs[certName] = cert;
+ return cert;
+ }
}
private X509Crl LoadCrl(string crlName)
{
- X509Crl crl = (X509Crl)crls[crlName];
- if (null != crl)
- return crl;
-
- Stream fs = null;
+ if (Crls.TryGetValue(crlName, out var cachedCrl))
+ return cachedCrl;
- try
- {
- fs = SimpleTest.GetTestDataAsStream("PKITS.crls." + crlName + ".crl");
- crl = new X509CrlParser().ReadCrl(fs);
- crls[crlName] = crl;
- return crl;
- }
- catch (Exception)
- {
- throw new InvalidOperationException("exception loading CRL: " + crlName);
- }
- finally
- {
- fs.Close();
- }
+ using (Stream fs = SimpleTest.GetTestDataAsStream("PKITS.crls." + crlName + ".crl"))
+ {
+ var crl = new X509CrlParser().ReadCrl(fs);
+ Crls[crlName] = crl;
+ return crl;
+ }
}
private TrustAnchor GetTrustAnchor(string trustAnchorName)
diff --git a/crypto/test/src/test/nist/NistCertPathTest2.cs b/crypto/test/src/test/nist/NistCertPathTest2.cs
index 244f9f9c5..1bc40e805 100644
--- a/crypto/test/src/test/nist/NistCertPathTest2.cs
+++ b/crypto/test/src/test/nist/NistCertPathTest2.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.IO;
using NUnit.Framework;
@@ -28,15 +26,16 @@ namespace Org.BouncyCastle.Tests.Nist
private static readonly string NIST_TEST_POLICY_2 = "2.16.840.1.101.3.2.1.48.2";
private static readonly string NIST_TEST_POLICY_3 = "2.16.840.1.101.3.2.1.48.3";
- private static readonly IDictionary certs = new Hashtable();
- private static readonly IDictionary crls = new Hashtable();
+ private static readonly IDictionary<string, X509Certificate> m_certs =
+ new Dictionary<string, X509Certificate>();
+ private static readonly IDictionary<string, X509Crl> m_crls = new Dictionary<string, X509Crl>();
- private static readonly ISet noPolicies = new HashSet();
- private static readonly ISet anyPolicy = new HashSet();
- private static readonly ISet nistTestPolicy1 = new HashSet();
- private static readonly ISet nistTestPolicy2 = new HashSet();
- private static readonly ISet nistTestPolicy3 = new HashSet();
- private static readonly ISet nistTestPolicy1And2 = new HashSet();
+ private static readonly ISet<string> noPolicies = new HashSet<string>();
+ private static readonly ISet<string> anyPolicy = new HashSet<string>();
+ private static readonly ISet<string> nistTestPolicy1 = new HashSet<string>();
+ private static readonly ISet<string> nistTestPolicy2 = new HashSet<string>();
+ private static readonly ISet<string> nistTestPolicy3 = new HashSet<string>();
+ private static readonly ISet<string> nistTestPolicy1And2 = new HashSet<string>();
static NistCertPathTest2()
{
@@ -425,52 +424,28 @@ namespace Org.BouncyCastle.Tests.Nist
private X509Certificate LoadCert(string certName)
{
- X509Certificate cert = (X509Certificate)certs[certName];
- if (null != cert)
- return cert;
+ if (m_certs.TryGetValue(certName, out var cachedCert))
+ return cachedCert;
- Stream fs = null;
-
- try
- {
- fs = SimpleTest.GetTestDataAsStream("PKITS.certs." + certName + ".crt");
- cert = new X509CertificateParser().ReadCertificate(fs);
- certs[certName] = cert;
- return cert;
- }
- catch (Exception e)
- {
- throw new InvalidOperationException("exception loading certificate " + certName + ": " + e);
- }
- finally
- {
- fs.Close();
- }
+ using (var fs = SimpleTest.GetTestDataAsStream("PKITS.certs." + certName + ".crt"))
+ {
+ var cert = new X509CertificateParser().ReadCertificate(fs);
+ m_certs[certName] = cert;
+ return cert;
+ }
}
private X509Crl LoadCrl(string crlName)
{
- X509Crl crl = (X509Crl)crls[crlName];
- if (null != crl)
- return crl;
+ if (m_crls.TryGetValue(crlName, out var cachedCrl))
+ return cachedCrl;
- Stream fs = null;
-
- try
- {
- fs = SimpleTest.GetTestDataAsStream("PKITS.crls." + crlName + ".crl");
- crl = new X509CrlParser().ReadCrl(fs);
- crls[crlName] = crl;
- return crl;
- }
- catch (Exception)
- {
- throw new InvalidOperationException("exception loading CRL: " + crlName);
- }
- finally
- {
- fs.Close();
- }
+ using (var fs = SimpleTest.GetTestDataAsStream("PKITS.crls." + crlName + ".crl"))
+ {
+ var crl = new X509CrlParser().ReadCrl(fs);
+ m_crls[crlName] = crl;
+ return crl;
+ }
}
private TrustAnchor GetTrustAnchor(string trustAnchorName)
diff --git a/crypto/test/src/tls/test/MockDatagramAssociation.cs b/crypto/test/src/tls/test/MockDatagramAssociation.cs
index 3e0c0f52b..ef317c7b6 100644
--- a/crypto/test/src/tls/test/MockDatagramAssociation.cs
+++ b/crypto/test/src/tls/test/MockDatagramAssociation.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Threading;
using Org.BouncyCastle.Utilities;
@@ -15,8 +15,8 @@ namespace Org.BouncyCastle.Tls.Tests
{
this.m_mtu = mtu;
- IList clientQueue = new ArrayList();
- IList serverQueue = new ArrayList();
+ var clientQueue = new List<byte[]>();
+ var serverQueue = new List<byte[]>();
this.m_client = new MockDatagramTransport(this, clientQueue, serverQueue);
this.m_server = new MockDatagramTransport(this, serverQueue, clientQueue);
@@ -36,9 +36,10 @@ namespace Org.BouncyCastle.Tls.Tests
: DatagramTransport
{
private readonly MockDatagramAssociation m_outer;
- private IList m_receiveQueue, m_sendQueue;
+ private IList<byte[]> m_receiveQueue, m_sendQueue;
- internal MockDatagramTransport(MockDatagramAssociation outer, IList receiveQueue, IList sendQueue)
+ internal MockDatagramTransport(MockDatagramAssociation outer, IList<byte[]> receiveQueue,
+ IList<byte[]> sendQueue)
{
this.m_outer = outer;
this.m_receiveQueue = receiveQueue;
@@ -74,7 +75,7 @@ namespace Org.BouncyCastle.Tls.Tests
return -1;
}
- byte[] packet = (byte[])m_receiveQueue[0];
+ byte[] packet = m_receiveQueue[0];
m_receiveQueue.RemoveAt(0);
int copyLength = System.Math.Min(len, packet.Length);
Array.Copy(packet, 0, buf, off, copyLength);
diff --git a/crypto/test/src/tsp/test/NewTspTest.cs b/crypto/test/src/tsp/test/NewTspTest.cs
index c188cb26a..f6d45ef09 100644
--- a/crypto/test/src/tsp/test/NewTspTest.cs
+++ b/crypto/test/src/tsp/test/NewTspTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
@@ -125,19 +124,19 @@ namespace Org.BouncyCastle.Tsp.Tests
try
{
- request.Validate(new ArrayList(), new ArrayList(), new ArrayList());
+ request.Validate(new List<string>(), new List<string>(), new List<string>());
Assert.Fail("expected exception");
} catch(Exception ex)
{
Assert.True("request contains unknown algorithm" == ex.Message);
}
- ArrayList algorithms = new ArrayList();
+ var algorithms = new List<string>();
algorithms.Add(TspAlgorithms.Sha1);
try
{
- request.Validate(algorithms, new ArrayList(), new ArrayList());
+ request.Validate(algorithms, new List<string>(), new List<string>());
Assert.Fail("no exception");
}
catch (Exception e)
@@ -145,14 +144,14 @@ namespace Org.BouncyCastle.Tsp.Tests
Assert.IsTrue(e.Message == "request contains unknown policy");
}
- ArrayList policies = new ArrayList();
+ var policies = new List<string>();
// Testing only do not use in real world.
policies.Add("2.5.29.56");
try
{
- request.Validate(algorithms, policies, new ArrayList());
+ request.Validate(algorithms, policies, new List<string>());
Assert.Fail("no exception");
}
catch (Exception e)
@@ -160,7 +159,7 @@ namespace Org.BouncyCastle.Tsp.Tests
Assert.IsTrue(e.Message == "request contains unknown extension");
}
- ArrayList extensions = new ArrayList();
+ var extensions = new List<string>();
// Testing only do not use in real world/
extensions.Add("1.3.6.1.5.5.7.1.2");
@@ -197,10 +196,10 @@ namespace Org.BouncyCastle.Tsp.Tests
TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
TimeStampRequest request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20]);
- ArrayList algorithms = new ArrayList();
+ var algorithms = new List<string>();
algorithms.Add(TspAlgorithms.Sha1);
- request.Validate(algorithms, new ArrayList(), new ArrayList());
+ request.Validate(algorithms, new List<string>(), new List<string>());
Assert.False(request.CertReq);
@@ -423,7 +422,8 @@ namespace Org.BouncyCastle.Tsp.Tests
reqGen.SetReqPolicy("1.1");
TimeStampRequest request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20]);
- TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed, new ArrayList());
+ TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed,
+ new List<string>());
TimeStampResponse tsResp = tsRespGen.Generate(request, BigInteger.ValueOf(23), DateTime.UtcNow);
diff --git a/crypto/test/src/tsp/test/TSPTest.cs b/crypto/test/src/tsp/test/TSPTest.cs
index 06c20e4bd..99e11046f 100644
--- a/crypto/test/src/tsp/test/TSPTest.cs
+++ b/crypto/test/src/tsp/test/TSPTest.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
@@ -267,7 +266,8 @@ namespace Org.BouncyCastle.Tsp.Tests
TimeStampRequest request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20]);
- TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed, new ArrayList());
+ TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed,
+ new List<string>());
TimeStampResponse tsResp = tsRespGen.Generate(request, BigInteger.ValueOf(23), DateTime.UtcNow);
diff --git a/crypto/test/src/tsp/test/TSPTestUtil.cs b/crypto/test/src/tsp/test/TSPTestUtil.cs
index 20eb7e228..abe153ac1 100644
--- a/crypto/test/src/tsp/test/TSPTestUtil.cs
+++ b/crypto/test/src/tsp/test/TSPTestUtil.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Text;
using Org.BouncyCastle.Asn1;
@@ -59,18 +59,18 @@ namespace Org.BouncyCastle.Tsp.Tests
public static readonly string EncryptionGost3410 = CryptoProObjectIdentifiers.GostR3410x94.Id;
public static readonly string EncryptionECGost3410 = CryptoProObjectIdentifiers.GostR3410x2001.Id;
- private static readonly IDictionary encryptionAlgs = new Hashtable();
- private static readonly IDictionary digestAlgs = new Hashtable();
- private static readonly IDictionary digestAliases = new Hashtable();
+ private static readonly Dictionary<string, string> EncryptionAlgs = new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> DigestAlgs = new Dictionary<string, string>();
+ private static readonly Dictionary<string, string[]> DigestAliases = new Dictionary<string, string[]>();
- private static readonly ISet noParams = new HashSet();
- private static readonly IDictionary ecAlgorithms = new Hashtable();
+ private static readonly ISet<string> NoParams = new HashSet<string>();
+ private static readonly Dictionary<string, string> ECAlgorithms = new Dictionary<string, string>();
private static void AddEntries(DerObjectIdentifier oid, string digest, string encryption)
{
string alias = oid.Id;
- digestAlgs.Add(alias, digest);
- encryptionAlgs.Add(alias, encryption);
+ DigestAlgs.Add(alias, digest);
+ EncryptionAlgs.Add(alias, encryption);
}
static TspTestUtil()
@@ -131,49 +131,49 @@ namespace Org.BouncyCastle.Tsp.Tests
AddEntries(EacObjectIdentifiers.id_TA_RSA_PSS_SHA_1, "SHA1", "RSAandMGF1");
AddEntries(EacObjectIdentifiers.id_TA_RSA_PSS_SHA_256, "SHA256", "RSAandMGF1");
- encryptionAlgs.Add(X9ObjectIdentifiers.IdDsa.Id, "DSA");
- encryptionAlgs.Add(PkcsObjectIdentifiers.RsaEncryption.Id, "RSA");
- encryptionAlgs.Add(TeleTrusTObjectIdentifiers.TeleTrusTRsaSignatureAlgorithm.Id, "RSA");
- encryptionAlgs.Add(X509ObjectIdentifiers.IdEARsa.Id, "RSA");
- encryptionAlgs.Add(EncryptionRsaPss, "RSAandMGF1");
- encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x94.Id, "GOST3410");
- encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x2001.Id, "ECGOST3410");
- encryptionAlgs.Add("1.3.6.1.4.1.5849.1.6.2", "ECGOST3410");
- encryptionAlgs.Add("1.3.6.1.4.1.5849.1.1.5", "GOST3410");
-
- digestAlgs.Add(PkcsObjectIdentifiers.MD2.Id, "MD2");
- digestAlgs.Add(PkcsObjectIdentifiers.MD4.Id, "MD4");
- digestAlgs.Add(PkcsObjectIdentifiers.MD5.Id, "MD5");
- digestAlgs.Add(OiwObjectIdentifiers.IdSha1.Id, "SHA1");
- digestAlgs.Add(NistObjectIdentifiers.IdSha224.Id, "SHA224");
- digestAlgs.Add(NistObjectIdentifiers.IdSha256.Id, "SHA256");
- digestAlgs.Add(NistObjectIdentifiers.IdSha384.Id, "SHA384");
- digestAlgs.Add(NistObjectIdentifiers.IdSha512.Id, "SHA512");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD128.Id, "RIPEMD128");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD160.Id, "RIPEMD160");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD256.Id, "RIPEMD256");
- digestAlgs.Add(CryptoProObjectIdentifiers.GostR3411.Id, "GOST3411");
- digestAlgs.Add("1.3.6.1.4.1.5849.1.2.1", "GOST3411");
-
- digestAliases.Add("SHA1", new string[] { "SHA-1" });
- digestAliases.Add("SHA224", new string[] { "SHA-224" });
- digestAliases.Add("SHA256", new string[] { "SHA-256" });
- digestAliases.Add("SHA384", new string[] { "SHA-384" });
- digestAliases.Add("SHA512", new string[] { "SHA-512" });
-
- noParams.Add(EncryptionDsa);
+ EncryptionAlgs.Add(X9ObjectIdentifiers.IdDsa.Id, "DSA");
+ EncryptionAlgs.Add(PkcsObjectIdentifiers.RsaEncryption.Id, "RSA");
+ EncryptionAlgs.Add(TeleTrusTObjectIdentifiers.TeleTrusTRsaSignatureAlgorithm.Id, "RSA");
+ EncryptionAlgs.Add(X509ObjectIdentifiers.IdEARsa.Id, "RSA");
+ EncryptionAlgs.Add(EncryptionRsaPss, "RSAandMGF1");
+ EncryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x94.Id, "GOST3410");
+ EncryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x2001.Id, "ECGOST3410");
+ EncryptionAlgs.Add("1.3.6.1.4.1.5849.1.6.2", "ECGOST3410");
+ EncryptionAlgs.Add("1.3.6.1.4.1.5849.1.1.5", "GOST3410");
+
+ DigestAlgs.Add(PkcsObjectIdentifiers.MD2.Id, "MD2");
+ DigestAlgs.Add(PkcsObjectIdentifiers.MD4.Id, "MD4");
+ DigestAlgs.Add(PkcsObjectIdentifiers.MD5.Id, "MD5");
+ DigestAlgs.Add(OiwObjectIdentifiers.IdSha1.Id, "SHA1");
+ DigestAlgs.Add(NistObjectIdentifiers.IdSha224.Id, "SHA224");
+ DigestAlgs.Add(NistObjectIdentifiers.IdSha256.Id, "SHA256");
+ DigestAlgs.Add(NistObjectIdentifiers.IdSha384.Id, "SHA384");
+ DigestAlgs.Add(NistObjectIdentifiers.IdSha512.Id, "SHA512");
+ DigestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD128.Id, "RIPEMD128");
+ DigestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD160.Id, "RIPEMD160");
+ DigestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD256.Id, "RIPEMD256");
+ DigestAlgs.Add(CryptoProObjectIdentifiers.GostR3411.Id, "GOST3411");
+ DigestAlgs.Add("1.3.6.1.4.1.5849.1.2.1", "GOST3411");
+
+ DigestAliases.Add("SHA1", new string[] { "SHA-1" });
+ DigestAliases.Add("SHA224", new string[] { "SHA-224" });
+ DigestAliases.Add("SHA256", new string[] { "SHA-256" });
+ DigestAliases.Add("SHA384", new string[] { "SHA-384" });
+ DigestAliases.Add("SHA512", new string[] { "SHA-512" });
+
+ NoParams.Add(EncryptionDsa);
//noParams.Add(EncryptionECDsa);
- noParams.Add(EncryptionECDsaWithSha1);
- noParams.Add(EncryptionECDsaWithSha224);
- noParams.Add(EncryptionECDsaWithSha256);
- noParams.Add(EncryptionECDsaWithSha384);
- noParams.Add(EncryptionECDsaWithSha512);
-
- ecAlgorithms.Add(DigestSha1, EncryptionECDsaWithSha1);
- ecAlgorithms.Add(DigestSha224, EncryptionECDsaWithSha224);
- ecAlgorithms.Add(DigestSha256, EncryptionECDsaWithSha256);
- ecAlgorithms.Add(DigestSha384, EncryptionECDsaWithSha384);
- ecAlgorithms.Add(DigestSha512, EncryptionECDsaWithSha512);
+ NoParams.Add(EncryptionECDsaWithSha1);
+ NoParams.Add(EncryptionECDsaWithSha224);
+ NoParams.Add(EncryptionECDsaWithSha256);
+ NoParams.Add(EncryptionECDsaWithSha384);
+ NoParams.Add(EncryptionECDsaWithSha512);
+
+ ECAlgorithms.Add(DigestSha1, EncryptionECDsaWithSha1);
+ ECAlgorithms.Add(DigestSha224, EncryptionECDsaWithSha224);
+ ECAlgorithms.Add(DigestSha256, EncryptionECDsaWithSha256);
+ ECAlgorithms.Add(DigestSha384, EncryptionECDsaWithSha384);
+ ECAlgorithms.Add(DigestSha512, EncryptionECDsaWithSha512);
}
public static string DumpBase64(
@@ -187,13 +187,12 @@ namespace Org.BouncyCastle.Tsp.Tests
{
if (i + 64 < data.Length)
{
- buf.Append(Encoding.ASCII.GetString(data, i, 64));
+ buf.AppendLine(Encoding.ASCII.GetString(data, i, 64));
}
else
{
- buf.Append(Encoding.ASCII.GetString(data, i, data.Length - i));
+ buf.AppendLine(Encoding.ASCII.GetString(data, i, data.Length - i));
}
- buf.Append('\n');
}
return buf.ToString();
@@ -201,33 +200,17 @@ namespace Org.BouncyCastle.Tsp.Tests
public static string GetDigestAlgName(string digestAlgOid)
{
- string algName = (string)digestAlgs[digestAlgOid];
-
- if (algName != null)
- {
- return algName;
- }
-
- return digestAlgOid;
+ return CollectionUtilities.GetValueOrKey(DigestAlgs, digestAlgOid);
}
public static string GetEncryptionAlgName(string encryptionAlgOid)
{
- string algName = (string)encryptionAlgs[encryptionAlgOid];
-
- if (algName != null)
- {
- return algName;
- }
-
- return encryptionAlgOid;
+ return CollectionUtilities.GetValueOrKey(EncryptionAlgs, encryptionAlgOid);
}
- internal static string GetEncOid(
- AsymmetricKeyParameter key,
- string digestOID)
+ internal static string GetEncOid(AsymmetricKeyParameter key, string digestOID)
{
- string encOID = null;
+ string encOID;
if (key is RsaKeyParameters)
{
@@ -275,9 +258,7 @@ namespace Org.BouncyCastle.Tsp.Tests
else
{
// TODO Should we insist on algName being one of "EC" or "ECDSA", as Java does?
- encOID = (string)ecAlgorithms[digestOID];
-
- if (encOID == null)
+ if (!ECAlgorithms.TryGetValue(digestOID, out encOID))
throw new ArgumentException("can't mix ECDSA with anything but SHA family digests");
}
}
diff --git a/crypto/test/src/util/io/pem/test/AllTests.cs b/crypto/test/src/util/io/pem/test/AllTests.cs
index 9a413450d..88ccf2e40 100644
--- a/crypto/test/src/util/io/pem/test/AllTests.cs
+++ b/crypto/test/src/util/io/pem/test/AllTests.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
@@ -14,20 +14,20 @@ namespace Org.BouncyCastle.Utilities.IO.Pem.Tests
{
for (int i = 1; i != 60; i++)
{
- LengthTest("CERTIFICATE", new ArrayList(), new byte[i]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[i]);
}
- LengthTest("CERTIFICATE", new ArrayList(), new byte[100]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[101]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[102]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[103]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[100]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[101]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[102]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[103]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[1000]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[1001]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[1002]);
- LengthTest("CERTIFICATE", new ArrayList(), new byte[1003]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[1000]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[1001]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[1002]);
+ LengthTest("CERTIFICATE", new List<PemHeader>(), new byte[1003]);
- IList headers = new ArrayList();
+ var headers = new List<PemHeader>();
headers.Add(new PemHeader("Proc-Type", "4,ENCRYPTED"));
headers.Add(new PemHeader("DEK-Info", "DES3,0001020304050607"));
LengthTest("RSA PRIVATE KEY", headers, new byte[103]);
@@ -48,7 +48,7 @@ namespace Org.BouncyCastle.Utilities.IO.Pem.Tests
}
}
- private void LengthTest(string type, IList headers, byte[] data)
+ private void LengthTest(string type, IList<PemHeader> headers, byte[] data)
{
StringWriter sw = new StringWriter();
PemWriter pWrt = new PemWriter(sw);
diff --git a/crypto/test/src/util/test/SimpleTest.cs b/crypto/test/src/util/test/SimpleTest.cs
index 1695164e5..91c493ef7 100644
--- a/crypto/test/src/util/test/SimpleTest.cs
+++ b/crypto/test/src/util/test/SimpleTest.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Reflection;
@@ -148,7 +148,7 @@ namespace Org.BouncyCastle.Utilities.Test
{
string fullPrefix = GetFullName(prefix);
- ArrayList result = new ArrayList();
+ var result = new List<string>();
string[] fullNames = GetAssembly().GetManifestResourceNames();
foreach (string fullName in fullNames)
{
@@ -158,7 +158,7 @@ namespace Org.BouncyCastle.Utilities.Test
result.Add(name);
}
}
- return (string[])result.ToArray(typeof(string));
+ return result.ToArray();
}
private static Assembly GetAssembly()
diff --git a/crypto/test/src/x509/test/TestCertificateGen.cs b/crypto/test/src/x509/test/TestCertificateGen.cs
index d1ac173bc..f4dc5cc01 100644
--- a/crypto/test/src/x509/test/TestCertificateGen.cs
+++ b/crypto/test/src/x509/test/TestCertificateGen.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
|