Skip to content

Commit 1970635

Browse files
authored
Merge branch 'develop' into copilot/refactor-collection-assertions
2 parents b8a5836 + 4e02502 commit 1970635

File tree

179 files changed

+851
-1125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+851
-1125
lines changed

.editorconfig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ dotnet_diagnostic.S2699.severity = none
177177
# S2930: "IDisposables" should be disposed
178178
# https://rules.sonarsource.com/csharp/RSPEC-2930/
179179
#
180-
# Duplicate of CA2000.
180+
# too noisy.
181181
dotnet_diagnostic.S2930.severity = none
182182

183183
# S2933: Fields that are only assigned in the constructor should be "readonly"
@@ -344,6 +344,10 @@ dotnet_diagnostic.S5659.severity = none
344344
# https://rules.sonarsource.com/csharp/RSPEC-5773/
345345
dotnet_diagnostic.S4581.severity = none
346346

347+
# S6966: Awaitable method should be used
348+
# Duplicate of CA1849
349+
dotnet_diagnostic.S6966.severity = none
350+
347351
#### StyleCop rules ####
348352

349353
# SA1003: Symbols must be spaced correctly
@@ -683,6 +687,10 @@ dotnet_diagnostic.CA1305.severity = none
683687
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1309
684688
dotnet_diagnostic.CA1309.severity = none
685689

690+
# CA1508: Avoid dead conditional code
691+
# Too many false positives.
692+
dotnet_diagnostic.CA1508.severity = none
693+
686694
# CA1510: Use ArgumentNullException throw helper
687695
#
688696
# This is only available in .NET 6.0 and higher. We'd need to use conditional compilation to only
@@ -726,6 +734,14 @@ dotnet_diagnostic.CA1848.severity = silent
726734
# By default, this diagnostic is only reported for private members.
727735
dotnet_code_quality.CA1859.api_surface = private,internal
728736

737+
# CA1873: Evaluation of this argument may be expensive and unnecessary if logging is disabled
738+
dotnet_diagnostic.CA1873.severity = suggestion
739+
740+
# CA2000: Dispose objects before losing scope
741+
#
742+
# too noisy.
743+
dotnet_diagnostic.CA2000.severity = suggestion
744+
729745
# CA2208: Instantiate argument exceptions correctly
730746
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2208
731747
#

.github/workflows/build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ jobs:
1818
uses: actions/setup-dotnet@v5
1919

2020
- name: Build Unit Tests .NET
21-
run: dotnet build -f net9.0 test/Renci.SshNet.Tests/
21+
run: dotnet build -f net10.0 test/Renci.SshNet.Tests/
2222

2323
- name: Build IntegrationTests .NET
24-
run: dotnet build -f net9.0 test/Renci.SshNet.IntegrationTests/
24+
run: dotnet build -f net10.0 test/Renci.SshNet.IntegrationTests/
2525

2626
- name: Run Unit Tests .NET
2727
run: |
2828
dotnet test \
29-
-f net9.0 \
29+
-f net10.0 \
3030
--no-build \
3131
--logger "console;verbosity=normal" \
3232
--logger GitHubActions \
3333
-p:CollectCoverage=true \
3434
-p:CoverletOutputFormat=cobertura \
35-
-p:CoverletOutput=../../coverlet/linux_unit_test_net_9_coverage.xml \
35+
-p:CoverletOutput=../../coverlet/linux_unit_test_net_10_coverage.xml \
3636
test/Renci.SshNet.Tests/
3737
3838
- name: Run Integration Tests .NET
3939
run: |
4040
dotnet test \
41-
-f net9.0 \
41+
-f net10.0 \
4242
--no-build \
4343
--logger "console;verbosity=normal" \
4444
--logger GitHubActions \
4545
-p:CollectCoverage=true \
4646
-p:CoverletOutputFormat=cobertura \
47-
-p:CoverletOutput=../../coverlet/linux_integration_test_net_9_coverage.xml \
47+
-p:CoverletOutput=../../coverlet/linux_integration_test_net_10_coverage.xml \
4848
test/Renci.SshNet.IntegrationTests/
4949
5050
- name: Archive Coverlet Results
@@ -82,13 +82,13 @@ jobs:
8282
- name: Run Unit Tests .NET
8383
run: |
8484
dotnet test `
85-
-f net9.0 `
85+
-f net10.0 `
8686
--no-build `
8787
--logger "console;verbosity=normal" `
8888
--logger GitHubActions `
8989
-p:CollectCoverage=true `
9090
-p:CoverletOutputFormat=cobertura `
91-
-p:CoverletOutput=../../coverlet/windows_unit_test_net_9_coverage.xml `
91+
-p:CoverletOutput=../../coverlet/windows_unit_test_net_10_coverage.xml `
9292
test/Renci.SshNet.Tests/
9393
9494
- name: Run Unit Tests .NET Framework
@@ -173,7 +173,7 @@ jobs:
173173
- name: Run Integration Tests .NET
174174
run:
175175
dotnet test `
176-
-f net9.0 `
176+
-f net10.0 `
177177
--logger "console;verbosity=normal" `
178178
--logger GitHubActions `
179179
-p:CollectCoverage=true `

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
-->
2424
<PropertyGroup>
2525
<EnableNETAnalyzers>true</EnableNETAnalyzers>
26-
<AnalysisLevel>preview-All</AnalysisLevel>
2726
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
2827
</PropertyGroup>
2928

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!-- Should stay on LTS .NET releases. -->
1414
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0" />
1515
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
16-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.9" />
16+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
1717
<PackageVersion Include="MSTest" Version="4.0.2" />
1818
<PackageVersion Include="Moq" Version="4.20.72" />
1919
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.300",
3+
"version": "10.0.100",
44
"rollForward": "latestFeature"
55
}
66
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#nullable enable
2+
#if !NET
3+
using System.Text;
4+
#endif
5+
6+
namespace System
7+
{
8+
internal static class ConvertExtensions
9+
{
10+
extension(Convert)
11+
{
12+
#if !NET
13+
public static byte[] FromHexString(string s)
14+
{
15+
return Org.BouncyCastle.Utilities.Encoders.Hex.Decode(s);
16+
}
17+
18+
public static string ToHexString(byte[] inArray)
19+
{
20+
ArgumentNullException.ThrowIfNull(inArray);
21+
22+
var builder = new StringBuilder(inArray.Length * 2);
23+
24+
foreach (var b in inArray)
25+
{
26+
builder.Append(b.ToString("X2"));
27+
}
28+
29+
return builder.ToString();
30+
}
31+
#endif
32+
}
33+
}
34+
}

