Skip to content

Commit

Permalink
Merge pull request #130 from dorssel/net9
Browse files Browse the repository at this point in the history
Use .NET 9 SDK
  • Loading branch information
dorssel authored Nov 17, 2024
2 parents 837bf73 + 6ca8bb8 commit 3ad45c8
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 108 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ end_of_line = crlf
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
###############################
# C# Coding Conventions #
###############################
Expand Down Expand Up @@ -151,11 +152,13 @@ csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
###############################
# VB Coding Conventions #
###############################
Expand Down
6 changes: 3 additions & 3 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ DISABLE:
- COPYPASTE # Comment to enable checks of excessive copy-pastes
- SPELL # Comment to enable checks of spelling mistakes
DISABLE_LINTERS:
- CSHARP_DOTNET_FORMAT # Not compatible with .NET 8 (yet)
- CSHARP_CSHARPIER # Not compatible with .NET 8 (yet)
- CSHARP_ROSLYNATOR # Not compatible with .NET 8 (yet)
- CSHARP_DOTNET_FORMAT # Not compatible with .NET 9 (yet)
- CSHARP_CSHARPIER # Not compatible with .NET 9 (yet)
- CSHARP_ROSLYNATOR # Not compatible with .NET 9 (yet)
- REPOSITORY_TRIVY # Unstable, leading to a lot of build failures
SHOW_ELAPSED_TIME: true
FILEIO_REPORTER: false
Expand Down
17 changes: 8 additions & 9 deletions AesExtra/AesCmac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
Expand All @@ -17,16 +16,16 @@ public sealed class AesCmac

/// <inheritdoc cref="KeyedHashAlgorithm.Create()" />
/// <remarks>This static override defaults to <see cref="AesCmac" />.</remarks>
public static new KeyedHashAlgorithm Create() => new AesCmac();
public static new KeyedHashAlgorithm Create()
{
return new AesCmac();
}

/// <inheritdoc cref="KeyedHashAlgorithm.Create(string)" />
public static new KeyedHashAlgorithm? Create(string algorithmName)
{
if (algorithmName == null)
{
throw new ArgumentNullException(nameof(algorithmName));
}
return algorithmName == nameof(AesCmac) ? Create() : null;
return algorithmName != null ? algorithmName == nameof(AesCmac) ? Create() : null
: throw new ArgumentNullException(nameof(algorithmName));
}

/// <summary>
Expand Down Expand Up @@ -100,7 +99,7 @@ public override byte[] Key
// In-place: X = CIPH_K(X)
void CIPH_K_InPlace(byte[] X_Base, int X_Offset = 0)
{
CryptoTransform.TransformBlock(X_Base, X_Offset, BLOCKSIZE, X_Base, X_Offset);
_ = CryptoTransform.TransformBlock(X_Base, X_Offset, BLOCKSIZE, X_Base, X_Offset);
}

// See: NIST SP 800-38B, Section 6.1
Expand Down Expand Up @@ -152,7 +151,7 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
}

// If we have a non-empty && non-full Partial block already -> append to that first.
if ((0 < PartialLength) && (PartialLength < BLOCKSIZE))
if (PartialLength is > 0 and < BLOCKSIZE)
{
var count = Math.Min(cbSize, BLOCKSIZE - PartialLength);
Array.Copy(array, ibStart, Partial, PartialLength, count);
Expand Down
23 changes: 14 additions & 9 deletions AesExtra/AesCtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
Expand All @@ -19,16 +18,16 @@ public sealed class AesCtr
const int FixedFeedbackSize = FixedBlockSize * 8; // bits

/// <inheritdoc cref="Aes.Create()" />
public static new Aes Create() => new AesCtr();
public static new Aes Create()
{
return new AesCtr();
}

/// <inheritdoc cref="Aes.Create(string)" />
public static new Aes? Create(string algorithmName)
{
if (algorithmName == null)
{
throw new ArgumentNullException(nameof(algorithmName));
}
return algorithmName == nameof(AesCtr) ? Create() : null;
return algorithmName != null ? algorithmName == nameof(AesCtr) ? Create() : null
: throw new ArgumentNullException(nameof(algorithmName));
}

AesCtr()
Expand Down Expand Up @@ -134,10 +133,16 @@ AesCtrTransform CreateTransform(byte[] rgbKey, byte[]? rgbIV)
}

/// <inheritdoc cref="AesManaged.CreateDecryptor(byte[], byte[])" />
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => CreateTransform(rgbKey, rgbIV);
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV)
{
return CreateTransform(rgbKey, rgbIV);
}

/// <inheritdoc cref="AesManaged.CreateEncryptor(byte[], byte[])" />
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => CreateTransform(rgbKey, rgbIV);
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV)
{
return CreateTransform(rgbKey, rgbIV);
}

