-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix support of webassembly #911
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,14 +202,69 @@ private ReadOnlySpan<byte> GenerateSigningKey(string region, DateTime signingDat | |
/// <param name="content">Bytes to be hmac computed</param> | ||
/// <returns>Computed hmac of input content</returns> | ||
private ReadOnlySpan<byte> SignHmac(ReadOnlySpan<byte> key, ReadOnlySpan<byte> content) | ||
{ | ||
return ComputeHmac256(key.ToArray(), content.ToArray()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code is the cause of the Functional test failure caught during the build tests. You need to debug the code and resolve the issue. |
||
//#if NETSTANDARD | ||
// using var hmac = new HMACSHA256(key.ToArray()); | ||
// hmac.Initialize(); | ||
// return hmac.ComputeHash(content.ToArray()); | ||
//#else | ||
// return HMACSHA256.HashData(key, content); | ||
//#endif | ||
} | ||
|
||
private byte[] ComputeHmac256(byte[] key, byte[] content) | ||
{ | ||
var hKey = key; | ||
if (hKey.Length > 64) | ||
{ | ||
hKey = ComputeSha256(hKey); | ||
} | ||
else if (hKey.Length < 64) | ||
{ | ||
var data = new byte[64]; | ||
Array.Copy(hKey.ToArray(), data, hKey.Length); | ||
hKey = (data); | ||
} | ||
|
||
var innerKeyPad = new byte[hKey.Length]; | ||
for (var i = 0; i < hKey.Length; i++) | ||
{ | ||
innerKeyPad[i] = (byte)(hKey[i] ^ 0x36); | ||
} | ||
|
||
var innerBody = new byte[content.Length + innerKeyPad.Length]; | ||
Array.Copy(innerKeyPad, innerBody, innerKeyPad.Length); | ||
Array.Copy(content,0, innerBody, innerKeyPad.Length, content.Length); | ||
var innerHash = ComputeSha256(innerBody); | ||
|
||
var outerKeyPad = new byte[hKey.Length]; | ||
for (var i = 0; i < hKey.Length; i++) | ||
{ | ||
outerKeyPad[i] = (byte)(hKey[i] ^ 0x5c); | ||
} | ||
|
||
var outerBody = new byte[innerHash.Length + outerKeyPad.Length]; | ||
Array.Copy(outerKeyPad, outerBody, outerKeyPad.Length); | ||
Array.Copy(innerHash, 0, outerBody, outerKeyPad.Length, innerHash.Length); | ||
var outerHash = ComputeSha256(outerBody); | ||
return outerHash; | ||
} | ||
/// <summary> | ||
/// Compute sha256 checksum. | ||
/// </summary> | ||
/// <param name="body">Bytes body</param> | ||
/// <returns>Bytes of sha256 checksum</returns> | ||
private byte[] ComputeSha256(byte[] body) | ||
{ | ||
#if NETSTANDARD | ||
using var hmac = new HMACSHA256(key.ToArray()); | ||
hmac.Initialize(); | ||
return hmac.ComputeHash(content.ToArray()); | ||
using var sha = SHA256.Create(); | ||
var hash | ||
= sha.ComputeHash(body.ToArray()); | ||
#else | ||
return HMACSHA256.HashData(key, content); | ||
var hash = SHA256.HashData(body); | ||
#endif | ||
return hash; | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the previous review comments, this part needs to be cleaned up as
responseResult
has theContentStream
already set up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also run
dotnet regitlint
for formatting problems.