Shortcut on 0-byte inputs

This commit is contained in:
Matt Nadareski
2024-11-10 20:38:39 -05:00
parent 2e3e16e8ae
commit a5f7e7d91d

View File

@@ -342,6 +342,17 @@ namespace SabreTools.Hashing
// Create the output dictionary
var hashDict = new Dictionary<HashType, string?>();
// Shortcut if we have a 0-byte input
if (input.Length == 0)
{
foreach (var hashType in hashTypes)
{
hashDict[hashType] = ZeroHash.GetString(hashType);
}
return hashDict;
}
// Run the hashing
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen);
if (hashers == null)
@@ -373,6 +384,17 @@ namespace SabreTools.Hashing
// Create the output dictionary
var hashDict = new Dictionary<HashType, byte[]?>();
// Shortcut if we have a 0-byte input
if (input.Length == 0)
{
foreach (var hashType in hashTypes)
{
hashDict[hashType] = ZeroHash.GetBytes(hashType);
}
return hashDict;
}
// Run the hashing
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen);
if (hashers == null)