Skip to content

Commit 1f32558

Browse files
committed
Remove unused code.
1 parent 5c2e2b4 commit 1f32558

File tree

2 files changed

+3
-94
lines changed

2 files changed

+3
-94
lines changed

src/Renci.SshNet/Security/BouncyCastle/security/DigestUtilities.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections;
3-
4-
using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests;
51
using Renci.SshNet.Security.Org.BouncyCastle.Crypto;
6-
using Renci.SshNet.Security.Org.BouncyCastle.Utilities;
7-
using System.Collections.Generic;
82

93
namespace Renci.SshNet.Security.Org.BouncyCastle.Security
104
{
@@ -21,58 +15,6 @@ private DigestUtilities()
2115
{
2216
}
2317

24-
private static readonly IDictionary algorithms = new Dictionary<object, object>();
25-
private static readonly IDictionary oids = new Dictionary<object, object>();
26-
27-
static DigestUtilities()
28-
{
29-
// Signal to obfuscation tools not to change enum constants
30-
((DigestAlgorithm)Enums.GetArbitraryValue(typeof(DigestAlgorithm))).ToString();
31-
32-
algorithms["SHA256"] = "SHA-256";
33-
algorithms["2.16.840.1.101.3.4.2.1"] = "SHA-256";
34-
}
35-
36-
public static ICollection Algorithms
37-
{
38-
get { return oids.Keys; }
39-
}
40-
41-
public static IDigest GetDigest(
42-
string algorithm)
43-
{
44-
string upper = algorithm.ToUpper();
45-
string mechanism = (string) algorithms[upper];
46-
47-
if (mechanism == null)
48-
{
49-
mechanism = upper;
50-
}
51-
52-
try
53-
{
54-
DigestAlgorithm digestAlgorithm = (DigestAlgorithm)Enums.GetEnumValue(
55-
typeof(DigestAlgorithm), mechanism);
56-
57-
switch (digestAlgorithm)
58-
{
59-
case DigestAlgorithm.SHA_256: return new Sha256Digest();
60-
}
61-
}
62-
catch (ArgumentException)
63-
{
64-
}
65-
66-
throw new SecurityUtilityException("Digest " + mechanism + " not recognised.");
67-
}
68-
69-
public static byte[] CalculateDigest(string algorithm, byte[] input)
70-
{
71-
IDigest digest = GetDigest(algorithm);
72-
digest.BlockUpdate(input, 0, input.Length);
73-
return DoFinal(digest);
74-
}
75-
7618
public static byte[] DoFinal(
7719
IDigest digest)
7820
{

src/Renci.SshNet/Security/BouncyCastle/security/SecureRandom.cs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33

44
using Renci.SshNet.Security.Org.BouncyCastle.Crypto;
5+
using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Digests;
56
using Renci.SshNet.Security.Org.BouncyCastle.Crypto.Prng;
67
using Renci.SshNet.Security.Org.BouncyCastle.Utilities;
78

@@ -23,11 +24,8 @@ private static SecureRandom Master
2324
get { return master; }
2425
}
2526

26-
private static DigestRandomGenerator CreatePrng(string digestName, bool autoSeed)
27+
private static DigestRandomGenerator CreatePrng(IDigest digest, bool autoSeed)
2728
{
28-
IDigest digest = DigestUtilities.GetDigest(digestName);
29-
if (digest == null)
30-
return null;
3129
DigestRandomGenerator prng = new DigestRandomGenerator(digest);
3230
if (autoSeed)
3331
{
@@ -44,41 +42,10 @@ public static byte[] GetNextBytes(SecureRandom secureRandom, int length)
4442
return result;
4543
}
4644

47-
/// <summary>
48-
/// Create and auto-seed an instance based on the given algorithm.
49-
/// </summary>
50-
/// <remarks>Equivalent to GetInstance(algorithm, true)</remarks>
51-
/// <param name="algorithm">e.g. "SHA256PRNG"</param>
52-
public static SecureRandom GetInstance(string algorithm)
53-
{
54-
return GetInstance(algorithm, true);
55-
}
56-
57-
/// <summary>
58-
/// Create an instance based on the given algorithm, with optional auto-seeding
59-
/// </summary>
60-
/// <param name="algorithm">e.g. "SHA256PRNG"</param>
61-
/// <param name="autoSeed">If true, the instance will be auto-seeded.</param>
62-
public static SecureRandom GetInstance(string algorithm, bool autoSeed)
63-
{
64-
string upper = algorithm.ToUpper();
65-
if (upper.EndsWith("PRNG"))
66-
{
67-
string digestName = upper.Substring(0, upper.Length - "PRNG".Length);
68-
DigestRandomGenerator prng = CreatePrng(digestName, autoSeed);
69-
if (prng != null)
70-
{
71-
return new SecureRandom(prng);
72-
}
73-
}
74-
75-
throw new ArgumentException("Unrecognised PRNG algorithm: " + algorithm, "algorithm");
76-
}
77-
7845
protected readonly IRandomGenerator generator;
7946

8047
public SecureRandom()
81-
: this(CreatePrng("SHA256", true))
48+
: this(CreatePrng(new Sha256Digest(), true))
8249
{
8350
}
8451

0 commit comments

Comments
 (0)