Last active
July 23, 2024 15:01
-
-
Save joelverhagen/d8e8571c62d0b2bee3c3630e1ad4858f to your computer and use it in GitHub Desktop.
Generate version ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GenerateVersionId(Guid extensionId, string version, string? targetPlatform) | |
{ | |
StringBuilder builder = new(); | |
builder.Append(extensionId.ToString("D")); // use default string format | |
builder.Append('|'); // extension ID cannot contain '|' | |
builder.Append(version.ToLowerInvariant()); // SQL collation is case insensitive | |
if (targetPlatform is not null) | |
{ | |
builder.Append('|'); // version cannot contain '|' | |
builder.Append(targetPlatform.ToLowerInvariant()); // SQL collation is case insensitive | |
} | |
// if future non-null fields are added, a '|' should be added for target platform | |
byte[] input = Encoding.UTF8.GetBytes(builder.ToString()); | |
byte[] hash = SHA256.HashData(input); // SHA-256 because input is user provided, and because Kusto hash_sha256 exists | |
return Convert.ToHexString(hash).ToLowerInvariant(); // lowercase to be consistent with CDN URL casing (and less yelling) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment