Skip to content

Commit

Permalink
Use .NET 9 SDK
Browse files Browse the repository at this point in the history
dorssel committed Nov 17, 2024
1 parent 837bf73 commit 6ca8bb8
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
@@ -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 #
###############################
@@ -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 #
###############################
6 changes: 3 additions & 3 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 8 additions & 9 deletions AesExtra/AesCmac.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
@@ -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>
@@ -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
@@ -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);
23 changes: 14 additions & 9 deletions AesExtra/AesCtr.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
@@ -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()
@@ -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()
3 changes: 1 addition & 2 deletions AesExtra/AesCtrTransform.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Security.Cryptography;

namespace Dorssel.Security.Cryptography;
@@ -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;
}
4 changes: 0 additions & 4 deletions AesExtra/AesExtra.csproj
Original file line number Diff line number Diff line change
@@ -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
@@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: MIT

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

namespace Dorssel.Security.Cryptography;
@@ -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
1 change: 0 additions & 1 deletion AesExtra/AssemblySettings.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

using System;
using System.Runtime.CompilerServices;

[assembly: CLSCompliant(true)]
2 changes: 1 addition & 1 deletion AesExtra/CryptographicOperations.cs
Original file line number Diff line number Diff line change
@@ -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"/>
16 changes: 9 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -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>
@@ -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>
@@ -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>
@@ -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>

5 changes: 1 addition & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -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
@@ -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!);
});
@@ -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]);
});
@@ -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!);
});
@@ -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;
}

