mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-17 22:43:07 +03:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user