Skip to content

Commit

Permalink
Use MSTest SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
dorssel committed Nov 25, 2024
1 parent a4a37dd commit 164e897
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 65 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ on:
pull_request:
branches: [master]

permissions: read-all
permissions:
contents: read
issues: read
checks: write
pull-requests: write

jobs:
build:
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions AesExtra/AesExtra.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ SPDX-License-Identifier: MIT
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Dorssel.Security.Cryptography</RootNamespace>
<AssemblyName>Dorssel.Security.Cryptography.AesExtra</AssemblyName>

<IsPackable>true</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>Dorssel.Security.Cryptography.AesExtra</PackageId>
<SignAssembly>True</SignAssembly>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<None Include="..\LICENSE.txt" Pack="true" PackagePath="" Visible="false" />
<None Include="..\README.md" Pack="true" PackagePath="" Visible="false" />
Expand Down
22 changes: 15 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,37 @@ SPDX-License-Identifier: MIT
<!-- Sane defaults; override in project where needed -->

<PropertyGroup>
<Platforms>AnyCPU</Platforms>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' != 'true'">false</ContinuousIntegrationBuild>

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

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

<!-- Be very strict -->
<WarningLevel>9999</WarningLevel>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisLevel>latest-all</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CheckForOverflowUnderflow Condition="'$(Configuration)' == 'Debug'">true</CheckForOverflowUnderflow>

<!-- Common defaults -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<InvariantGlobalization>true</InvariantGlobalization>
<SelfContained>false</SelfContained>
<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>
<Company>Frans van Dorsselaer</Company>
<Copyright>Copyright (C) $([System.DateTime]::UtcNow.ToString("yyyy")) $(Company)</Copyright>

<!-- NuGet metadata -->
<Title>$(Product)</Title>
Expand All @@ -58,6 +57,15 @@ SPDX-License-Identifier: MIT
<PackageReference Include="GitVersion.MsBuild" PrivateAssets="all" />
</ItemGroup>

<Target Name="SetCopyright" AfterTargets="GetVersion">
<PropertyGroup>
<!-- For deterministic builds, use the commit year as the copyright year. -->
<CopyrightYear Condition="$(ContinuousIntegrationBuild)">$([System.DateTime]::Parse($(GitVersion_CommitDate)).ToString("yyyy"))</CopyrightYear>
<CopyrightYear Condition="!$(ContinuousIntegrationBuild)">$([System.DateTime]::UtcNow.ToString("yyyy"))</CopyrightYear>
<Copyright>Copyright (C) $(CopyrightYear) $(Company)</Copyright>
</PropertyGroup>
</Target>

<Target Name="SetPackageVersion" AfterTargets="GetVersion">
<PropertyGroup>
<PackageVersion>$(GitVersion_MajorMinorPatch)</PackageVersion>
Expand Down
4 changes: 0 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ SPDX-License-Identifier: MIT
<!-- all -->
<PackageVersion Include="GitVersion.MsBuild" Version="6.0.5" />
<!-- UnitTests -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<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="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//
// SPDX-License-Identifier: MIT

[assembly: CLSCompliant(false)]
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
[assembly: DiscoverInternals]
27 changes: 19 additions & 8 deletions UnitTests/NistAesCmacSampleTestVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NistAesCmacSampleTestVector> All { get; }
Expand All @@ -20,17 +22,26 @@ static byte[] FromHexString(string hexWithWhiteSpace)
return Convert.FromHexString(WhitespaceRegex().Replace(hexWithWhiteSpace, ""));
}

public string Name { get; }
public ReadOnlyMemory<byte> Key { get; }
public ReadOnlyMemory<byte> PT { get; }
public ReadOnlyMemory<byte> 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<byte> Key => _Key;
public ReadOnlyMemory<byte> PT => _PT;
public ReadOnlyMemory<byte> 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()
Expand Down
39 changes: 27 additions & 12 deletions UnitTests/NistAesCtrSampleTestVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NistAesCtrSampleTestVector> All { get; }

public string Section { get; }
public string Name { get; }
public ReadOnlyMemory<byte> Key { get; }
public ReadOnlyMemory<byte> InitialCounter { get; }
public ReadOnlyMemory<byte> Plaintext { get; }
public ReadOnlyMemory<byte> 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<byte> Key => _Key;
public ReadOnlyMemory<byte> InitialCounter => _InitialCounter;
public ReadOnlyMemory<byte> Plaintext => _Plaintext;
public ReadOnlyMemory<byte> 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();
Expand Down Expand Up @@ -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]+)$")]
Expand Down
41 changes: 28 additions & 13 deletions UnitTests/RfcAesSivTestVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RfcAesSivTestVector> All { get; }
Expand All @@ -21,31 +23,44 @@ static byte[] FromHexString(string hexWithWhiteSpace)
return Convert.FromHexString(WhitespaceRegex().Replace(hexWithWhiteSpace, ""));
}

public string Name { get; }
public ReadOnlyMemory<byte> Key { get; }
public ReadOnlyCollection<ReadOnlyMemory<byte>> AD { get; }
public ReadOnlyMemory<byte>? Nonce { get; }
public ReadOnlyMemory<byte> Plaintext { get; }
public ReadOnlyMemory<byte> 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<byte> Key => _Key;
public ReadOnlyCollection<ReadOnlyMemory<byte>> AD => new((from item in _AD select (ReadOnlyMemory<byte>)item.AsMemory()).ToList());
public ReadOnlyMemory<byte>? Nonce => _Nonce is null ? null : (ReadOnlyMemory<byte>?)_Nonce.AsMemory();
public ReadOnlyMemory<byte> Plaintext => _Plaintext;
public ReadOnlyMemory<byte> 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<byte>[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()
Expand Down
12 changes: 7 additions & 5 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ SPDX-FileCopyrightText: 2022 Frans van Dorsselaer
SPDX-License-Identifier: MIT
-->
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk">

<PropertyGroup>
<TargetFramework>$(MainTargetFramework)</TargetFramework>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<SignAssembly>True</SignAssembly>
</PropertyGroup>

<PropertyGroup>
<!-- Updates to transitive MSTest.Sdk dependencies -->
<MicrosoftNETTestSdkVersion>17.12.0</MicrosoftNETTestSdkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"version": "9.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"MSTest.Sdk": "3.6.3"
}
}

0 comments on commit 164e897

Please sign in to comment.