From a5f7e7d91de390e71efbc2880ae143fdc85317fe Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 10 Nov 2024 20:38:39 -0500 Subject: [PATCH] Shortcut on 0-byte inputs --- SabreTools.Hashing/HashTool.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/SabreTools.Hashing/HashTool.cs b/SabreTools.Hashing/HashTool.cs index 6737d84..b6d6439 100644 --- a/SabreTools.Hashing/HashTool.cs +++ b/SabreTools.Hashing/HashTool.cs @@ -342,6 +342,17 @@ namespace SabreTools.Hashing // Create the output dictionary var hashDict = new Dictionary(); + // 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(); + // 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)