Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ internal static unsafe bool ExportPkcs8KeyBlob(

Interop.NCrypt.PBE_PARAMS pbeParams = default;
Span<byte> salt = new Span<byte>(pbeParams.rgbSalt, Interop.NCrypt.PBE_PARAMS.RgbSaltSize);
#if NET
RandomNumberGenerator.Fill(salt);
#else
CngHelpers.GetRandomBytes(salt);
#endif
pbeParams.Params.cbSalt = salt.Length;
pbeParams.Params.iIterations = kdfCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Formats.Asn1;
using System.Security.Cryptography.Rsa.Tests;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -189,7 +190,7 @@ internal static void AssertPrivateKeyEquals(CompositeMLDsaAlgorithm algorithm, R
RSAParameters expectedRsaParameters = RSAParametersFromRawPrivateKey(expectedTradKey);
RSAParameters actualRsaParameters = RSAParametersFromRawPrivateKey(actualTradKey);

Rsa.Tests.ImportExport.AssertKeyEquals(expectedRsaParameters, actualRsaParameters);
RSATestHelpers.AssertKeyEquals(expectedRsaParameters, actualRsaParameters);
},
_ => Assert.Equal(expectedTradKey, actualTradKey),
_ => Assert.Equal(expectedTradKey, actualTradKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void PaddedExport()

// DP is the most likely to fail, the rest just otherwise ensure that Export
// isn't losing data.
AssertKeyEquals(diminishedDPParameters, exported);
RSATestHelpers.AssertKeyEquals(diminishedDPParameters, exported);
}

[Fact]
Expand Down Expand Up @@ -94,7 +94,7 @@ public static void LargeKeyImportExport()

exported = rsa.ExportParameters(true);

AssertKeyEquals(imported, exported);
RSATestHelpers.AssertKeyEquals(imported, exported);
}
}

Expand All @@ -119,7 +119,7 @@ public static void UnusualExponentImportExport()

// Exponent is the most likely to fail, the rest just otherwise ensure that Export
// isn't losing data.
AssertKeyEquals(unusualExponentParameters, exported);
RSATestHelpers.AssertKeyEquals(unusualExponentParameters, exported);
}

[Fact]
Expand All @@ -136,7 +136,7 @@ public static void ImportExport1032()
exportedPublic = rsa.ExportParameters(false);
}

AssertKeyEquals(imported, exported);
RSATestHelpers.AssertKeyEquals(imported, exported);

Assert.Equal(exportedPublic.Modulus, imported.Modulus);
Assert.Equal(exportedPublic.Exponent, imported.Exponent);
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void ImportReset()
Assert.Equal(imported.Modulus.Length * 8, rsa.KeySize);

exported = rsa.ExportParameters(true);
AssertKeyEquals(imported, exported);
RSATestHelpers.AssertKeyEquals(imported, exported);
}
}

Expand Down Expand Up @@ -207,18 +207,18 @@ public static void MultiExport()
RSAParameters exportedPrivate3 = rsa.ExportParameters(true);
RSAParameters exportedPublic3 = rsa.ExportParameters(false);

AssertKeyEquals(imported, exportedPrivate);
RSATestHelpers.AssertKeyEquals(imported, exportedPrivate);

Assert.Equal(imported.Modulus, exportedPublic.Modulus);
Assert.Equal(imported.Exponent, exportedPublic.Exponent);
Assert.Null(exportedPublic.D);
ValidateParameters(ref exportedPublic);

AssertKeyEquals(exportedPrivate, exportedPrivate2);
AssertKeyEquals(exportedPrivate, exportedPrivate3);
RSATestHelpers.AssertKeyEquals(exportedPrivate, exportedPrivate2);
RSATestHelpers.AssertKeyEquals(exportedPrivate, exportedPrivate3);

AssertKeyEquals(exportedPublic, exportedPublic2);
AssertKeyEquals(exportedPublic, exportedPublic3);
RSATestHelpers.AssertKeyEquals(exportedPublic, exportedPublic2);
RSATestHelpers.AssertKeyEquals(exportedPublic, exportedPublic3);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ private static void ReadWriteKey(
arrayExport = writeArrayFunc(rsa);

RSAParameters rsaParameters = rsa.ExportParameters(isPrivateKey);
ImportExport.AssertKeyEquals(expected, rsaParameters);
RSATestHelpers.AssertKeyEquals(expected, rsaParameters);
}

// Public key formats are stable.
Expand All @@ -1478,7 +1478,7 @@ private static void ReadWriteKey(
Assert.Equal(arrayExport.Length, bytesRead);

RSAParameters rsaParameters = rsa.ExportParameters(isPrivateKey);
ImportExport.AssertKeyEquals(expected, rsaParameters);
RSATestHelpers.AssertKeyEquals(expected, rsaParameters);

Assert.False(
writeSpanFunc(rsa, Span<byte>.Empty, out int bytesWritten),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void ImportFromPem_RSAPrivateKey_Simple()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand All @@ -68,7 +68,7 @@ public static void ImportFromPem_Pkcs8UnEncrypted_Simple()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public static void ImportFromPem_Pkcs8UnEncrypted_UnrelatedAlgorithmIsIgnored()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand All @@ -114,7 +114,7 @@ public static void ImportFromPem_SubjectPublicKeyInfo_Simple()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(false);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
}
}

