Skip to content

Commit 0fd5b75

Browse files
committed
Migrate to .NET 9 and temporarily remove other frameworks support
1 parent fb67481 commit 0fd5b75

36 files changed

+136
-358
lines changed

.editorconfig

+28-25
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ charset = utf-8-bom
1212

1313
[*.{cs,vb}]
1414
dotnet_sort_system_directives_first = true
15-
dotnet_style_qualification_for_field = false:silent
16-
dotnet_style_qualification_for_property = false:silent
17-
dotnet_style_qualification_for_method = false:silent
18-
dotnet_style_qualification_for_event = false:silent
19-
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
20-
dotnet_style_predefined_type_for_member_access = true:silent
21-
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
22-
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
23-
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
24-
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
25-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
15+
dotnet_style_qualification_for_field = false:none
16+
dotnet_style_qualification_for_property = false:none
17+
dotnet_style_qualification_for_method = false:none
18+
dotnet_style_qualification_for_event = false:none
19+
dotnet_style_predefined_type_for_locals_parameters_members = true:none
20+
dotnet_style_predefined_type_for_member_access = true:none
21+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
22+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
23+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
24+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:none
25+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:none
2626
dotnet_style_readonly_field = true:suggestion
2727
dotnet_style_object_initializer = true:suggestion
2828
dotnet_style_collection_initializer = true:suggestion
2929
dotnet_style_explicit_tuple_names = true:suggestion
3030
dotnet_style_null_propagation = true:suggestion
3131
dotnet_style_coalesce_expression = true:suggestion
32-
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
32+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:none
3333
dotnet_style_prefer_inferred_tuple_names = true:suggestion
3434
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
35-
dotnet_style_prefer_auto_properties = true:silent
36-
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
37-
dotnet_style_prefer_conditional_expression_over_return = true:silent
35+
dotnet_style_prefer_auto_properties = true:none
36+
dotnet_style_prefer_conditional_expression_over_assignment = true:none
37+
dotnet_style_prefer_conditional_expression_over_return = true:none
3838
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
3939
dotnet_naming_style.camel_case_style.capitalization = camel_case
4040
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
@@ -72,21 +72,21 @@ dotnet_naming_symbols.private_fields.applicable_kinds = field
7272
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
7373

7474
[*.cs]
75-
csharp_style_var_for_built_in_types = true:silent
76-
csharp_style_var_when_type_is_apparent = true:silent
77-
csharp_style_var_elsewhere = true:silent
78-
csharp_style_expression_bodied_methods = false:silent
79-
csharp_style_expression_bodied_constructors = false:silent
80-
csharp_style_expression_bodied_operators = false:silent
81-
csharp_style_expression_bodied_properties = true:silent
82-
csharp_style_expression_bodied_indexers = true:silent
83-
csharp_style_expression_bodied_accessors = true:silent
75+
csharp_style_var_for_built_in_types = true:none
76+
csharp_style_var_when_type_is_apparent = true:none
77+
csharp_style_var_elsewhere = true:none
78+
csharp_style_expression_bodied_methods = false:none
79+
csharp_style_expression_bodied_constructors = false:none
80+
csharp_style_expression_bodied_operators = false:none
81+
csharp_style_expression_bodied_properties = true:none
82+
csharp_style_expression_bodied_indexers = true:none
83+
csharp_style_expression_bodied_accessors = true:none
8484
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
8585
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
8686
csharp_style_throw_expression = true:suggestion
8787
csharp_style_conditional_delegate_call = true:suggestion
8888
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
89-
csharp_prefer_braces = false:silent
89+
csharp_prefer_braces = false:none
9090
csharp_style_deconstructed_variable_declaration = true:suggestion
9191
csharp_prefer_simple_default_expression = true:suggestion
9292
csharp_style_pattern_local_over_anonymous_function = true:suggestion
@@ -114,6 +114,9 @@ csharp_space_between_method_call_name_and_opening_parenthesis = false
114114
csharp_space_between_method_call_empty_parameter_list_parentheses = false
115115
csharp_preserve_single_line_statements = true
116116
csharp_preserve_single_line_blocks = true
117+
csharp_style_namespace_declarations = file_scoped
118+
csharp_using_directive_placement = outside_namespace:none
119+
csharp_style_prefer_range_operator = false:none
117120

118121
[*.vb]
119122
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion

.github/workflows/dotnet.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
- name: Setup .NET
1717
uses: actions/setup-dotnet@v2
1818
with:
19-
dotnet-version: 8.0.x
19+
dotnet-version: 9.0.x
2020
- name: Restore dependencies
2121
run: dotnet restore
2222
- name: Build
2323
run: dotnet build --no-restore -c Release
2424
- name: Test
25-
run: dotnet test --no-build --verbosity normal -c Release -f net8.0
25+
run: dotnet test --no-build --verbosity normal -c Release -f net9.0

Directory.Build.props

-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Key.snk</AssemblyOriginatorKeyFile>
1313
</PropertyGroup>
1414

15-
<ItemGroup>
16-
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.11.0">
17-
<PrivateAssets>all</PrivateAssets>
18-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19-
</PackageReference>
20-
</ItemGroup>
21-
2215
<ItemGroup>
2316
<Using Include="System.Security.Cryptography" />
2417
</ItemGroup>

benchmarks/OpenGost.Security.Cryptography.Benchmarks/OpenGost.Security.Cryptography.Benchmarks.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
55
<OutputType>Exe</OutputType>
66
</PropertyGroup>
77

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestMinor"
55
}
66
}

src/Directory.Build.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<PropertyGroup>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8-
<WarningLevel>7</WarningLevel>
98
<IsPackable>true</IsPackable>
109
<IncludeSymbols>true</IncludeSymbols>
1110
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
@@ -17,7 +16,7 @@
1716
<AnalysisLevel>latest-all</AnalysisLevel>
1817
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1918
<EnableNETAnalyzers>true</EnableNETAnalyzers>
20-
<NoWarn>$(NoWarn);CA1508;CA1859;CA5358;NU1903;SYSLIB0045</NoWarn>
19+
<NoWarn>$(NoWarn);CA5358;SYSLIB0045</NoWarn>
2120
</PropertyGroup>
2221

2322
<ItemGroup>

src/OpenGost.Security.Cryptography/CMAC.cs

+20-24
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ namespace OpenGost.Security.Cryptography;
1010
[ComVisible(true)]
1111
public abstract class CMAC : KeyedHashAlgorithm
1212
{
13-
private static readonly IReadOnlyDictionary<int, byte[]> _irreduciblePolynomials = new Dictionary<int, byte[]>
14-
{
15-
[64] =
13+
private static readonly byte[]
14+
_irreduciblePolynomial64 =
1615
[
1716
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B
1817
],
19-
[128] =
18+
_irreduciblePolynomial128 =
2019
[
2120
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87
2221
],
23-
[256] =
22+
_irreduciblePolynomial256 =
2423
[
2524
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2625
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x25
27-
],
28-
};
26+
];
2927

3028
private SymmetricAlgorithm _symmetricAlgorithm = null!;
3129
private ICryptoTransform? _encryptor;
@@ -58,12 +56,8 @@ public override byte[] Key
5856
get => (byte[])KeyValue.Clone();
5957
set
6058
{
61-
#if NET6_0_OR_GREATER
6259
ArgumentNullException.ThrowIfNull(value);
63-
#else
64-
if (value is null)
65-
throw new ArgumentNullException(nameof(value));
66-
#endif
60+
6761
if (_hashing)
6862
throw new CryptographicException(CryptographyStrings.CryptographicSymmetricAlgorithmKeySet);
6963

@@ -170,19 +164,19 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
170164
Buffer.BlockCopy(array, ibStart, _buffer, _bufferLength, bytesToCopy);
171165
ibStart += bytesToCopy;
172166
cbSize -= bytesToCopy;
173-
_encryptor!.TransformBlock(_buffer, 0, _bytesPerBlock, _temp, 0);
167+
_ = _encryptor!.TransformBlock(_buffer, 0, _bytesPerBlock, _temp, 0);
174168
_bufferLength = 0;
175169
}
176170

177171
if (cbSize >= _bytesPerBlock && _bufferLength == _bytesPerBlock)
178172
{
179-
_encryptor!.TransformBlock(_buffer, 0, _bytesPerBlock, _temp, 0);
173+
_ = _encryptor!.TransformBlock(_buffer, 0, _bytesPerBlock, _temp, 0);
180174
_bufferLength = 0;
181175
}
182176

183177
while (cbSize > _bytesPerBlock)
184178
{
185-
_encryptor!.TransformBlock(array, ibStart, _bytesPerBlock, _temp, 0);
179+
_ = _encryptor!.TransformBlock(array, ibStart, _bytesPerBlock, _temp, 0);
186180
ibStart += _bytesPerBlock;
187181
cbSize -= _bytesPerBlock;
188182
}
@@ -242,17 +236,18 @@ protected override void Dispose(bool disposing)
242236
base.Dispose(disposing);
243237
}
244238

245-
#region Creation factory methods
246-
247239
/// <summary>
248240
/// Creates an instance of the default implementation of <see cref="CMAC"/> algorithm.
249241
/// </summary>
250242
/// <returns>
251243
/// A new instance of <see cref="CMAC"/>.
252244
/// </returns>
253245
[ComVisible(false)]
246+
[Obsolete(Obsoletions.DefaultCryptoAlgorithmsMessage,
247+
DiagnosticId = Obsoletions.DefaultCryptoAlgorithmsDiagId,
248+
UrlFormat = Obsoletions.SharedUrlFormat)]
254249
public static new CMAC Create()
255-
=> Create(CryptoConstants.CMACGrasshopperAlgorithmName);
250+
=> new CMACGrasshopper();
256251