src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,8 @@ namespace Renci.SshNet.Abstractions
77
{
88
internal static class CryptoAbstraction
99
{
10-
private static readonly RandomNumberGenerator Randomizer = RandomNumberGenerator.Create();
10+
internal static readonly RandomNumberGenerator Randomizer = RandomNumberGenerator.Create();
1111

1212
internal static readonly SecureRandom SecureRandom = new SecureRandom(new CryptoApiRandomGenerator(Randomizer));
13-
14-
/// <summary>
15-
/// Generates a <see cref="byte"/> array of the specified length, and fills it with a
16-
/// cryptographically strong random sequence of values.
17-
/// </summary>
18-
/// <param name="length">The length of the array generate.</param>
19-
public static byte[] GenerateRandom(int length)
20-
{
21-
var random = new byte[length];
22-
Randomizer.GetBytes(random);
23-
return random;
24-
}
25-
26-
public static byte[] HashMD5(byte[] source)
27-
{
28-
#if NET
29-
return MD5.HashData(source);
30-
#else
31-
using (var md5 = MD5.Create())
32-
{
33-
return md5.ComputeHash(source);
34-
}
35-
#endif
36-
}
37-
38-
public static byte[] HashSHA1(byte[] source)
39-
{
40-
#if NET
41-
return SHA1.HashData(source);
42-
#else
43-
using (var sha1 = SHA1.Create())
44-
{
45-
return sha1.ComputeHash(source);
46-
}
47-
#endif
48-
}
49-
50-
public static byte[] HashSHA256(byte[] source)
51-
{
52-
#if NET
53-
return SHA256.HashData(source);
54-
#else
55-
using (var sha256 = SHA256.Create())
56-
{
57-
return sha256.ComputeHash(source);
58-
}
59-
#endif
60-
}
61-
62-
public static byte[] HashSHA384(byte[] source)
63-
{
64-
#if NET
65-
return SHA384.HashData(source);
66-
#else
67-
using (var sha384 = SHA384.Create())
68-
{
69-
return sha384.ComputeHash(source);
70-
}
71-
#endif
72-
}
73-
74-
public static byte[] HashSHA512(byte[] source)
75-
{
76-
#if NET
77-
return SHA512.HashData(source);
78-
#else
79-
using (var sha512 = SHA512.Create())
80-
{
81-
return sha512.ComputeHash(source);
82-
}
83-
#endif
84-
}
8513
}
8614
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#nullable enable
2+
namespace System
3+
{
4+
internal static class DateTimeExtensions
5+
{
6+
extension(DateTime)
7+
{
8+
#if !NET
9+
public static DateTime UnixEpoch
10+
{
11+
get
12+
{
13+
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
14+
}
15+
}
16+
#endif
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#nullable enable
2+
namespace System.Security.Cryptography
3+
{
4+
internal static class MD5Extensions
5+
{
6+
extension(MD5)
7+
{
8+
#if !NET
9+
public static byte[] HashData(byte[] source)
10+
{
11+
using (var md5 = MD5.Create())
12+
{
13+
return md5.ComputeHash(source);
14+
}
15+
}
16+
#endif
17+
}
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#nullable enable
2+
#if !NET
3+
using Renci.SshNet.Abstractions;
4+
#endif
5+
6+
namespace System.Security.Cryptography
7+
{
8+
internal static class RandomNumberGeneratorExtensions
9+
{
10+
extension(RandomNumberGenerator)
11+
{
12+
#if !NET
13+
public static byte[] GetBytes(int length)
14+
{
15+
var random = new byte[length];
16+
CryptoAbstraction.Randomizer.GetBytes(random);
17+
return random;
18+
}
19+
#endif
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)