Skip to content
Permalink
Browse files

Turn on S1449, S4026, S4056 & S4057

  • Loading branch information
dahlia committed Dec 18, 2019
1 parent f8dead3 commit 336e9f94fdc151efc834ab97472c6f0aeb52186f
@@ -42,6 +42,14 @@
</Rules>

<Rules AnalyzerId="SonarAnalyzer" RuleNamespace="SonarAnalyzer">
<!-- These warn about leaving parameters taking ICultureInfo default,
which implicitly follows the system's locale settings so that code is
non-deterministic. -->
<Rule Id="S1449" Action="Warning" />
<Rule Id="S4026" Action="Warning" />
<Rule Id="S4056" Action="Warning" />
<Rule Id="S4057" Action="Warning" />

<!-- Either remove or fill this block of code. -->
<Rule Id="S108" Action="None" />
<!-- 'System.NullReferenceException' should not be thrown by user code. -->
@@ -1,6 +1,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
@@ -266,7 +267,7 @@ private static string ToChecksumAddress(string hex)
for (var i = 0; i < hex.Length; i++)
{
char c = hex[i];
address += (hashHex[i] >= '8') ? char.ToUpper(c) : c;
address += (hashHex[i] >= '8') ? char.ToUpper(c, CultureInfo.InvariantCulture) : c;
}

return address;
@@ -305,7 +306,8 @@ private static byte[] DeriveAddress(string hex)
);
}

if (hex.ToLower() != hex && ToChecksumAddress(hex.ToLower()) != hex)
if (hex.ToLower(CultureInfo.InvariantCulture) != hex &&
ToChecksumAddress(hex.ToLower(CultureInfo.InvariantCulture)) != hex)
{
throw new ArgumentException(
"address checksum is invalid",
@@ -206,7 +206,8 @@ private Block(RawBlock rb)
n =>
{
int nLen = n.ByteArray.Length;
byte[] nLenStr = Encoding.ASCII.GetBytes(nLen.ToString());
byte[] nLenStr = Encoding.ASCII.GetBytes(
nLen.ToString(CultureInfo.InvariantCulture));
int totalLen =
stampPrefix.Length + nLenStr.Length + 1 + nLen + stampSuffix.Length;
byte[] stamp = new byte[totalLen];
@@ -1,6 +1,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;

namespace Libplanet
@@ -74,7 +75,7 @@ public static string Hex(byte[] bytes)

string s = BitConverter.ToString(bytes);

return s.Replace("-", string.Empty).ToLower();
return s.Replace("-", string.Empty).ToLower(CultureInfo.InvariantCulture);
}

/// <summary>
@@ -2,6 +2,7 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using Org.BouncyCastle.Crypto;
@@ -88,9 +89,10 @@ public string WriteJson(Utf8JsonWriter writer)
writer.WriteStartObject();
writer.WriteNumber("c", Iterations);
writer.WriteNumber("dklen", KeyLength);
string alg = new T().AlgorithmName;
writer.WriteString(
"prf",
"hmac-" + new T().AlgorithmName.ToLower().Replace("-", string.Empty)
"hmac-" + alg.ToLower(CultureInfo.InvariantCulture).Replace("-", string.Empty)
);
writer.WriteString("salt", ByteUtil.Hex(Salt));
writer.WriteEndObject();
@@ -1,6 +1,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@@ -365,8 +366,11 @@ public void WriteJson(Utf8JsonWriter writer, [Pure] in Guid? id = null)
{
writer.WriteStartObject();
writer.WriteNumber("version", 3);
writer.WriteString("id", (id ?? Guid.NewGuid()).ToString().ToLower());
writer.WriteString("address", Address.ToHex().ToLower());
writer.WriteString(
"id",
(id ?? Guid.NewGuid()).ToString().ToLower(CultureInfo.InvariantCulture)
);
writer.WriteString("address", Address.ToHex().ToLower(CultureInfo.InvariantCulture));
writer.WriteStartObject("crypto");
writer.WriteString("ciphertext", ByteUtil.Hex(Ciphertext));
writer.WritePropertyName("cipherparams");
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@@ -586,7 +587,7 @@ HashDigest<SHA256> blockHash

string collId = StateRefId(chainId);
LiteCollection<StateRefDoc> coll = _db.GetCollection<StateRefDoc>(collId);
string addressString = address.ToHex().ToLower();
string addressString = address.ToHex().ToLower(CultureInfo.InvariantCulture);
IEnumerable<StateRefDoc> stateRefs = coll.Find(
Query.And(
Query.All("BlockIndex", Query.Descending),
@@ -876,7 +877,7 @@ public Address Address

set
{
AddressString = value.ToHex().ToLower();
AddressString = value.ToHex().ToLower(CultureInfo.InvariantCulture);
}
}

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -162,7 +163,7 @@ public override string ToString()
UpdatedAddresses.Select(a => "\n " + ByteUtil.Hex(a.ToArray()))
);
return $@"{nameof(RawTransaction)}
{nameof(Nonce)} = {Nonce.ToString()}
{nameof(Nonce)} = {Nonce.ToString(CultureInfo.InvariantCulture)}
{nameof(Signer)} = {ByteUtil.Hex(Signer.ToArray())}
{nameof(PublicKey)} = {ByteUtil.Hex(PublicKey.ToArray())}
{nameof(UpdatedAddresses)} = {updatedAddresses}

0 comments on commit 336e9f9

Please sign in to comment.
You can’t perform that action at this time.