@@ -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);
}
42 changes: 21 additions & 21 deletions UnitTests/AesCtrTransform_Tests.cs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public void Constructor()
[DataRow(BLOCKSIZE * 8)]
public void Constructor_InvalidIVSize(int ivSize)
{
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
using var transform = new AesCtrTransform(new byte[ivSize], AesEcbTransform);
});
@@ -47,10 +47,10 @@ public void Constructor_InvalidIVSize(int ivSize)
public void Constructor_TransformInvalidInputBlockSize()
{
var mockTransform = new Mock<ICryptoTransform>();
mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE + 1);
mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE + 1);
_ = mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);

Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
using var transform = new AesCtrTransform(InitialCounter, mockTransform.Object);
});
@@ -60,10 +60,10 @@ public void Constructor_TransformInvalidInputBlockSize()
public void Constructor_TransformInvalidOutputBlockSize()
{
var mockTransform = new Mock<ICryptoTransform>();
mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE + 1);
_ = mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE + 1);

Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
using var transform = new AesCtrTransform(InitialCounter, mockTransform.Object);
});
@@ -131,7 +131,7 @@ public void TransformBlock_ValidSize(int size)
[DataRow(BLOCKSIZE + 1)]
public void TransformBlock_InvalidSizeFails(int size)
{
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
{
using ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformBlock(new byte[size], 0, size, new byte[size], 0);
@@ -143,7 +143,7 @@ public void TransformBlock_AfterFinalFails()
{
using ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformFinalBlock([], 0, 0);
Assert.ThrowsException<InvalidOperationException>(() =>
_ = Assert.ThrowsException<InvalidOperationException>(() =>
{
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
});
@@ -155,7 +155,7 @@ public void TransformBlock_AfterDisposeFails()
ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
transform.Dispose();
Assert.ThrowsException<ObjectDisposedException>(() =>
_ = Assert.ThrowsException<ObjectDisposedException>(() =>
{
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
});
@@ -165,15 +165,15 @@ public void TransformBlock_AfterDisposeFails()
public void TransformBlock_TransformInvalidReturn()
{
var mockTransform = new Mock<ICryptoTransform>();
mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);
mockTransform.SetupSequence(m => m.TransformBlock(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<byte[]>(), It.IsAny<int>()))
_ = mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.SetupSequence(m => m.TransformBlock(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<byte[]>(), It.IsAny<int>()))
.Returns(BLOCKSIZE)
.Returns(BLOCKSIZE + 1);

using ICryptoTransform transform = new AesCtrTransform(InitialCounter, mockTransform.Object);
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
});
@@ -196,7 +196,7 @@ public void TransformFinalBlock_ValidSize(int size)
[DataRow(2 * BLOCKSIZE)]
public void TransformFinalBlock_InvalidSizeFails(int size)
{
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
{
using ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformFinalBlock(new byte[size], 0, size);
@@ -208,7 +208,7 @@ public void TransformFinalBlock_AfterFinalFails()
{
using ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformFinalBlock([], 0, 0);
Assert.ThrowsException<InvalidOperationException>(() =>
_ = Assert.ThrowsException<InvalidOperationException>(() =>
{
_ = transform.TransformFinalBlock([], 0, 0);
});
@@ -220,7 +220,7 @@ public void TransformFinalBlock_AfterDisposeFails()
ICryptoTransform transform = new AesCtrTransform(InitialCounter, AesEcbTransform);
_ = transform.TransformBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE, new byte[BLOCKSIZE], 0);
transform.Dispose();
Assert.ThrowsException<ObjectDisposedException>(() =>
_ = Assert.ThrowsException<ObjectDisposedException>(() =>
{
_ = transform.TransformFinalBlock([], 0, 0);
});
@@ -230,12 +230,12 @@ public void TransformFinalBlock_AfterDisposeFails()
public void TransformFinalBlock_TransformInvalidReturn()
{
var mockTransform = new Mock<ICryptoTransform>();
mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);
mockTransform.Setup(m => m.TransformFinalBlock(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new byte[BLOCKSIZE + 1]);
_ = mockTransform.SetupGet(m => m.InputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.SetupGet(m => m.OutputBlockSize).Returns(BLOCKSIZE);
_ = mockTransform.Setup(m => m.TransformFinalBlock(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new byte[BLOCKSIZE + 1]);

using ICryptoTransform transform = new AesCtrTransform(InitialCounter, mockTransform.Object);
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
_ = transform.TransformFinalBlock(new byte[BLOCKSIZE], 0, BLOCKSIZE);
});
8 changes: 4 additions & 4 deletions UnitTests/AesCtr_Tests.cs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public void Create_Name()
[TestMethod]
public void Create_NullNameFails()
{
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
using var aes = AesCtr.Create(null!);
});
@@ -66,7 +66,7 @@ public void Mode_CannotChange()
{
using var aes = AesCtr.Create();
Assert.AreEqual(CipherMode.ECB, aes.Mode); // DevSkim: ignore DS187371
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
aes.Mode = CipherMode.CBC;
});
@@ -88,7 +88,7 @@ public void Padding_CannotChange()
using var aes = AesCtr.Create();
var padding = aes.Padding;
Assert.AreEqual(PaddingMode.None, padding);
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
aes.Padding = PaddingMode.PKCS7;
});
@@ -109,7 +109,7 @@ public void FeedbackSize_CannotChange()
{
using var aes = AesCtr.Create();
Assert.AreEqual(aes.BlockSize, aes.FeedbackSize);
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
aes.FeedbackSize = 8;
});
34 changes: 17 additions & 17 deletions UnitTests/AesSiv_Tests.cs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public void Constructor_WithKey(int keySize)
[TestMethod]
public void Constructor_WithInvalidKeySize()
{
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
using var aesSiv = new AesSiv(new byte[42]);
});
@@ -32,7 +32,7 @@ public void Constructor_WithInvalidKeySize()
[TestMethod]
public void Constructor_WithNullKey()
{
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
using var aesSiv = new AesSiv(null!);
});
@@ -57,7 +57,7 @@ public void Dispose_Double()
public void Encrypt_NullPlaintextThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Encrypt(null!, TestCiphertext);
});
@@ -67,7 +67,7 @@ public void Encrypt_NullPlaintextThrows()
public void Encrypt_NullCiphertextThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Encrypt(TestPlaintext, null!);
});
@@ -77,7 +77,7 @@ public void Encrypt_NullCiphertextThrows()
public void Encrypt_NullAssociatedDataThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Encrypt(TestPlaintext, TestCiphertext, null!);
});
@@ -87,7 +87,7 @@ public void Encrypt_NullAssociatedDataThrows()
public void Encrypt_NullAssociatedDataItemThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Encrypt(TestPlaintext, TestCiphertext, [null!]);
});
@@ -97,7 +97,7 @@ public void Encrypt_NullAssociatedDataItemThrows()
public void Encrypt_InvalidCiphertextLengthThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Encrypt(TestPlaintext, new byte[TestCiphertext.Length + 1]);
});
@@ -118,7 +118,7 @@ public void Encrypt_TooManyAssociatedDataThrows()
var associatedData = Enumerable.Range(1, 127).Select(i => Array.Empty<byte>()).ToArray();

using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Encrypt(TestPlaintext, new byte[TestCiphertext.Length], associatedData);
});
@@ -128,7 +128,7 @@ public void Encrypt_TooManyAssociatedDataThrows()
public void Decrypt_NullCiphertextThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Decrypt(null!, TestPlaintext);
});
@@ -138,7 +138,7 @@ public void Decrypt_NullCiphertextThrows()
public void Decrypt_NullPlaintextThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Decrypt(TestCiphertext, null!);
});
@@ -148,7 +148,7 @@ public void Decrypt_NullPlaintextThrows()
public void Decrypt_NullAssociatedDataThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
aesSiv.Decrypt(TestCiphertext, TestPlaintext, null!);
});
@@ -158,7 +158,7 @@ public void Decrypt_NullAssociatedDataThrows()
public void Decrypt_NullAssociatedDataItemThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Decrypt(TestCiphertext, TestPlaintext, [null!]);
});
@@ -168,7 +168,7 @@ public void Decrypt_NullAssociatedDataItemThrows()
public void Decrypt_InvalidCiphertextLengthThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Decrypt(new byte[15], TestPlaintext);
});
@@ -178,7 +178,7 @@ public void Decrypt_InvalidCiphertextLengthThrows()
public void Decrypt_InvalidPlaintextLengthThrows()
{
using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Decrypt(TestCiphertext, new byte[TestPlaintext.Length + 1]);
});
@@ -201,7 +201,7 @@ public void Decrypt_TooManyAssociatedDataThrows()
var associatedData = Enumerable.Range(1, 127).Select(i => Array.Empty<byte>()).ToArray();

