Apply suggestions from code review

Adding minor stylistic suggestions from Bond-009

Co-Authored-By: LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>
This commit is contained in:
LogicalPhallacy
2019-02-18 00:31:03 -08:00
committed by GitHub
parent d8e6808d77
commit 9f3aa2cead
3 changed files with 264 additions and 255 deletions

View File

@@ -72,7 +72,7 @@ namespace Emby.Server.Implementations.Cryptography
}
private byte[] PBKDF2(string method, byte[] bytes, byte[] salt, int iterations)
{
{
using (var r = new Rfc2898DeriveBytes(bytes, salt, iterations, new HashAlgorithmName(method)))
{
return r.GetBytes(32);
@@ -107,9 +107,9 @@ namespace Emby.Server.Implementations.Cryptography
}
else
{
throw new CryptographicException(String.Format("Requested hash method is not supported: {0}", HashMethod));
throw new CryptographicException($"Requested hash method is not supported: {HashMethod}"));
}
}
}
public byte[] ComputeHashWithDefaultMethod(byte[] bytes, byte[] salt)
{
@@ -117,25 +117,32 @@ namespace Emby.Server.Implementations.Cryptography
}
public byte[] ComputeHash(PasswordHash hash)
{
int iterations = defaultiterations;
if (!hash.Parameters.ContainsKey("iterations"))
{
hash.Parameters.Add("iterations", defaultiterations.ToString());
}
else
{
try { iterations = int.Parse(hash.Parameters["iterations"]); }
catch (Exception e) { iterations = defaultiterations; throw new Exception($"Couldn't successfully parse iterations value from string:{hash.Parameters["iterations"]}", e); }
{
int iterations = defaultiterations;
if (!hash.Parameters.ContainsKey("iterations"))
{
hash.Parameters.Add("iterations", defaultiterations.ToString(CultureInfo.InvariantCulture));
}
return PBKDF2(hash.Id, hash.HashBytes, hash.SaltBytes,iterations);
}
else
{
try
{
iterations = int.Parse(hash.Parameters["iterations"]);
}
catch (Exception e)
{
iterations = defaultiterations;
throw new Exception($"Couldn't successfully parse iterations value from string:{hash.Parameters["iterations"]}", e);
}
}
return PBKDF2(hash.Id, hash.HashBytes, hash.SaltBytes, iterations);
}
public byte[] GenerateSalt()
{
byte[] salt = new byte[64];
rng.GetBytes(salt);
return salt;
}
}
}
}