From 296a22544c63b43e72b8fbfe8c70bf46768d5d16 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 25 Oct 2022 21:47:21 +0700 Subject: FIne-grained SupportedOSPlatform attributes --- crypto/src/security/DotNetUtilities.cs | 27 ++++++++++++++++++++++--- crypto/test/src/security/test/TestDotNetUtil.cs | 9 +++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/crypto/src/security/DotNetUtilities.cs b/crypto/src/security/DotNetUtilities.cs index ccfb2b2b8..3a7c5f0cb 100644 --- a/crypto/src/security/DotNetUtilities.cs +++ b/crypto/src/security/DotNetUtilities.cs @@ -18,9 +18,6 @@ namespace Org.BouncyCastle.Security /// /// A class containing methods to interface the BouncyCastle world to the .NET Crypto world. /// -#if NET5_0_OR_GREATER - [SupportedOSPlatform("windows")] -#endif public static class DotNetUtilities { /// @@ -153,33 +150,51 @@ namespace Org.BouncyCastle.Security throw new ArgumentException("Unsupported algorithm specified", "privateKey"); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaKeyParameters rsaKey) { // TODO This appears to not work for private keys (when no CRT info) return CreateRSAProvider(ToRSAParameters(rsaKey)); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaKeyParameters rsaKey, CspParameters csp) { // TODO This appears to not work for private keys (when no CRT info) return CreateRSAProvider(ToRSAParameters(rsaKey), csp); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey) { return CreateRSAProvider(ToRSAParameters(privKey)); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey, CspParameters csp) { return CreateRSAProvider(ToRSAParameters(privKey), csp); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaPrivateKeyStructure privKey) { return CreateRSAProvider(ToRSAParameters(privKey)); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif public static RSA ToRSA(RsaPrivateKeyStructure privKey, CspParameters csp) { return CreateRSAProvider(ToRSAParameters(privKey), csp); @@ -229,6 +244,9 @@ namespace Org.BouncyCastle.Security return BigIntegers.AsUnsignedByteArray(size, n); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif private static RSACryptoServiceProvider CreateRSAProvider(RSAParameters rp) { CspParameters csp = new CspParameters(); @@ -236,6 +254,9 @@ namespace Org.BouncyCastle.Security return CreateRSAProvider(rp, csp); } +#if NET5_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif private static RSACryptoServiceProvider CreateRSAProvider(RSAParameters rp, CspParameters csp) { RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider(csp); diff --git a/crypto/test/src/security/test/TestDotNetUtil.cs b/crypto/test/src/security/test/TestDotNetUtil.cs index 3ca3efdbb..b83a94a36 100644 --- a/crypto/test/src/security/test/TestDotNetUtil.cs +++ b/crypto/test/src/security/test/TestDotNetUtil.cs @@ -20,12 +20,13 @@ using Org.BouncyCastle.X509; namespace Org.BouncyCastle.Security.Tests { [TestFixture] -#if NET5_0_OR_GREATER - [SupportedOSPlatform("windows")] -#endif public class TestDotNetUtilities { - [Test] +//#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER + [SupportedOSPlatform("windows")] +#endif + [Test] public void TestRsaInterop() { for (int i = 0; i < 100; ++i) -- cgit 1.4.1