Use friendly name in exception if OID value is null. (#37110)
authorKevin Jones <kevin@vcsjones.com>
Thu, 28 May 2020 16:14:37 +0000 (12:14 -0400)
committerGitHub <noreply@github.com>
Thu, 28 May 2020 16:14:37 +0000 (12:14 -0400)
src/libraries/Common/src/System/Security/Cryptography/EccSecurityTransforms.cs
src/libraries/System.Security.Cryptography.Algorithms/tests/ECDiffieHellmanTests.cs
src/libraries/System.Security.Cryptography.Algorithms/tests/ECDsaTests.cs

index 09c8502..301851b 100644 (file)
@@ -60,7 +60,7 @@ namespace System.Security.Cryptography
                     break;
                 default:
                     throw new PlatformNotSupportedException(
-                        SR.Format(SR.Cryptography_CurveNotSupported, curve.Oid.Value));
+                        SR.Format(SR.Cryptography_CurveNotSupported, curve.Oid.Value ?? curve.Oid.FriendlyName));
             }
 
             GenerateKey(keySize);
index e3abdd0..2fc7649 100644 (file)
@@ -50,6 +50,14 @@ namespace System.Security.Cryptography.EcDiffieHellman.Tests
         }
 
         [Fact]
+        public void Create_InvalidECCurveFriendlyName_ThrowsPlatformNotSupportedException()
+        {
+            ECCurve curve = ECCurve.CreateFromFriendlyName("bad potato");
+            PlatformNotSupportedException pnse = Assert.Throws<PlatformNotSupportedException>(() => ECDiffieHellman.Create(curve));
+            Assert.Contains("'bad potato'", pnse.Message);
+        }
+
+        [Fact]
         public static void Equivalence_Hash()
         {
             using (ECDiffieHellman ecdh = ECDiffieHellmanFactory.Create())
index ad178b4..b42ebf0 100644 (file)
@@ -19,6 +19,14 @@ namespace System.Security.Cryptography.Algorithms.Tests
         }
 
         [Fact]
+        public void Create_InvalidECCurveFriendlyName_ThrowsPlatformNotSupportedException()
+        {
+            ECCurve curve = ECCurve.CreateFromFriendlyName("bad potato");
+            PlatformNotSupportedException pnse = Assert.Throws<PlatformNotSupportedException>(() => ECDsa.Create(curve));
+            Assert.Contains("'bad potato'", pnse.Message);
+        }
+
+        [Fact]
         public void NotSupportedBaseMethods_Throw()
         {
             using (var ecdsa = new OverrideAbstractECDsa(ECDsaFactory.Create()))