257252
/// <summary>
258253
/// Creates an instance of a specified implementation of <see cref="CMAC"/> algorithm.
@@ -267,8 +262,6 @@ protected override void Dispose(bool disposing)
267262
public static new CMAC Create(string algorithmName)
268263
=> (CMAC)CryptoConfig.CreateFromName(algorithmName)!;
269264

270-
#endregion
271-
272265
private void EnsureEncryptorInitialized()
273266
{
274267
if (_encryptor is null)
@@ -319,9 +312,12 @@ private static void LeftShiftLittleEndianOneBit(byte[] data)
319312

320313
private static byte[] GetIrreduciblePolynomial(int blockSize)
321314
{
322-
if (_irreduciblePolynomials.TryGetValue(blockSize, out var result))
323-
return result;
324-
325-
throw new CryptographicException(CryptographyStrings.CryptographicInvalidBlockSize);
315+
return blockSize switch
316+
{
317+
64 => _irreduciblePolynomial64,
318+
128 => _irreduciblePolynomial128,
319+
256 => _irreduciblePolynomial256,
320+
_ => throw new CryptographicException(CryptographyStrings.CryptographicInvalidBlockSize),
321+
};
326322
}
327323
}

src/OpenGost.Security.Cryptography/ECCurveOidMap.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -453,23 +453,15 @@ private static IReadOnlyDictionary<string, ECCurve> ECCurveOidDictionary
453453

454454
public static bool OidValueRegistered(string oidValue)
455455
{
456-
#if NET6_0_OR_GREATER
457456
ArgumentNullException.ThrowIfNull(oidValue);
458-
#else
459-
if (oidValue is null)
460-
throw new ArgumentNullException(nameof(oidValue));
461-
#endif
457+
462458
return ECCurveOidDictionary.ContainsKey(oidValue);
463459
}
464460

465461
public static ECCurve GetExplicitCurveByOid(string oidValue)
466462
{
467-
#if NET6_0_OR_GREATER
468463
ArgumentNullException.ThrowIfNull(oidValue);
469-
#else
470-
if (oidValue is null)
471-
throw new ArgumentNullException(nameof(oidValue));
472-
#endif
464+
473465
if (!ECCurveOidDictionary.ContainsKey(oidValue))
474466
throw new NotImplementedException();
475467

src/OpenGost.Security.Cryptography/GostECDsa.cs

+1-18
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ protected GostECDsa()
2727
KeySizeValue = 512;
2828
}
2929

30-
#region Creation factory methods
31-
3230
/// <summary>
3331
/// Creates an instance of the default implementation of <see cref="GostECDsa"/> algorithm.
3432
/// </summary>
@@ -37,20 +35,5 @@ protected GostECDsa()
3735
/// </returns>
3836
[ComVisible(false)]
3937
public static new GostECDsa Create()
40-
=> Create(CryptoConstants.GostECDsaAlgorithmName);
41-
42-
/// <summary>
43-
/// Creates an instance of a specified implementation of <see cref="GostECDsa"/> algorithm.
44-
/// </summary>
45-
/// <param name="algorithmName">
46-
/// The name of the specific implementation of <see cref="GostECDsa"/> to be used.
47-
/// </param>
48-
/// <returns>
49-
/// A new instance of <see cref="GostECDsa"/> using the specified implementation.
50-
/// </returns>
51-
[ComVisible(false)]
52-
public static new GostECDsa Create(string algorithmName)
53-
=> (GostECDsa)CryptoConfig.CreateFromName(algorithmName)!;
54-
55-
#endregion
38+
=> new GostECDsaManaged();
5639
}

src/OpenGost.Security.Cryptography/GostECDsaCertificateExtensions.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using OpenGost.Security.Cryptography.Asn1;
44
using OpenGost.Security.Cryptography.Properties;
55

6+
#pragma warning disable IDE0130
67
namespace System.Security.Cryptography.X509Certificates;
8+
#pragma warning restore IDE0130
79

810
using static CryptoConstants;
911

@@ -32,12 +34,7 @@ public static class GostECDsaCertificateExtensions
3234
/// </exception>
3335
public static GostECDsa? GetGostECDsaPublicKey(this X509Certificate2 certificate)
3436
{
35-
#if NET6_0_OR_GREATER
3637
ArgumentNullException.ThrowIfNull(certificate);
37-
#else
38-
if (certificate is null)
39-
throw new ArgumentNullException(nameof(certificate));
40-
#endif
4138

4239
if (!IsGostECDsa(certificate))
4340
return null;
@@ -87,7 +84,7 @@ public static class GostECDsaCertificateExtensions
8784
private static bool IsGostECDsa(X509Certificate2 certificate)
8885
{
8986
var value = certificate.PublicKey.Oid.Value;
90-
if (value != GostECDsa256OidValue && value != GostECDsa512OidValue)
87+
if (value is not GostECDsa256OidValue and not GostECDsa512OidValue)
9188
return false;
9289

9390
foreach (var extension in certificate.Extensions)

0 commit comments

Comments
 (0)