/// <inheritdoc cref="AesManaged.GenerateIV" />
public override void GenerateIV()
Expand Down
3 changes: 1 addition & 2 deletions AesExtra/AesCtrTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
Expand Down Expand Up @@ -128,7 +127,7 @@ int ICryptoTransform.TransformBlock(byte[] inputBuffer, int inputOffset, int inp

for (var i = 0; i < inputCount / BLOCKSIZE; ++i)
{
TransformBlock(inputBuffer, inputOffset + i * BLOCKSIZE, outputBuffer, outputOffset + i * BLOCKSIZE);
TransformBlock(inputBuffer, inputOffset + (i * BLOCKSIZE), outputBuffer, outputOffset + (i * BLOCKSIZE));
}
return inputCount;
}
Expand Down
4 changes: 0 additions & 4 deletions AesExtra/AesExtra.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ SPDX-License-Identifier: MIT
<None Include="..\README.md" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions AesExtra/AesSiv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Linq;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
Expand Down Expand Up @@ -64,9 +62,9 @@ byte[] S2V(byte[][] associatedData, byte[] plaintext)
// D takes the role of the "end" in "xorend"
D.xor_InPlace(0, plaintext, plaintext.Length - BLOCKSIZE, BLOCKSIZE);
// Using Transform instead of Compute prevents cloning plaintext.
Cmac.TransformBlock(plaintext, 0, plaintext.Length - BLOCKSIZE, null, 0);
Cmac.TransformBlock(D, 0, BLOCKSIZE, null, 0);
Cmac.TransformFinalBlock([], 0, 0);
_ = Cmac.TransformBlock(plaintext, 0, plaintext.Length - BLOCKSIZE, null, 0);
_ = Cmac.TransformBlock(D, 0, BLOCKSIZE, null, 0);
_ = Cmac.TransformFinalBlock([], 0, 0);
return Cmac.Hash;
}
else
Expand Down
1 change: 0 additions & 1 deletion AesExtra/AssemblySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Runtime.CompilerServices;

[assembly: CLSCompliant(true)]
Expand Down
2 changes: 1 addition & 1 deletion AesExtra/CryptographicOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Dorssel.Security.Cryptography;

/// <summary>
/// This is a backport of .NET 6.0. Since this library is for .NET Standard 2.0 it uses <see cref="byte"/>[] instead of Span.
/// This is a backport of .NET 9. Since this library is for .NET Standard 2.0 it uses <see cref="byte"/>[] instead of Span.
/// <para/>
/// See:
/// <see href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptographicOperations.cs"/>
Expand Down
16 changes: 9 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ SPDX-License-Identifier: MIT
<Platforms>AnyCPU</Platforms>

<!-- Use the latest .NET SDK -->
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>

<!-- Use the latest C# language standard -->
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Be very strict -->
<WarningLevel>9999</WarningLevel>
Expand All @@ -31,6 +32,10 @@ SPDX-License-Identifier: MIT
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\strongname.snk</AssemblyOriginatorKeyFile>
<!--
See https://github.com/dotnet/roslyn/issues/41640
-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- Assembly metadata -->
<Product>dotnet-aes-extra</Product>
Expand All @@ -40,15 +45,11 @@ SPDX-License-Identifier: MIT
<!-- NuGet metadata -->
<Title>$(Product)</Title>
<Authors>$(Company)</Authors>
<Description>.NET Standard 2.0 implementation of AES-CTR, AES-CMAC, and AES-SIV.</Description>
<Description>.NET Standard 2.0 implementation of AES-CTR, AES-CMAC, and SIV-AES.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/dorssel/dotnet-aes-extra</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>

<!-- SourceLink -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
Expand All @@ -60,6 +61,7 @@ SPDX-License-Identifier: MIT
<Target Name="SetPackageVersion" AfterTargets="GetVersion">
<PropertyGroup>
<PackageVersion>$(GitVersion_MajorMinorPatch)</PackageVersion>
<PackageVersion Condition=" '$(GitVersion_MajorMinorPatch)' == '' ">0.9.99</PackageVersion>
</PropertyGroup>
</Target>

Expand Down
5 changes: 1 addition & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ SPDX-License-Identifier: MIT
<Project>
<ItemGroup>
<!-- all -->
<PackageVersion Include="GitVersion.MsBuild" Version="6.0.4" />
<!-- AesExtra -->
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="GitVersion.MsBuild" Version="6.0.5" />
<!-- UnitTests -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.3" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions UnitTests/AesCmac_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Create_Name()
[TestMethod]
public void Create_NullNameFails()
{
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
using var keyedHashAlgorithm = AesCmac.Create(null!);
});
Expand Down Expand Up @@ -55,7 +55,7 @@ public void Constructor_WithKey(int keySize)
[TestMethod]
public void Constructor_WithInvalidKeySize()
{
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
using var aesCmac = new AesCmac(new byte[42]);
});
Expand All @@ -64,7 +64,7 @@ public void Constructor_WithInvalidKeySize()
[TestMethod]
public void Constructor_WithNullKey()
{
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
using var aesCmac = new AesCmac(null!);
});
Expand Down Expand Up @@ -110,7 +110,7 @@ public void ComputeHash_Segmented()
var pos = 0;
void Transfer(int count)
{
aesCmac.TransformBlock(testVector.PT.ToArray(), pos, count, null, 0);
_ = aesCmac.TransformBlock(testVector.PT.ToArray(), pos, count, null, 0);
pos += count;
}

Expand All @@ -121,13 +121,13 @@ void Transfer(int count)
// complete the partial block precisely
Transfer(1);
// more than 1 block, but not an exact multiple
Transfer(2 * 16 - 3);
Transfer((2 * 16) - 3);
// topping off the partial block + again less than 1 block
Transfer(16);
// remainder
Transfer(testVector.PT.Length - pos);

aesCmac.TransformFinalBlock([], 0, 0);
_ = aesCmac.TransformFinalBlock([], 0, 0);

CollectionAssert.AreEqual(testVector.Tag.ToArray(), aesCmac.Hash);
}
Expand Down
Loading

0 comments on commit 3ad45c8

Please sign in to comment.