diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 2d16853231758..cfb593d70b54d 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -85,6 +85,7 @@ The PR that reveals the implementation of the ` throw new PlatformNotSupportedException(SR.SystemSecurityCryptographyAlgorithms_PlatformNotSupported); [UnsupportedOSPlatform("browser")] + [Obsolete(Obsoletions.CryptoConfigEncodeOIDMessage, DiagnosticId = Obsoletions.CryptoConfigEncodeOIDDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static byte[] EncodeOID(string str) => throw new PlatformNotSupportedException(SR.SystemSecurityCryptographyAlgorithms_PlatformNotSupported); [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")] diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CryptoConfig.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CryptoConfig.cs index ff73ce605054d..e7d3919b2f3cc 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CryptoConfig.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CryptoConfig.cs @@ -508,6 +508,7 @@ public static void AddOID(string oid, params string[] names) } [UnsupportedOSPlatform("browser")] + [Obsolete(Obsoletions.CryptoConfigEncodeOIDMessage, DiagnosticId = Obsoletions.CryptoConfigEncodeOIDDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static byte[] EncodeOID(string str) { if (str == null) diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs index 067a50a10015d..b724370944024 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs @@ -348,25 +348,30 @@ public static void CreateFromName_CtorArguments() [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public static void EncodeOID_Validation() { +#pragma warning disable SYSLIB0031 // EncodeOID is obsolete Assert.Throws(() => CryptoConfig.EncodeOID(null)); Assert.Throws(() => CryptoConfig.EncodeOID(string.Empty)); Assert.Throws(() => CryptoConfig.EncodeOID("BAD.OID")); Assert.Throws(() => CryptoConfig.EncodeOID("1.2.BAD.OID")); Assert.Throws(() => CryptoConfig.EncodeOID("1." + uint.MaxValue)); +#pragma warning restore SYSLIB0031 } [Fact] [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public static void EncodeOID_Compat() { +#pragma warning disable SYSLIB0031 // EncodeOID is obsolete string actual = CryptoConfig.EncodeOID("-1.2.-3").ByteArrayToHex(); Assert.Equal("0602DAFD", actual); // Negative values not checked +#pragma warning restore SYSLIB0031 } [Fact] [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public static void EncodeOID_Length_Boundary() { +#pragma warning disable SYSLIB0031 // EncodeOID is obsolete string valueToRepeat = "1.1"; // Build a string like 1.11.11.11. ... .11.1, which has 0x80 separators. @@ -379,6 +384,7 @@ public static void EncodeOID_Length_Boundary() // and would just clutter up this test, so only verify it doesn't throw. s = new StringBuilder(valueToRepeat.Length * 0x7f).Insert(0, valueToRepeat, 0x7f).ToString(); CryptoConfig.EncodeOID(s); +#pragma warning restore SYSLIB0031 } [Theory] @@ -392,9 +398,11 @@ public static void EncodeOID_Value_Boundary_And_Compat(uint elementValue, string { // Boundary cases in EncodeOID; output may produce the wrong value mathematically due to encoding // algorithm semantics but included here for compat reasons. +#pragma warning disable SYSLIB0031 // EncodeOID is obsolete byte[] actual = CryptoConfig.EncodeOID("1." + elementValue.ToString()); byte[] expected = expectedEncoding.HexToByteArray(); Assert.Equal(expected, actual); +#pragma warning restore SYSLIB0031 } [Theory] @@ -404,12 +412,14 @@ public static void EncodeOID_Value_Boundary_And_Compat(uint elementValue, string [InlineData("MD5", "1.2.840.113549.2.5", "06082A864886F70D0205")] public static void MapAndEncodeOID(string alg, string expectedOid, string expectedEncoding) { +#pragma warning disable SYSLIB0031 // EncodeOID is obsolete string oid = CryptoConfig.MapNameToOID(alg); Assert.Equal(expectedOid, oid); byte[] actual = CryptoConfig.EncodeOID(oid); byte[] expected = expectedEncoding.HexToByteArray(); Assert.Equal(expected, actual); +#pragma warning restore SYSLIB0031 } private static void VerifyCreateFromName(string name)