using var aesSiv = new AesSiv(TestKey);
Assert.ThrowsException<ArgumentException>(() =>
_ = Assert.ThrowsException<ArgumentException>(() =>
{
aesSiv.Decrypt(TestCiphertext, new byte[TestPlaintext.Length], associatedData);
});
@@ -212,7 +212,7 @@ public void Decrypt_InvalidAuthenticationThrows()
{
using var aesSiv = new AesSiv(TestKey);
aesSiv.Encrypt(TestPlaintext, TestCiphertext, [1]);
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
aesSiv.Decrypt(TestCiphertext, TestPlaintext, [2]);
});
@@ -231,7 +231,7 @@ public void EmptyPlaintext()
using var aesSiv = new AesSiv(TestKey);
aesSiv.Decrypt(cipherText, []);
}
Assert.ThrowsException<CryptographicException>(() =>
_ = Assert.ThrowsException<CryptographicException>(() =>
{
using var aesSiv = new AesSiv(TestKey);
aesSiv.Decrypt(cipherText, [], [2]);
2 changes: 1 addition & 1 deletion UnitTests/NistAesCmacSampleDataSourceAttribute.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
namespace UnitTests;

[AttributeUsage(AttributeTargets.Method)]
internal sealed class NistAesCmacSampleDataSourceAttribute
sealed class NistAesCmacSampleDataSourceAttribute
: Attribute
, ITestDataSource
{
2 changes: 1 addition & 1 deletion UnitTests/NistAesCmacSampleTestVector.cs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

namespace UnitTests;

public partial record NistAesCmacSampleTestVector
sealed partial record NistAesCmacSampleTestVector
{
public static IReadOnlyList<NistAesCmacSampleTestVector> All { get; }

2 changes: 1 addition & 1 deletion UnitTests/NistAesCtrSampleDataSourceAttribute.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
namespace UnitTests;

[AttributeUsage(AttributeTargets.Method)]
internal sealed class NistAesCtrSampleDataSourceAttribute
sealed class NistAesCtrSampleDataSourceAttribute
: Attribute
, ITestDataSource
{
12 changes: 6 additions & 6 deletions UnitTests/NistAesCtrSampleTestVector.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

namespace UnitTests;

public partial record NistAesCtrSampleTestVector
sealed partial record NistAesCtrSampleTestVector
{
public static IReadOnlyList<NistAesCtrSampleTestVector> All { get; }

@@ -20,7 +20,7 @@ public partial record NistAesCtrSampleTestVector
public ReadOnlyMemory<byte> Plaintext { get; }
public ReadOnlyMemory<byte> Ciphertext { get; }

private static readonly char[] lineSeparators = ['\r', '\n'];
static readonly char[] lineSeparators = ['\r', '\n'];

NistAesCtrSampleTestVector(string Section, string Name, string Data)
{
@@ -40,19 +40,19 @@ public partial record NistAesCtrSampleTestVector
var hex = match.Groups[1].Value;
if (line.StartsWith("Key") || line == hex)
{
keyHex.Append(hex);
_ = keyHex.Append(hex);
}
else if (line.StartsWith("Init. Counter"))
{
initialCounterHex.Append(hex);
_ = initialCounterHex.Append(hex);
}
else if (line.StartsWith("Plaintext"))
{
plaintextHex.Append(hex);
_ = plaintextHex.Append(hex);
}
else if (line.StartsWith("Ciphertext"))
{
ciphertextHex.Append(hex);
_ = ciphertextHex.Append(hex);
}
}
}
2 changes: 1 addition & 1 deletion UnitTests/RfcAesSivTestVector.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

namespace UnitTests;

public partial record RfcAesSivTestVector
sealed partial record RfcAesSivTestVector
{
public static IReadOnlyList<RfcAesSivTestVector> All { get; }

2 changes: 1 addition & 1 deletion UnitTests/RfcAesSivTestVectorSourceAttribute.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
namespace UnitTests;

[AttributeUsage(AttributeTargets.Method)]
internal sealed class RfcAesSivTestVectorSourceAttribute
sealed class RfcAesSivTestVectorSourceAttribute
: Attribute
, ITestDataSource
{
2 changes: 0 additions & 2 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: MIT
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<SignAssembly>True</SignAssembly>
</PropertyGroup>
@@ -17,7 +16,6 @@ SPDX-License-Identifier: MIT
<PackageReference Include="Moq" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="System.IO.Pipelines" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.403",
"version": "9.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
}

0 comments on commit 6ca8bb8

Please sign in to comment.