Browse Source

Remove unused code.

drieseng 5 years ago
parent
commit
1f325586eb

+ 0 - 58
src/Renci.SshNet/Security/BouncyCastle/security/DigestUtilities.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections;
-
-using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests;
 using Renci.SshNet.Security.Org.BouncyCastle.Crypto;
-using Renci.SshNet.Security.Org.BouncyCastle.Utilities;
-using System.Collections.Generic;
 
 namespace Renci.SshNet.Security.Org.BouncyCastle.Security
 {
@@ -21,58 +15,6 @@ namespace Renci.SshNet.Security.Org.BouncyCastle.Security
         {
         }
 
-        private static readonly IDictionary algorithms = new Dictionary<object, object>();
-        private static readonly IDictionary oids = new Dictionary<object, object>();
-
-        static DigestUtilities()
-        {
-            // Signal to obfuscation tools not to change enum constants
-            ((DigestAlgorithm)Enums.GetArbitraryValue(typeof(DigestAlgorithm))).ToString();
-
-            algorithms["SHA256"] = "SHA-256";
-            algorithms["2.16.840.1.101.3.4.2.1"] = "SHA-256";
-        }
-
-        public static ICollection Algorithms
-        {
-            get { return oids.Keys; }
-        }
-
-        public static IDigest GetDigest(
-            string algorithm)
-        {
-            string upper = algorithm.ToUpper();
-            string mechanism = (string) algorithms[upper];
-
-            if (mechanism == null)
-            {
-                mechanism = upper;
-            }
-
-            try
-            {
-                DigestAlgorithm digestAlgorithm = (DigestAlgorithm)Enums.GetEnumValue(
-                    typeof(DigestAlgorithm), mechanism);
-
-                switch (digestAlgorithm)
-                {
-                    case DigestAlgorithm.SHA_256: return new Sha256Digest();
-                }
-            }
-            catch (ArgumentException)
-            {
-            }
-
-            throw new SecurityUtilityException("Digest " + mechanism + " not recognised.");
-        }
-
-        public static byte[] CalculateDigest(string algorithm, byte[] input)
-        {
-            IDigest digest = GetDigest(algorithm);
-            digest.BlockUpdate(input, 0, input.Length);
-            return DoFinal(digest);
-        }
-
         public static byte[] DoFinal(
             IDigest digest)
         {

+ 3 - 36
src/Renci.SshNet/Security/BouncyCastle/security/SecureRandom.cs

@@ -2,6 +2,7 @@ using System;
 using System.Threading;
 
 using Renci.SshNet.Security.Org.BouncyCastle.Crypto;
+using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests;
 using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Prng;
 using Renci.SshNet.Security.Org.BouncyCastle.Utilities;
 
@@ -23,11 +24,8 @@ namespace Renci.SshNet.Security.Org.BouncyCastle.Security
             get { return master; }
         }
 
-        private static DigestRandomGenerator CreatePrng(string digestName, bool autoSeed)
+        private static DigestRandomGenerator CreatePrng(IDigest digest, bool autoSeed)
         {
-            IDigest digest = DigestUtilities.GetDigest(digestName);
-            if (digest == null)
-                return null;
             DigestRandomGenerator prng = new DigestRandomGenerator(digest);
             if (autoSeed)
             {
@@ -44,41 +42,10 @@ namespace Renci.SshNet.Security.Org.BouncyCastle.Security
             return result;
         }
 
-        /// <summary>
-        /// Create and auto-seed an instance based on the given algorithm.
-        /// </summary>
-        /// <remarks>Equivalent to GetInstance(algorithm, true)</remarks>
-        /// <param name="algorithm">e.g. "SHA256PRNG"</param>
-        public static SecureRandom GetInstance(string algorithm)
-        {
-            return GetInstance(algorithm, true);
-        }
-
-        /// <summary>
-        /// Create an instance based on the given algorithm, with optional auto-seeding
-        /// </summary>
-        /// <param name="algorithm">e.g. "SHA256PRNG"</param>
-        /// <param name="autoSeed">If true, the instance will be auto-seeded.</param>
-        public static SecureRandom GetInstance(string algorithm, bool autoSeed)
-        {
-            string upper = algorithm.ToUpper();
-            if (upper.EndsWith("PRNG"))
-            {
-                string digestName = upper.Substring(0, upper.Length - "PRNG".Length);
-                DigestRandomGenerator prng = CreatePrng(digestName, autoSeed);
-                if (prng != null)
-                {
-                    return new SecureRandom(prng);
-                }
-            }
-
-            throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm");
-        }
-
         protected readonly IRandomGenerator generator;
 
         public SecureRandom()
-            : this(CreatePrng("SHA256", true))
+            : this(CreatePrng(new Sha256Digest(), true))
         {
         }