From 164e897445a2db0973551ed74ba84556c1b31da0 Mon Sep 17 00:00:00 2001 From: Frans van Dorsselaer <17404029+dorssel@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:53:26 +0100 Subject: [PATCH] Use MSTest SDK --- .github/workflows/dotnet.yml | 32 ++++++++++++--- AesExtra/AesExtra.csproj | 11 +---- Directory.Build.props | 22 ++++++---- Directory.Packages.props | 4 -- ...{AssemblySettings.cs => MSTestSettings.cs} | 2 +- UnitTests/NistAesCmacSampleTestVector.cs | 27 ++++++++---- UnitTests/NistAesCtrSampleTestVector.cs | 39 ++++++++++++------ UnitTests/RfcAesSivTestVector.cs | 41 +++++++++++++------ UnitTests/UnitTests.csproj | 12 +++--- global.json | 3 ++ 10 files changed, 128 insertions(+), 65 deletions(-) rename UnitTests/{AssemblySettings.cs => MSTestSettings.cs} (67%) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index dd5be4b..359bbd8 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -13,7 +13,11 @@ on: pull_request: branches: [master] -permissions: read-all +permissions: + contents: read + issues: read + checks: write + pull-requests: write jobs: build: @@ -28,17 +32,35 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 + - name: Cache + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('global.json', '**/Directory.Packages.props') }} + - name: Restore dependencies - run: dotnet restore + run: | + dotnet restore - name: Build - run: dotnet build --configuration Release --no-restore + run: | + dotnet build --configuration Release --no-restore - name: Test - run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" + run: | + dotnet test --configuration Release --no-build \ + -p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml" - name: Package - run: dotnet pack --configuration Release --no-build + run: | + dotnet pack --configuration Release --no-build + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: | + **/TestResults/*.trx - name: Upload Package Artifact uses: actions/upload-artifact@v4 diff --git a/AesExtra/AesExtra.csproj b/AesExtra/AesExtra.csproj index 08f2985..e46d95a 100644 --- a/AesExtra/AesExtra.csproj +++ b/AesExtra/AesExtra.csproj @@ -7,24 +7,15 @@ SPDX-License-Identifier: MIT - netstandard2.0 + netstandard2.0 Dorssel.Security.Cryptography Dorssel.Security.Cryptography.AesExtra true - true Dorssel.Security.Cryptography.AesExtra True - - True - - - - true - - diff --git a/Directory.Build.props b/Directory.Build.props index c7d7b77..ea96447 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,38 +9,37 @@ SPDX-License-Identifier: MIT - AnyCPU + true + false - net9.0 + net9.0 13.0 + enable enable 9999 - enable true latest-all true + true true + true true false false false $(MSBuildThisFileDirectory)\strongname.snk - true dotnet-aes-extra Frans van Dorsselaer - Copyright (C) $([System.DateTime]::UtcNow.ToString("yyyy")) $(Company) $(Product) @@ -58,6 +57,15 @@ SPDX-License-Identifier: MIT + + + + $([System.DateTime]::Parse($(GitVersion_CommitDate)).ToString("yyyy")) + $([System.DateTime]::UtcNow.ToString("yyyy")) + Copyright (C) $(CopyrightYear) $(Company) + + + $(GitVersion_MajorMinorPatch) diff --git a/Directory.Packages.props b/Directory.Packages.props index aad7f62..a8f6740 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,10 +9,6 @@ SPDX-License-Identifier: MIT - - - - \ No newline at end of file diff --git a/UnitTests/AssemblySettings.cs b/UnitTests/MSTestSettings.cs similarity index 67% rename from UnitTests/AssemblySettings.cs rename to UnitTests/MSTestSettings.cs index 3b6f233..1564fb5 100644 --- a/UnitTests/AssemblySettings.cs +++ b/UnitTests/MSTestSettings.cs @@ -2,5 +2,5 @@ // // SPDX-License-Identifier: MIT -[assembly: CLSCompliant(false)] +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] [assembly: DiscoverInternals] diff --git a/UnitTests/NistAesCmacSampleTestVector.cs b/UnitTests/NistAesCmacSampleTestVector.cs index 2ad08ed..32a99d4 100644 --- a/UnitTests/NistAesCmacSampleTestVector.cs +++ b/UnitTests/NistAesCmacSampleTestVector.cs @@ -4,10 +4,12 @@ // SPDX-License-Identifier: MIT // SPDX-License-Identifier: LicenseRef-NIST-OtherDataWorks +using System.Runtime.Serialization; using System.Text.RegularExpressions; namespace UnitTests; +[DataContract] sealed partial record NistAesCmacSampleTestVector { public static IReadOnlyList All { get; } @@ -20,17 +22,26 @@ static byte[] FromHexString(string hexWithWhiteSpace) return Convert.FromHexString(WhitespaceRegex().Replace(hexWithWhiteSpace, "")); } - public string Name { get; } - public ReadOnlyMemory Key { get; } - public ReadOnlyMemory PT { get; } - public ReadOnlyMemory Tag { get; } + [DataMember] + string _Name { get; init; } + [DataMember] + byte[] _Key { get; init; } + [DataMember] + byte[] _PT { get; init; } + [DataMember] + byte[] _Tag { get; init; } + + public string Name => _Name; + public ReadOnlyMemory Key => _Key; + public ReadOnlyMemory PT => _PT; + public ReadOnlyMemory Tag => _Tag; NistAesCmacSampleTestVector(string Name, string Key, string PT, string Tag) { - this.Name = Name; - this.Key = FromHexString(Key); - this.PT = FromHexString(PT); - this.Tag = FromHexString(Tag); + _Name = Name; + _Key = FromHexString(Key); + _PT = FromHexString(PT); + _Tag = FromHexString(Tag); } static NistAesCmacSampleTestVector() diff --git a/UnitTests/NistAesCtrSampleTestVector.cs b/UnitTests/NistAesCtrSampleTestVector.cs index f137525..cb7366c 100644 --- a/UnitTests/NistAesCtrSampleTestVector.cs +++ b/UnitTests/NistAesCtrSampleTestVector.cs @@ -4,28 +4,43 @@ // SPDX-License-Identifier: MIT // SPDX-License-Identifier: LicenseRef-NIST-OtherDataWorks +using System.Runtime.Serialization; using System.Text; using System.Text.RegularExpressions; namespace UnitTests; +[DataContract] sealed partial record NistAesCtrSampleTestVector { public static IReadOnlyList All { get; } - public string Section { get; } - public string Name { get; } - public ReadOnlyMemory Key { get; } - public ReadOnlyMemory InitialCounter { get; } - public ReadOnlyMemory Plaintext { get; } - public ReadOnlyMemory Ciphertext { get; } + [DataMember] + string _Section { get; init; } + [DataMember] + string _Name { get; init; } + [DataMember] + byte[] _Key { get; init; } + [DataMember] + byte[] _InitialCounter { get; init; } + [DataMember] + byte[] _Plaintext { get; init; } + [DataMember] + byte[] _Ciphertext { get; init; } + + public string Section => _Section; + public string Name => _Name; + public ReadOnlyMemory Key => _Key; + public ReadOnlyMemory InitialCounter => _InitialCounter; + public ReadOnlyMemory Plaintext => _Plaintext; + public ReadOnlyMemory Ciphertext => _Ciphertext; static readonly char[] lineSeparators = ['\r', '\n']; NistAesCtrSampleTestVector(string Section, string Name, string Data) { - this.Section = Section; - this.Name = Name; + _Section = Section; + _Name = Name; var keyHex = new StringBuilder(); var initialCounterHex = new StringBuilder(); @@ -56,10 +71,10 @@ sealed partial record NistAesCtrSampleTestVector } } } - Key = Convert.FromHexString(keyHex.ToString()); - InitialCounter = Convert.FromHexString(initialCounterHex.ToString()); - Plaintext = Convert.FromHexString(plaintextHex.ToString()); - Ciphertext = Convert.FromHexString(ciphertextHex.ToString()); + _Key = Convert.FromHexString(keyHex.ToString()); + _InitialCounter = Convert.FromHexString(initialCounterHex.ToString()); + _Plaintext = Convert.FromHexString(plaintextHex.ToString()); + _Ciphertext = Convert.FromHexString(ciphertextHex.ToString()); } [GeneratedRegex("([0-9a-fA-F]+)$")] diff --git a/UnitTests/RfcAesSivTestVector.cs b/UnitTests/RfcAesSivTestVector.cs index 312238b..82c527e 100644 --- a/UnitTests/RfcAesSivTestVector.cs +++ b/UnitTests/RfcAesSivTestVector.cs @@ -5,10 +5,12 @@ // SPDX-License-Identifier: LicenseRef-IETF-Trust using System.Collections.ObjectModel; +using System.Runtime.Serialization; using System.Text.RegularExpressions; namespace UnitTests; +[DataContract] sealed partial record RfcAesSivTestVector { public static IReadOnlyList All { get; } @@ -21,31 +23,44 @@ static byte[] FromHexString(string hexWithWhiteSpace) return Convert.FromHexString(WhitespaceRegex().Replace(hexWithWhiteSpace, "")); } - public string Name { get; } - public ReadOnlyMemory Key { get; } - public ReadOnlyCollection> AD { get; } - public ReadOnlyMemory? Nonce { get; } - public ReadOnlyMemory Plaintext { get; } - public ReadOnlyMemory output { get; } + [DataMember] + string _Name { get; init; } + [DataMember] + byte[] _Key { get; init; } + [DataMember] + byte[][] _AD { get; init; } + [DataMember] + byte[]? _Nonce { get; init; } + [DataMember] + byte[] _Plaintext { get; init; } + [DataMember] + byte[] _output { get; init; } + + public string Name => _Name; + public ReadOnlyMemory Key => _Key; + public ReadOnlyCollection> AD => new((from item in _AD select (ReadOnlyMemory)item.AsMemory()).ToList()); + public ReadOnlyMemory? Nonce => _Nonce is null ? null : (ReadOnlyMemory?)_Nonce.AsMemory(); + public ReadOnlyMemory Plaintext => _Plaintext; + public ReadOnlyMemory output => _output; RfcAesSivTestVector(string Name, string Key, string[] AD, string? Nonce, string Plaintext, string output) { - this.Name = Name; - this.Key = FromHexString(Key); + _Name = Name; + _Key = FromHexString(Key); { - var associatedData = new ReadOnlyMemory[AD.Length]; + var associatedData = new byte[AD.Length][]; for (var i = 0; i < AD.Length; i++) { associatedData[i] = FromHexString(AD[i]); } - this.AD = new(associatedData); + _AD = associatedData; } if (Nonce is not null) { - this.Nonce = FromHexString(Nonce); + _Nonce = FromHexString(Nonce); } - this.Plaintext = FromHexString(Plaintext); - this.output = FromHexString(output); + _Plaintext = FromHexString(Plaintext); + _output = FromHexString(output); } static RfcAesSivTestVector() diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index d54565a..e1e368b 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -4,19 +4,21 @@ SPDX-FileCopyrightText: 2022 Frans van Dorsselaer SPDX-License-Identifier: MIT --> - + + $(MainTargetFramework) True True + + + 17.12.0 + + - - - - diff --git a/global.json b/global.json index db8627a..2f7c4cc 100644 --- a/global.json +++ b/global.json @@ -3,5 +3,8 @@ "version": "9.0.100", "allowPrerelease": false, "rollForward": "latestFeature" + }, + "msbuild-sdks": { + "MSTest.Sdk": "3.6.3" } }