Skip to content

Instantly share code, notes, and snippets.

@joelverhagen
Last active July 23, 2024 15:01
Show Gist options
  • Select an option

  • Save joelverhagen/d8e8571c62d0b2bee3c3630e1ad4858f to your computer and use it in GitHub Desktop.

Select an option

Save joelverhagen/d8e8571c62d0b2bee3c3630e1ad4858f to your computer and use it in GitHub Desktop.

Revisions

  1. joelverhagen revised this gist Jul 23, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions GenerateVersionId.cs
    Original file line number Diff line number Diff line change
    @@ -17,5 +17,5 @@ private static string GenerateVersionId(Guid extensionId, string version, string
    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();
    }
    return Convert.ToHexString(hash).ToLowerInvariant(); // lowercase to be consistent with CDN URL casing (and less yelling)
    }
  2. joelverhagen created this gist Jul 23, 2024.
    21 changes: 21 additions & 0 deletions GenerateVersionId.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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();
    }