E M 87bba240b2
feat: ignore whitespace in openapi hash
Previously, whitespace deviations in openapi.yaml spec would cause a hash mismatch between the openapi.yaml in the Logos Storage image and the openapi.yaml in the project. This update removes whitespaces from the file contents before SHA256 hashing the contents.

In addition, there were two independent Hash functions that were copies of each other to produce the same hash. This has been unified into a single FileHash utility.
2026-06-26 16:43:04 +10:00

25 lines
678 B
C#

using System.Security.Cryptography;
using System.Text;
namespace Utils
{
public static class FileHash
{
public static string HashContents(string fileContents)
{
var fileBytes = Encoding.ASCII.GetBytes(fileContents
.Replace(Environment.NewLine, "")
.Replace(" ", "")); // Ignore whitespace deviations in openapi.yaml
var hash = SHA256.HashData(fileBytes);
return BitConverter.ToString(hash);
}
public static string Hash(string filePath)
{
var file = File.ReadAllText(filePath);
return HashContents(file);
}
}
}