summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-05 23:03:16 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-05 23:03:16 +0700
commit6d442f9319a857fe483af22d67bbd1677b0991a1 (patch)
treef3356e473c23680d6675defe770532fbb5b42cdc /crypto/src/security
parentDelete experimental code (diff)
downloadBouncyCastle.NET-ed25519-6d442f9319a857fe483af22d67bbd1677b0991a1.tar.xz
Use generics in Enums
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/CipherUtilities.cs12
-rw-r--r--crypto/src/security/DigestUtilities.cs5
-rw-r--r--crypto/src/security/WrapperUtilities.cs5
3 files changed, 10 insertions, 12 deletions
diff --git a/crypto/src/security/CipherUtilities.cs b/crypto/src/security/CipherUtilities.cs
index 929040e2c..8fbf19218 100644
--- a/crypto/src/security/CipherUtilities.cs
+++ b/crypto/src/security/CipherUtilities.cs
@@ -118,9 +118,9 @@ namespace Org.BouncyCastle.Security
         static CipherUtilities()
         {
             // Signal to obfuscation tools not to change enum constants
-            ((CipherAlgorithm)Enums.GetArbitraryValue(typeof(CipherAlgorithm))).ToString();
-            ((CipherMode)Enums.GetArbitraryValue(typeof(CipherMode))).ToString();
-            ((CipherPadding)Enums.GetArbitraryValue(typeof(CipherPadding))).ToString();
+            Enums.GetArbitraryValue<CipherAlgorithm>().ToString();
+            Enums.GetArbitraryValue<CipherMode>().ToString();
+            Enums.GetArbitraryValue<CipherPadding>().ToString();
 
             // TODO Flesh out the list of aliases
 
@@ -358,7 +358,7 @@ namespace Org.BouncyCastle.Security
             CipherAlgorithm cipherAlgorithm;
             try
             {
-                cipherAlgorithm = (CipherAlgorithm)Enums.GetEnumValue(typeof(CipherAlgorithm), algorithmName);
+                cipherAlgorithm = Enums.GetEnumValue<CipherAlgorithm>(algorithmName);
             }
             catch (ArgumentException)
             {
@@ -531,7 +531,7 @@ namespace Org.BouncyCastle.Security
                 {
                     try
                     {
-                        cipherPadding = (CipherPadding)Enums.GetEnumValue(typeof(CipherPadding), paddingName);
+                        cipherPadding = Enums.GetEnumValue<CipherPadding>(paddingName);
                     }
                     catch (ArgumentException)
                     {
@@ -632,7 +632,7 @@ namespace Org.BouncyCastle.Security
                 {
                     CipherMode cipherMode = modeName == ""
                         ? CipherMode.NONE
-                        : (CipherMode)Enums.GetEnumValue(typeof(CipherMode), modeName);
+                        : Enums.GetEnumValue<CipherMode>(modeName);
 
                     switch (cipherMode)
                     {
diff --git a/crypto/src/security/DigestUtilities.cs b/crypto/src/security/DigestUtilities.cs
index 3f3036c8c..8c175b056 100644
--- a/crypto/src/security/DigestUtilities.cs
+++ b/crypto/src/security/DigestUtilities.cs
@@ -51,7 +51,7 @@ namespace Org.BouncyCastle.Security
         static DigestUtilities()
         {
             // Signal to obfuscation tools not to change enum constants
-            ((DigestAlgorithm)Enums.GetArbitraryValue(typeof(DigestAlgorithm))).ToString();
+            Enums.GetArbitraryValue<DigestAlgorithm>().ToString();
 
             Aliases[PkcsObjectIdentifiers.MD2.Id] = "MD2";
             Aliases[PkcsObjectIdentifiers.MD4.Id] = "MD4";
@@ -199,8 +199,7 @@ namespace Org.BouncyCastle.Security
 
             try
             {
-                DigestAlgorithm digestAlgorithm = (DigestAlgorithm)Enums.GetEnumValue(
-                    typeof(DigestAlgorithm), mechanism);
+                DigestAlgorithm digestAlgorithm = Enums.GetEnumValue<DigestAlgorithm>(mechanism);
 
                 switch (digestAlgorithm)
                 {
diff --git a/crypto/src/security/WrapperUtilities.cs b/crypto/src/security/WrapperUtilities.cs
index 48ffe3a96..74e13f121 100644
--- a/crypto/src/security/WrapperUtilities.cs
+++ b/crypto/src/security/WrapperUtilities.cs
@@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Security
         static WrapperUtilities()
         {
             // Signal to obfuscation tools not to change enum constants
-            ((WrapAlgorithm)Enums.GetArbitraryValue(typeof(WrapAlgorithm))).ToString();
+            Enums.GetArbitraryValue<WrapAlgorithm>().ToString();
 
             Algorithms[NistObjectIdentifiers.IdAes128Wrap.Id] = "AESWRAP";
             Algorithms[NistObjectIdentifiers.IdAes192Wrap.Id] = "AESWRAP";
@@ -56,8 +56,7 @@ namespace Org.BouncyCastle.Security
 
             try
             {
-                WrapAlgorithm wrapAlgorithm = (WrapAlgorithm)Enums.GetEnumValue(
-                    typeof(WrapAlgorithm), mechanism);
+                WrapAlgorithm wrapAlgorithm = Enums.GetEnumValue<WrapAlgorithm>(mechanism);
 
                 switch (wrapAlgorithm)
                 {