summary refs log tree commit diff
path: root/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs')
-rw-r--r--crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs97
1 files changed, 44 insertions, 53 deletions
diff --git a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
index dcc160016..b863babce 100644
--- a/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
+++ b/crypto/src/asn1/teletrust/TeleTrusTNamedCurves.cs
@@ -1,20 +1,18 @@
-using System.Collections;
+using System;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Math.EC;
 using Org.BouncyCastle.Math.EC.Multiplier;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
 using Org.BouncyCastle.Utilities.Encoders;
 
 namespace Org.BouncyCastle.Asn1.TeleTrust
 {
-    /**
-    * elliptic curves defined in "ECC Brainpool Standard Curves and Curve Generation"
-    * http://www.ecc-brainpool.org/download/draft_pkix_additional_ecc_dp.txt
-    */
-    public class TeleTrusTNamedCurves
+    /// <summary>Elliptic curve registry for curves defined in "ECC Brainpool Standard Curves and Curve Generation"
+    /// http://www.ecc-brainpool.org/download/draft_pkix_additional_ecc_dp.txt .</summary>
+    public static class TeleTrusTNamedCurves
     {
         private static X9ECPoint ConfigureBasepoint(ECCurve curve, string encoding)
         {
@@ -460,17 +458,16 @@ namespace Org.BouncyCastle.Asn1.TeleTrust
             }
         }
 
+        private static readonly Dictionary<string, DerObjectIdentifier> objIds =
+            new Dictionary<string, DerObjectIdentifier>(StringComparer.OrdinalIgnoreCase);
+        private static readonly Dictionary<DerObjectIdentifier, X9ECParametersHolder> curves =
+            new Dictionary<DerObjectIdentifier, X9ECParametersHolder>();
+        private static readonly Dictionary<DerObjectIdentifier, string> names =
+            new Dictionary<DerObjectIdentifier, string>();
 
-        private static readonly IDictionary objIds = Platform.CreateHashtable();
-        private static readonly IDictionary curves = Platform.CreateHashtable();
-        private static readonly IDictionary names = Platform.CreateHashtable();
-
-        private static void DefineCurve(
-            string					name,
-            DerObjectIdentifier		oid,
-            X9ECParametersHolder	holder)
+        private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
         {
-            objIds.Add(Platform.ToUpperInvariant(name), oid);
+            objIds.Add(name, oid);
             names.Add(oid, name);
             curves.Add(oid, holder);
         }
@@ -493,70 +490,64 @@ namespace Org.BouncyCastle.Asn1.TeleTrust
             DefineCurve("brainpoolP512t1", TeleTrusTObjectIdentifiers.BrainpoolP512T1, BrainpoolP512t1Holder.Instance);
         }
 
+        /// <summary>Look up the <see cref="X9ECParameters"/> for the curve with the given name.</summary>
+        /// <param name="name">The name of the curve.</param>
         public static X9ECParameters GetByName(string name)
         {
             DerObjectIdentifier oid = GetOid(name);
             return oid == null ? null : GetByOid(oid);
         }
 
+        /// <summary>Look up an <see cref="X9ECParametersHolder"/> for the curve with the given name.</summary>
+        /// <remarks>
+        /// Allows accessing the <see cref="ECCurve">curve</see> without necessarily triggering the creation of the
+        /// full <see cref="X9ECParameters"/>.
+        /// </remarks>
+        /// <param name="name">The name of the curve.</param>
         public static X9ECParametersHolder GetByNameLazy(string name)
         {
             DerObjectIdentifier oid = GetOid(name);
             return oid == null ? null : GetByOidLazy(oid);
         }
 
-        /**
-        * return the X9ECParameters object for the named curve represented by
-        * the passed in object identifier. Null if the curve isn't present.
-        *
-        * @param oid an object identifier representing a named curve, if present.
-        */
+        /// <summary>Look up the <see cref="X9ECParameters"/> for 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 X9ECParameters GetByOid(DerObjectIdentifier oid)
         {
-            X9ECParametersHolder holder = GetByOidLazy(oid);
-            return holder == null ? null : holder.Parameters;
+            return GetByOidLazy(oid)?.Parameters;
         }
 
+        /// <summary>Look up an <see cref="X9ECParametersHolder"/> for the curve with the given
+        /// <see cref="DerObjectIdentifier">OID</see>.</summary>
+        /// <remarks>
+        /// Allows accessing the <see cref="ECCurve">curve</see> without necessarily triggering the creation of the
+        /// full <see cref="X9ECParameters"/>.
+        /// </remarks>
+        /// <param name="oid">The <see cref="DerObjectIdentifier">OID</see> for the curve.</param>
         public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
         {
-            return (X9ECParametersHolder)curves[oid];
-        }
-
-        /**
-        * return the object identifier signified by the passed in name. Null
-        * if there is no object identifier associated with name.
-        *
-        * @return the object identifier associated with name, if present.
-        */
-        public static DerObjectIdentifier GetOid(
-            string name)
-        {
-            return (DerObjectIdentifier)objIds[Platform.ToUpperInvariant(name)];
+            return curves.TryGetValue(oid, out var holder) ? holder : null;
         }
 
-        /**
-        * return the named curve name represented by the given object identifier.
-        */
-        public static string GetName(
-            DerObjectIdentifier 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 (string)names[oid];
+            return names.TryGetValue(oid, out var name) ? name : null;
         }
 
-        /**
-         * returns an enumeration containing the name strings for curves
-         * contained in this structure.
-         */
-        public static IEnumerable Names
+        /// <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)
         {
-            get { return new EnumerableProxy(names.Values); }
+            return objIds.TryGetValue(name, out var oid) ? oid : null;
         }
 
-        public static DerObjectIdentifier GetOid(
-            short	curvesize,
-            bool	twisted)
+        /// <summary>Enumerate the available curve names in this registry.</summary>
+        public static IEnumerable<string> Names
         {
-            return GetOid("brainpoolP" + curvesize + (twisted ? "t" : "r") + "1");
+            get { return CollectionUtilities.Proxy(objIds.Keys); }
         }
     }
 }