Skip to content

Commit

Permalink
Use separate key instances for span/array/array+offset test classes (#…
Browse files Browse the repository at this point in the history
…34199)

Because the key object generation was done in the algorithm-specific base class,
the triplet of interface types was using the key instances in parallel.

By moving the static variable (and initialization thereof) to each of the derived
classes, the key objects are unique per class, which matches the test parallelism.

Making the classes be part of the same test collection would also solve this problem,
which would save on a few random keygens, but would likely overall take more
time due to the number of tests that would be moved to sequential execution.
  • Loading branch information
bartonjs authored Mar 28, 2020
1 parent e85e352 commit 7557b78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace System.Security.Cryptography.Dsa.Tests
{
public abstract class DSASignatureFormatTests : DsaFamilySignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool SupportsSha2 => DSAFactory.SupportsFips186_3;
protected override string HashParameterName => "rgbHash";
protected override string SignatureParameterName => "rgbSignature";
Expand Down Expand Up @@ -50,7 +47,7 @@ private static KeyDescription OpenKey(in DSAParameters dsaParameters)
dsaParameters.Q.Length * 8);
}

private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
protected static IEnumerable<KeyDescription> LocalGenerateTestKeys()
{
if (DSAFactory.SupportsKeyGeneration)
{
Expand All @@ -73,6 +70,9 @@ private static IEnumerable<KeyDescription> LocalGenerateTestKeys()

public sealed class DsaArraySignatureFormatTests : DSASignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => true;

protected override byte[] SignHash(
Expand Down Expand Up @@ -114,6 +114,9 @@ protected override bool VerifyData(

public sealed class DsaArrayOffsetSignatureFormatTests : DSASignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => true;

protected override byte[] SignHash(
Expand Down Expand Up @@ -232,6 +235,9 @@ public void OffsetAndCountOutOfRange()

public sealed class DsaSpanSignatureFormatTests : DSASignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => false;

protected override byte[] SignHash(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace System.Security.Cryptography.EcDsa.Tests
{
public abstract class ECDsaSignatureFormatTests : DsaFamilySignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool SupportsSha2 => true;

private static KeyDescription CreateKey(ECCurve curve)
Expand All @@ -38,7 +35,7 @@ private static KeyDescription OpenKey(in ECParameters ecParameters)
dsa.KeySize);
}

private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
protected static IEnumerable<KeyDescription> LocalGenerateTestKeys()
{
if (ECDsaFactory.IsCurveValid(EccTestData.BrainpoolP160r1Key1.Curve.Oid))
{
Expand All @@ -58,8 +55,11 @@ private static IEnumerable<KeyDescription> LocalGenerateTestKeys()

public sealed class ECDsaArraySignatureFormatTests : ECDsaSignatureFormatTests
{
protected override bool IsArrayBased => true;
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => true;

protected override byte[] SignHash(
KeyDescription key,
byte[] hash,
Expand Down Expand Up @@ -99,6 +99,9 @@ protected override bool VerifyData(

public sealed class ECDsaArrayOffsetSignatureFormatTests : ECDsaSignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => true;

protected override byte[] SignHash(
Expand Down Expand Up @@ -217,6 +220,9 @@ public void OffsetAndCountOutOfRange()

public sealed class ECDsaSpanSignatureFormatTests : ECDsaSignatureFormatTests
{
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();

protected override KeyDescription[] GenerateTestKeys() => s_keys;
protected override bool IsArrayBased => false;

protected override byte[] SignHash(
Expand Down

0 comments on commit 7557b78

Please sign in to comment.