From 22c4cc62ca7d23f5aa4f3f425ed9c19e702c1d53 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 4 Mar 2024 10:07:04 -0500 Subject: [PATCH] Add byte array methods to HashTool --- HashTool.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/HashTool.cs b/HashTool.cs index d821923..7ae1242 100644 --- a/HashTool.cs +++ b/HashTool.cs @@ -123,6 +123,45 @@ namespace SabreTools.Hashing #endregion + #region Byte Array Hashes + + /// + /// Get hashes from an input byte array + /// + /// Byte array to hash + /// Dictionary containing hashes on success, null on error + public static Dictionary? GetByteArrayHashes(byte[] input) + { + // Create a hash array for all entries + HashType[] hashTypes = (HashType[])Enum.GetValues(typeof(HashType)); + + // Return the hashes from the stream + return GetStreamHashes(new MemoryStream(input), hashTypes); + } + + /// + /// Get a hash from an input byte array + /// + /// Byte array to hash + /// Hash type to get from the file + /// Dictionary containing hashes on success, null on error + public static string? GetByteArrayHash(byte[] input, HashType hashType) + { + var hashes = GetStreamHashes(new MemoryStream(input), [hashType]); + return hashes?[hashType]; + } + + /// + /// Get hashes from an input byte array + /// + /// Byte array to hash + /// Array of hash types to get from the file + /// Dictionary containing hashes on success, null on error + public static Dictionary? GetByteArrayHashes(byte[] input, HashType[] hashTypes) + => GetStreamHashes(new MemoryStream(input), hashTypes); + + #endregion + #region Stream Hashes ///