Skip to content

Commit 697a100

Browse files
authored
Merge branch 'release/2.2' => 'master' (#7630)
- barely [automated]
2 parents e468a95 + 706b834 commit 697a100

File tree

4 files changed

+663
-968
lines changed

4 files changed

+663
-968
lines changed

src/Identity/test/Identity.Test/IdentityUIScriptsTest.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ public async Task IdentityUI_ScriptTags_SubresourceIntegrityCheck(ScriptTag scri
4848

4949
private async Task<string> GetShaIntegrity(ScriptTag scriptTag)
5050
{
51-
var prefix = scriptTag.Integrity.Substring(0, 6);
51+
var isSha256 = scriptTag.Integrity.StartsWith("sha256");
52+
var prefix = isSha256 ? "sha256" : "sha384";
5253
using (var respStream = await _httpClient.GetStreamAsync(scriptTag.Src))
53-
using (HashAlgorithm alg = string.Equals(prefix, "sha256") ? (HashAlgorithm)SHA256.Create() : (HashAlgorithm)SHA384.Create())
54+
using (var alg256 = SHA256.Create())
55+
using (var alg384 = SHA384.Create())
5456
{
55-
var hash = alg.ComputeHash(respStream);
57+
byte[] hash;
58+
if(isSha256)
59+
{
60+
hash = alg256.ComputeHash(respStream);
61+
}
62+
else
63+
{
64+
hash = alg384.ComputeHash(respStream);
65+
}
5666
return $"{prefix}-" + Convert.ToBase64String(hash);
5767
}
5868
}

0 commit comments

Comments
 (0)