Expand All @@ -136,7 +136,7 @@ public static void ImportFromPem_SubjectPublicKeyInfo_IgnoresUnrelatedAlgorithm(
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(false);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
}
}

Expand All @@ -154,7 +154,7 @@ public static void ImportFromPem_RSAPublicKey_Simple()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(false);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters.ToPublic(), rsaParameters);
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ public static void ImportFromPem_RSAPrivateKey_PrecedingUnrelatedPem()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand All @@ -216,7 +216,7 @@ public static void ImportFromPem_RSAPrivateKey_PrecedingMalformedPem()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand All @@ -243,7 +243,7 @@ public static void ImportFromPem_RSAPrivateKey_IgnoresOtherAlgorithms()
rsa.ImportFromPem(pem);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ public static void ImportFromEncryptedPem_Pkcs8Encrypted_Char_Simple()
rsa.ImportFromEncryptedPem(pem, (ReadOnlySpan<char>)"test");
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand All @@ -428,7 +428,7 @@ public static void ImportFromEncryptedPem_Pkcs8Encrypted_Byte_Simple()
rsa.ImportFromEncryptedPem(pem, "test"u8);
RSAParameters rsaParameters = rsa.ExportParameters(true);

ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
RSATestHelpers.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
// TODO This is used in multiple tests files, so move this into a common Helpers class.
public partial class ImportExport
public class RSATestHelpers
{
internal static void AssertKeyEquals(in RSAParameters expected, in RSAParameters actual)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,15 +996,15 @@ public static void FromToXml()
{
rsaPub.FromXmlString(xmlPub);

ImportExport.AssertKeyEquals(pubOnly, rsaPub.ExportParameters(false));
RSATestHelpers.AssertKeyEquals(pubOnly, rsaPub.ExportParameters(false));
}

using (RSA rsaPriv = RSAFactory.Create())
{
rsaPriv.FromXmlString(xmlPriv);

ImportExport.AssertKeyEquals(pubPriv, rsaPriv.ExportParameters(true));
ImportExport.AssertKeyEquals(pubOnly, rsaPriv.ExportParameters(false));
RSATestHelpers.AssertKeyEquals(pubPriv, rsaPriv.ExportParameters(true));
RSATestHelpers.AssertKeyEquals(pubOnly, rsaPriv.ExportParameters(false));
}
}
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ private static void TestReadXml(string xmlString, in RSAParameters expectedParam

bool includePrivateParameters = expectedParameters.D != null;

ImportExport.AssertKeyEquals(
RSATestHelpers.AssertKeyEquals(
expectedParameters,
rsa.ExportParameters(includePrivateParameters));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@
<Compile Include="$(CommonPath)Interop\Windows\NCrypt\Interop.SignVerify.cs"
Link="Common\Interop\Windows\NCrypt\Interop.SignVerify.cs" />

<Compile Include="System\Security\Cryptography\CngHelpers.cs" />
<Compile Include="System\Security\Cryptography\CngExtensions.cs" />
<Compile Include="System\Security\Cryptography\CngIdentifierExtensions.cs" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\MLDsa\MLDsaTestsData.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\MLDsa\MLDsaTestsData.Ietf.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\MLDsa\MLDsaTestsData.Ietf.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\SlhDsa\SlhDsaAlgorithmTests.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\SlhDsa\SlhDsaAlgorithmTests.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\SlhDsa\SlhDsaContractTests.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\EncryptDecrypt.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\TestData.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void RSAParametersToBlob_PublicOnly()
Exponent = TestData.RSA1024Params.Exponent,
};

ImportExport.AssertKeyEquals(expected, exported);
RSATestHelpers.AssertKeyEquals(expected, exported);
}

[Fact]
Expand All @@ -135,7 +135,7 @@ public static void RSAParametersToBlob_PublicPrivate()

RSAParameters expected = TestData.RSA1024Params;

ImportExport.AssertKeyEquals(expected, exported);
RSATestHelpers.AssertKeyEquals(expected, exported);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\EncryptDecrypt.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\TestData.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void VerifyParameterCtor()
{
using (RSA rsa = new RSAOpenSsl(TestData.RSA1032Parameters))
{
ImportExport.AssertKeyEquals(TestData.RSA1032Parameters, rsa.ExportParameters(true));
RSATestHelpers.AssertKeyEquals(TestData.RSA1032Parameters, rsa.ExportParameters(true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\EncryptDecrypt.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\ImportExport.Shared.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\KeyGeneration.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSAFactory.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\RSATestHelpers.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\SignVerify.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\RSA\TestData.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void CreateWithParameters(RSAParameters parameters)
exportedPrivate = rsa.ExportParameters(true);
}

ImportExport.AssertKeyEquals(parameters, exportedPrivate);
RSATestHelpers.AssertKeyEquals(parameters, exportedPrivate);
}

[Fact]
Expand Down
Loading
Loading