summary refs log tree commit diff
path: root/crypto/src/asn1
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 02:19:14 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-27 02:19:14 +0700
commit4ea1816cffd5c8663bc9ae1234df0a70ef23fcd6 (patch)
treeeb4fe294ef230435928a573fadef3047b4466e9b /crypto/src/asn1
parentImplement generic IEnumerable in ASN.1 classes (diff)
downloadBouncyCastle.NET-ed25519-4ea1816cffd5c8663bc9ae1234df0a70ef23fcd6.tar.xz
Generics migration work
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r--crypto/src/asn1/anssi/ANSSINamedCurves.cs6
-rw-r--r--crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs6
-rw-r--r--crypto/src/asn1/cryptopro/GOST3410NamedParameters.cs4
-rw-r--r--crypto/src/asn1/gm/GMNamedCurves.cs6
-rw-r--r--crypto/src/asn1/nist/NISTNamedCurves.cs4
-rw-r--r--crypto/src/asn1/sec/SECNamedCurves.cs6
-rw-r--r--crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs6
-rw-r--r--crypto/src/asn1/x509/V2TBSCertListGenerator.cs23
-rw-r--r--crypto/src/asn1/x509/X509Extensions.cs118
-rw-r--r--crypto/src/asn1/x509/X509ExtensionsGenerator.cs68
-rw-r--r--crypto/src/asn1/x9/X962NamedCurves.cs6
11 files changed, 106 insertions, 147 deletions
diff --git a/crypto/src/asn1/anssi/ANSSINamedCurves.cs b/crypto/src/asn1/anssi/ANSSINamedCurves.cs
index ed1faa75c..2e164989a 100644
--- a/crypto/src/asn1/anssi/ANSSINamedCurves.cs
+++ b/crypto/src/asn1/anssi/ANSSINamedCurves.cs
@@ -116,21 +116,21 @@ namespace Org.BouncyCastle.Asn1.Anssi
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs b/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs
index ec297f7a1..8e0f55001 100644
--- a/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs
+++ b/crypto/src/asn1/cryptopro/ECGOST3410NamedCurves.cs
@@ -369,21 +369,21 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/cryptopro/GOST3410NamedParameters.cs b/crypto/src/asn1/cryptopro/GOST3410NamedParameters.cs
index 2d183a4f9..cd0ab1a80 100644
--- a/crypto/src/asn1/cryptopro/GOST3410NamedParameters.cs
+++ b/crypto/src/asn1/cryptopro/GOST3410NamedParameters.cs
@@ -88,7 +88,7 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the parameter set.</param>
         public static Gost3410ParamSetParameters GetByOid(DerObjectIdentifier oid)
         {
-            return parameters.TryGetValue(oid, out var parameterSet) ? parameterSet : null;
+            return CollectionUtilities.GetValueOrNull(parameters, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the parameter set with the given name.
@@ -96,7 +96,7 @@ namespace Org.BouncyCastle.Asn1.CryptoPro
         /// <param name="name">The name of the parameter set.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available parameter set names in this registry.</summary>
diff --git a/crypto/src/asn1/gm/GMNamedCurves.cs b/crypto/src/asn1/gm/GMNamedCurves.cs
index fec0c1401..764b031ed 100644
--- a/crypto/src/asn1/gm/GMNamedCurves.cs
+++ b/crypto/src/asn1/gm/GMNamedCurves.cs
@@ -147,21 +147,21 @@ namespace Org.BouncyCastle.Asn1.GM
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/nist/NISTNamedCurves.cs b/crypto/src/asn1/nist/NISTNamedCurves.cs
index a8bc56549..b9307c879 100644
--- a/crypto/src/asn1/nist/NISTNamedCurves.cs
+++ b/crypto/src/asn1/nist/NISTNamedCurves.cs
@@ -89,14 +89,14 @@ namespace Org.BouncyCastle.Asn1.Nist
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/sec/SECNamedCurves.cs b/crypto/src/asn1/sec/SECNamedCurves.cs
index c0a783ec6..8a97af388 100644
--- a/crypto/src/asn1/sec/SECNamedCurves.cs
+++ b/crypto/src/asn1/sec/SECNamedCurves.cs
@@ -1248,21 +1248,21 @@ namespace Org.BouncyCastle.Asn1.Sec
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
index b863babce..5edb24045 100644
--- a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
+++ b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
@@ -527,21 +527,21 @@ namespace Org.BouncyCastle.Asn1.TeleTrust
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>
diff --git a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs
index 2c929188f..1d58751fd 100644
--- a/crypto/src/asn1/x509/V2TBSCertListGenerator.cs
+++ b/crypto/src/asn1/x509/V2TBSCertListGenerator.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 
 using Org.BouncyCastle.Utilities;
@@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1.X509
         private X509Name			issuer;
         private Time				thisUpdate, nextUpdate;
         private X509Extensions		extensions;
-        private IList			    crlEntries;
+        private List<Asn1Sequence>  crlEntries;
 
 		public V2TbsCertListGenerator()
         {
@@ -80,12 +80,11 @@ namespace Org.BouncyCastle.Asn1.X509
             this.nextUpdate = nextUpdate;
         }
 
-		public void AddCrlEntry(
-			Asn1Sequence crlEntry)
+		public void AddCrlEntry(Asn1Sequence crlEntry)
 		{
 			if (crlEntries == null)
 			{
-				crlEntries = Platform.CreateArrayList();
+                crlEntries = new List<Asn1Sequence>();
 			}
 
 			crlEntries.Add(crlEntry);
@@ -104,8 +103,8 @@ namespace Org.BouncyCastle.Asn1.X509
 		public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason,
 			DerGeneralizedTime invalidityDate)
 		{
-            IList extOids = Platform.CreateArrayList();
-            IList extValues = Platform.CreateArrayList();
+            var extOids = new List<DerObjectIdentifier>();
+            var extValues = new List<X509Extension>();
 
 			if (reason != 0)
 			{
@@ -147,8 +146,7 @@ namespace Org.BouncyCastle.Asn1.X509
 
 		public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, X509Extensions extensions)
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(
-				userCertificate, revocationDate);
+			Asn1EncodableVector v = new Asn1EncodableVector(userCertificate, revocationDate);
 
 			if (extensions != null)
 			{
@@ -182,12 +180,7 @@ namespace Org.BouncyCastle.Asn1.X509
 			// Add CRLEntries if they exist
             if (crlEntries != null)
             {
-                Asn1Sequence[] certs = new Asn1Sequence[crlEntries.Count];
-                for (int i = 0; i < crlEntries.Count; ++i)
-                {
-                    certs[i] = (Asn1Sequence)crlEntries[i];
-                }
-				v.Add(new DerSequence(certs));
+				v.Add(new DerSequence(crlEntries.ToArray()));
             }
 
 			if (extensions != null)
diff --git a/crypto/src/asn1/x509/X509Extensions.cs b/crypto/src/asn1/x509/X509Extensions.cs
index b01db1fb5..a399058c2 100644
--- a/crypto/src/asn1/x509/X509Extensions.cs
+++ b/crypto/src/asn1/x509/X509Extensions.cs
@@ -1,5 +1,5 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
@@ -169,8 +169,9 @@ namespace Org.BouncyCastle.Asn1.X509
          */
         public static readonly DerObjectIdentifier ExpiredCertsOnCrl = new DerObjectIdentifier("2.5.29.60");
 
-        private readonly IDictionary extensions = Platform.CreateHashtable();
-        private readonly IList ordering;
+        private readonly Dictionary<DerObjectIdentifier, X509Extension> m_extensions =
+            new Dictionary<DerObjectIdentifier, X509Extension>();
+        private readonly List<DerObjectIdentifier> m_ordering;
 
         public static X509Extension GetExtension(X509Extensions extensions, DerObjectIdentifier oid)
         {
@@ -182,11 +183,9 @@ namespace Org.BouncyCastle.Asn1.X509
             return null == extensions ? null : extensions.GetExtensionParsedValue(oid);
         }
 
-		public static X509Extensions GetInstance(
-            Asn1TaggedObject	obj,
-            bool				explicitly)
+		public static X509Extensions GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
+            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
 		public static X509Extensions GetInstance(
@@ -215,10 +214,9 @@ namespace Org.BouncyCastle.Asn1.X509
          *
          * the extensions are a list of constructed sequences, either with (Oid, OctetString) or (Oid, Boolean, OctetString)
          */
-        private X509Extensions(
-            Asn1Sequence seq)
+        private X509Extensions(Asn1Sequence seq)
         {
-            this.ordering = Platform.CreateArrayList();
+            m_ordering = new List<DerObjectIdentifier>();
 
 			foreach (Asn1Encodable ae in seq)
 			{
@@ -234,11 +232,11 @@ namespace Org.BouncyCastle.Asn1.X509
 
 				Asn1OctetString octets = Asn1OctetString.GetInstance(s[s.Count - 1].ToAsn1Object());
 
-                if (extensions.Contains(oid))
+                if (m_extensions.ContainsKey(oid))
                     throw new ArgumentException("repeated extension found: " + oid);
 
-                extensions.Add(oid, new X509Extension(isCritical, octets));
-				ordering.Add(oid);
+                m_extensions.Add(oid, new X509Extension(isCritical, octets));
+				m_ordering.Add(oid);
 			}
         }
 
@@ -247,8 +245,7 @@ namespace Org.BouncyCastle.Asn1.X509
          * <p>
          * it's is assumed the table contains Oid/string pairs.</p>
          */
-        public X509Extensions(
-            IDictionary extensions)
+        public X509Extensions(IDictionary<DerObjectIdentifier, X509Extension> extensions)
             : this(null, extensions)
         {
         }
@@ -258,22 +255,21 @@ namespace Org.BouncyCastle.Asn1.X509
          * <p>
          * It's is assumed the table contains Oid/string pairs.</p>
          */
-        public X509Extensions(
-            IList       ordering,
-            IDictionary extensions)
+        public X509Extensions(IList<DerObjectIdentifier> ordering,
+            IDictionary<DerObjectIdentifier, X509Extension> extensions)
         {
             if (ordering == null)
             {
-                this.ordering = Platform.CreateArrayList(extensions.Keys);
+                m_ordering = new List<DerObjectIdentifier>(extensions.Keys);
             }
             else
             {
-                this.ordering = Platform.CreateArrayList(ordering);
+                m_ordering = new List<DerObjectIdentifier>(ordering);
             }
 
-            foreach (DerObjectIdentifier oid in this.ordering)
+            foreach (DerObjectIdentifier oid in m_ordering)
             {
-                this.extensions.Add(oid, (X509Extension)extensions[oid]);
+                m_extensions.Add(oid, extensions[oid]);
             }
         }
 
@@ -283,25 +279,23 @@ namespace Org.BouncyCastle.Asn1.X509
          * @param objectIDs an ArrayList of the object identifiers.
          * @param values an ArrayList of the extension values.
          */
-        public X509Extensions(
-            IList oids,
-            IList values)
+        public X509Extensions(IList<DerObjectIdentifier> oids, IList<X509Extension> values)
         {
-            this.ordering = Platform.CreateArrayList(oids);
+            m_ordering = new List<DerObjectIdentifier>(oids);
 
             int count = 0;
-            foreach (DerObjectIdentifier oid in this.ordering)
+            foreach (DerObjectIdentifier oid in m_ordering)
             {
-                this.extensions.Add(oid, (X509Extension)values[count++]);
+                m_extensions.Add(oid, values[count++]);
             }
         }
 
 		/**
 		 * return an Enumeration of the extension field's object ids.
 		 */
-		public IEnumerable ExtensionOids
+		public IEnumerable<DerObjectIdentifier> ExtensionOids
         {
-			get { return new EnumerableProxy(ordering); }
+			get { return CollectionUtilities.Proxy(m_ordering); }
         }
 
 		/**
@@ -310,10 +304,9 @@ namespace Org.BouncyCastle.Asn1.X509
          *
          * @return the extension if it's present, null otherwise.
          */
-        public X509Extension GetExtension(
-            DerObjectIdentifier oid)
+        public X509Extension GetExtension(DerObjectIdentifier oid)
         {
-             return (X509Extension)extensions[oid];
+            return CollectionUtilities.GetValueOrNull(m_extensions, oid);
         }
 
         /**
@@ -324,9 +317,7 @@ namespace Org.BouncyCastle.Asn1.X509
          */
         public Asn1Encodable GetExtensionParsedValue(DerObjectIdentifier oid)
         {
-            X509Extension ext = GetExtension(oid);
-
-            return ext == null ? null : ext.GetParsedValue();
+            return GetExtension(oid)?.GetParsedValue();
         }
 
 		/**
@@ -341,44 +332,41 @@ namespace Org.BouncyCastle.Asn1.X509
 		 */
 		public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector	vec = new Asn1EncodableVector();
+            Asn1EncodableVector	v = new Asn1EncodableVector(m_ordering.Count);
 
-			foreach (DerObjectIdentifier oid in ordering)
+			foreach (DerObjectIdentifier oid in m_ordering)
 			{
-                X509Extension ext = (X509Extension) extensions[oid];
-                Asn1EncodableVector	v = new Asn1EncodableVector(oid);
-
-				if (ext.IsCritical)
+                X509Extension ext = m_extensions[oid];
+                if (ext.IsCritical)
                 {
-                    v.Add(DerBoolean.True);
+                    v.Add(new DerSequence(oid, DerBoolean.True, ext.Value));
+                }
+                else
+                {
+                    v.Add(new DerSequence(oid, ext.Value));
                 }
-
-				v.Add(ext.Value);
-
-				vec.Add(new DerSequence(v));
             }
 
-			return new DerSequence(vec);
+			return new DerSequence(v);
         }
 
-		public bool Equivalent(
-			X509Extensions other)
+		public bool Equivalent(X509Extensions other)
 		{
-			if (extensions.Count != other.extensions.Count)
+			if (m_extensions.Count != other.m_extensions.Count)
 				return false;
 
-			foreach (DerObjectIdentifier oid in extensions.Keys)
-			{
-				if (!extensions[oid].Equals(other.extensions[oid]))
-					return false;
-			}
+            foreach (var entry in m_extensions)
+            {
+                if (!entry.Value.Equals(other.GetExtension(entry.Key)))
+                    return false;
+            }
 
 			return true;
 		}
 
 		public DerObjectIdentifier[] GetExtensionOids()
 		{
-			return ToOidArray(ordering);
+            return m_ordering.ToArray();
 		}
 
 		public DerObjectIdentifier[] GetNonCriticalExtensionOids()
@@ -393,25 +381,17 @@ namespace Org.BouncyCastle.Asn1.X509
 
 		private DerObjectIdentifier[] GetExtensionOids(bool isCritical)
 		{
-			IList oids = Platform.CreateArrayList();
+			var oids = new List<DerObjectIdentifier>();
 
-			foreach (DerObjectIdentifier oid in this.ordering)
+			foreach (DerObjectIdentifier oid in m_ordering)
             {
-				X509Extension ext = (X509Extension)extensions[oid];
-				if (ext.IsCritical == isCritical)
+				if (m_extensions[oid].IsCritical == isCritical)
 				{
 					oids.Add(oid);
 				}
             }
 
-			return ToOidArray(oids);
-		}
-
-		private static DerObjectIdentifier[] ToOidArray(IList oids)
-		{
-			DerObjectIdentifier[] oidArray = new DerObjectIdentifier[oids.Count];
-			oids.CopyTo(oidArray, 0);
-			return oidArray;
+            return oids.ToArray();
 		}
 	}
 }
diff --git a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
index 3b952fffa..438c507aa 100644
--- a/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
+++ b/crypto/src/asn1/x509/X509ExtensionsGenerator.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Utilities;
 
@@ -8,8 +9,9 @@ namespace Org.BouncyCastle.Asn1.X509
     /// <remarks>Generator for X.509 extensions</remarks>
     public class X509ExtensionsGenerator
     {
-        private IDictionary extensions = Platform.CreateHashtable();
-        private IList extOrdering = Platform.CreateArrayList();
+        private Dictionary<DerObjectIdentifier, X509Extension> m_extensions =
+            new Dictionary<DerObjectIdentifier, X509Extension>();
+        private List<DerObjectIdentifier> m_ordering = new List<DerObjectIdentifier>();
 
         private static readonly IDictionary dupsAllowed = Platform.CreateHashtable();
 
@@ -19,16 +21,13 @@ namespace Org.BouncyCastle.Asn1.X509
             dupsAllowed.Add(X509Extensions.IssuerAlternativeName, true);
             dupsAllowed.Add(X509Extensions.SubjectDirectoryAttributes, true);
             dupsAllowed.Add(X509Extensions.CertificateIssuer, true);
-
         }
 
-
-
         /// <summary>Reset the generator</summary>
         public void Reset()
         {
-            extensions = Platform.CreateHashtable();
-            extOrdering = Platform.CreateArrayList();
+            m_extensions = new Dictionary<DerObjectIdentifier, X509Extension>();
+            m_ordering = new List<DerObjectIdentifier>();
         }
 
         /// <summary>
@@ -38,10 +37,7 @@ namespace Org.BouncyCastle.Asn1.X509
         /// <param name="oid">OID for the extension.</param>
         /// <param name="critical">True if critical, false otherwise.</param>
         /// <param name="extValue">The ASN.1 object to be included in the extension.</param>
-        public void AddExtension(
-            DerObjectIdentifier oid,
-            bool critical,
-            Asn1Encodable extValue)
+        public void AddExtension(DerObjectIdentifier oid, bool critical, Asn1Encodable extValue)
         {
             byte[] encoded;
             try
@@ -63,38 +59,30 @@ namespace Org.BouncyCastle.Asn1.X509
         /// <param name="oid">OID for the extension.</param>
         /// <param name="critical">True if critical, false otherwise.</param>
         /// <param name="extValue">The byte array to be wrapped.</param>
-        public void AddExtension(
-            DerObjectIdentifier oid,
-            bool critical,
-            byte[] extValue)
+        public void AddExtension(DerObjectIdentifier oid, bool critical, byte[] extValue)
         {
-            if (extensions.Contains(oid))
+            if (m_extensions.TryGetValue(oid, out X509Extension existingExtension))
             {
-                if (dupsAllowed.Contains(oid))
-                {
-                    X509Extension existingExtension = (X509Extension)extensions[oid];
-
-                    Asn1Sequence seq1 = Asn1Sequence.GetInstance(DerOctetString.GetInstance(existingExtension.Value).GetOctets());
-                    Asn1EncodableVector items = Asn1EncodableVector.FromEnumerable(seq1);
-                    Asn1Sequence seq2 = Asn1Sequence.GetInstance(extValue);
-
-                    foreach (Asn1Encodable enc in seq2)
-                    {
-                        items.Add(enc);
-                    }
+                if (!dupsAllowed.Contains(oid))
+                    throw new ArgumentException("extension " + oid + " already added");
 
-                    extensions[oid] = new X509Extension(existingExtension.IsCritical, new DerOctetString(new DerSequence(items).GetEncoded()));
+                Asn1Sequence seq1 = Asn1Sequence.GetInstance(
+                    Asn1OctetString.GetInstance(existingExtension.Value).GetOctets());
+                Asn1EncodableVector items = Asn1EncodableVector.FromEnumerable(seq1);
+                Asn1Sequence seq2 = Asn1Sequence.GetInstance(extValue);
 
-                }
-                else
+                foreach (Asn1Encodable enc in seq2)
                 {
-                    throw new ArgumentException("extension " + oid + " already added");
+                    items.Add(enc);
                 }
+
+                m_extensions[oid] = new X509Extension(existingExtension.IsCritical,
+                    new DerOctetString(new DerSequence(items).GetEncoded()));
             }
             else
             {
-                extOrdering.Add(oid);
-                extensions.Add(oid, new X509Extension(critical, new DerOctetString(extValue)));
+                m_ordering.Add(oid);
+                m_extensions.Add(oid, new X509Extension(critical, new DerOctetString(extValue)));
             }
         }
 
@@ -113,25 +101,23 @@ namespace Org.BouncyCastle.Asn1.X509
         /// <returns>True if empty, false otherwise</returns>
         public bool IsEmpty
         {
-            get { return extOrdering.Count < 1; }
+            get { return m_ordering.Count < 1; }
         }
 
         /// <summary>Generate an X509Extensions object based on the current state of the generator.</summary>
         /// <returns>An <c>X509Extensions</c> object</returns>
         public X509Extensions Generate()
         {
-            return new X509Extensions(extOrdering, extensions);
+            return new X509Extensions(m_ordering, m_extensions);
         }
 
         internal void AddExtension(DerObjectIdentifier oid, X509Extension x509Extension)
         {
-            if (extensions.Contains(oid))
-            {
+            if (m_extensions.ContainsKey(oid))
                 throw new ArgumentException("extension " + oid + " already added");
-            }
 
-            extOrdering.Add(oid);
-            extensions.Add(oid, x509Extension);
+            m_ordering.Add(oid);
+            m_extensions.Add(oid, x509Extension);
         }
     }
 }
diff --git a/crypto/src/asn1/x9/X962NamedCurves.cs b/crypto/src/asn1/x9/X962NamedCurves.cs
index e0fb625f9..893371fd4 100644
--- a/crypto/src/asn1/x9/X962NamedCurves.cs
+++ b/crypto/src/asn1/x9/X962NamedCurves.cs
@@ -836,21 +836,21 @@ namespace Org.BouncyCastle.Asn1.X9
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return curves.TryGetValue(oid, out var holder) ? holder : null;
+            return CollectionUtilities.GetValueOrNull(curves, oid);
         }
 
         /// <summary>Look up the name of the curve with the given <see cref="DerObjectIdentifier">OID</see>.</summary>
         /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static string GetName(DerObjectIdentifier oid)
         {
-            return names.TryGetValue(oid, out var name) ? name : null;
+            return CollectionUtilities.GetValueOrNull(names, oid);
         }
 
         /// <summary>Look up the <see cref="DerObjectIdentifier">OID</see> of the curve with the given name.</summary>
         /// <param name="name">The name of the curve.</param>
         public static DerObjectIdentifier GetOid(string name)
         {
-            return objIds.TryGetValue(name, out var oid) ? oid : null;
+            return CollectionUtilities.GetValueOrNull(objIds, name);
         }
 
         /// <summary>Enumerate the available curve names in this registry.</summary>