[#13] Client: Use code analyzers

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-09-23 18:53:21 +03:00
parent d7dbbf8da8
commit d1271df207
102 changed files with 2168 additions and 733 deletions

View file

@ -13,17 +13,17 @@ public static class Base58
{
if (input is null)
throw new ArgumentNullException(nameof(input));
byte[] buffer = Decode(input);
if (buffer.Length < 4)
if (buffer.Length < 4)
throw new FormatException();
byte[] checksum = buffer[0..(buffer.Length - 4)].Sha256().Sha256();
if (!buffer.AsSpan(buffer.Length - 4).SequenceEqual(checksum[..4].AsSpan()))
throw new FormatException();
var ret = buffer[..^4];
Array.Clear(buffer, 0, buffer.Length);
return ret;
@ -34,7 +34,7 @@ public static class Base58
byte[] checksum = data.ToArray().Sha256().Sha256();
Span<byte> buffer = stackalloc byte[data.Length + 4];
data.CopyTo(buffer);
checksum[..4].AsSpan().CopyTo(buffer[data.Length..]);
var ret = Encode(buffer);
buffer.Clear();
@ -44,6 +44,9 @@ public static class Base58
public static byte[] Decode(string input)
{
if (input == null)
throw new ArgumentNullException(nameof(input));
// Decode Base58 string to BigInteger
var bi = BigInteger.Zero;
for (int i = 0; i < input.Length; i++)
@ -61,7 +64,7 @@ public static class Base58
if (bi.IsZero)
return leadingZeros;
var bytesBigEndian = bi.ToByteArray().Reverse();
var bytesBigEndian = bi.ToByteArray().Reverse().ToArray();
var firstNonZeroIndex = 0;