Skip to content

Commit ea57f44

Browse files
committed
fix(Hash): 修复空输入处理与 Sha256Helper 行为一致
修改 Sha1Helper 对空字符串/空数组的处理方式, 返回实际的 SHA-1 哈希值而非 string.Empty, 与 Sha256Helper 行为保持一致。
1 parent 5de3cc9 commit ea57f44

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

GameFrameX.Foundation.Hash/Sha1Helper.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public static class Sha1Helper
2424
public static string ComputeHash(string input, Encoding encoding = null)
2525
{
2626
ArgumentNullException.ThrowIfNull(input, nameof(input));
27-
28-
if (input.Length == 0)
27+
28+
if (string.IsNullOrEmpty(input))
2929
{
30-
return string.Empty;
30+
return ComputeHash(Array.Empty<byte>());
3131
}
3232

3333
encoding ??= Encoding.UTF8;
@@ -44,11 +44,6 @@ public static string ComputeHash(string input, Encoding encoding = null)
4444
public static string ComputeHash(byte[] buffer)
4545
{
4646
ArgumentNullException.ThrowIfNull(buffer, nameof(buffer));
47-
48-
if (buffer.Length == 0)
49-
{
50-
return string.Empty;
51-
}
5247

5348
using var sha1 = SHA1.Create();
5449
var hash = sha1.ComputeHash(buffer);

0 commit comments

Comments
 (0)