summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-01-18 14:41:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-01-18 14:41:27 +0700
commitf8439e967ac1853291d74262c4fcc8cbd04145a2 (patch)
tree0999d954df26ed4b961bf17ec80aff45ed8fd6d9 /crypto/test
parentFix ordering changes in Pkcs12Store (diff)
downloadBouncyCastle.NET-ed25519-f8439e967ac1853291d74262c4fcc8cbd04145a2.tar.xz
Overhaul DerObjectIdentifier and Asn1RelativeOid
- contents is now primary data
- don't generate identifier string during parsing
- improved validation
- add TryFromID methods
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/asn1/test/OIDTest.cs47
-rw-r--r--crypto/test/src/asn1/test/RelativeOidTest.cs4
2 files changed, 41 insertions, 10 deletions
diff --git a/crypto/test/src/asn1/test/OIDTest.cs b/crypto/test/src/asn1/test/OIDTest.cs
index 6b6993855..5c8142554 100644
--- a/crypto/test/src/asn1/test/OIDTest.cs
+++ b/crypto/test/src/asn1/test/OIDTest.cs
@@ -44,19 +44,23 @@ namespace Org.BouncyCastle.Asn1.Tests
 
 		private void CheckValid(string oid)
 		{
-			DerObjectIdentifier o = new DerObjectIdentifier(oid);
+            Assert.True(DerObjectIdentifier.TryFromID(oid, out var ignore));
+
+            DerObjectIdentifier o = new DerObjectIdentifier(oid);
 			o = (DerObjectIdentifier)Asn1Object.FromByteArray(o.GetEncoded());
 
 			if (!o.Id.Equals(oid))
 			{
 				Fail("failed oid check: " + oid);
 			}
-		}
+        }
 
-		private void CheckInvalid(string oid)
+        private void CheckInvalid(string oid)
 		{
-			try
-			{
+            Assert.False(DerObjectIdentifier.TryFromID(oid, out var ignore));
+
+            try
+            {
 				new DerObjectIdentifier(oid);
 				Fail("failed to catch bad oid: " + oid);
 			}
@@ -95,8 +99,20 @@ namespace Org.BouncyCastle.Asn1.Tests
 			CheckValid("1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872");
 			CheckValid("1.2.123.12345678901.1.1.1");
 			CheckValid("2.25.196556539987194312349856245628873852187.1");
-
-			CheckInvalid("0");
+            CheckValid("0.0");
+            CheckValid("0.0.1");
+            CheckValid("0.39");
+            CheckValid("0.39.1");
+            CheckValid("1.0");
+            CheckValid("1.0.1");
+            CheckValid("1.39");
+            CheckValid("1.39.1");
+            CheckValid("2.0");
+            CheckValid("2.0.1");
+            CheckValid("2.40");
+            CheckValid("2.40.1");
+
+            CheckInvalid("0");
 			CheckInvalid("1");
 			CheckInvalid("2");
 			CheckInvalid("3.1");
@@ -110,8 +126,16 @@ namespace Org.BouncyCastle.Asn1.Tests
 			CheckInvalid(".12.345.77.234.");
 			CheckInvalid("1.2.3.4.A.5");
 			CheckInvalid("1,2");
+            CheckInvalid("0.40");
+            CheckInvalid("0.40.1");
+            CheckInvalid("0.100");
+            CheckInvalid("0.100.1");
+            CheckInvalid("1.40");
+            CheckInvalid("1.40.1");
+            CheckInvalid("1.100");
+            CheckInvalid("1.100.1");
 
-			BranchCheck("1.1", "2.2");
+            BranchCheck("1.1", "2.2");
 
 			OnCheck("1.1", "1.1", false);
 			OnCheck("1.1", "1.2", false);
@@ -121,9 +145,12 @@ namespace Org.BouncyCastle.Asn1.Tests
 			OnCheck("1.12", "1.1.2", false);
 			OnCheck("1.1", "1.1.1", true);
 			OnCheck("1.1", "1.1.2", true);
-		}
+            OnCheck("1.2.3.4.5.6", "1.2.3.4.5.6", false);
+            OnCheck("1.2.3.4.5.6", "1.2.3.4.5.6.7", true);
+            OnCheck("1.2.3.4.5.6", "1.2.3.4.5.6.7.8", true);
+        }
 
-		[Test]
+        [Test]
 		public void TestFunction()
 		{
 			string resultText = Perform().ToString();
diff --git a/crypto/test/src/asn1/test/RelativeOidTest.cs b/crypto/test/src/asn1/test/RelativeOidTest.cs
index f3d5ba13b..c7d13af68 100644
--- a/crypto/test/src/asn1/test/RelativeOidTest.cs
+++ b/crypto/test/src/asn1/test/RelativeOidTest.cs
@@ -40,6 +40,8 @@ namespace Org.BouncyCastle.Asn1.Tests
 
         private void CheckValid(string oid)
         {
+            Assert.True(Asn1RelativeOid.TryFromID(oid, out var ignore));
+
             Asn1RelativeOid o = new Asn1RelativeOid(oid);
 			o = (Asn1RelativeOid)Asn1Object.FromByteArray(o.GetEncoded());
 
@@ -51,6 +53,8 @@ namespace Org.BouncyCastle.Asn1.Tests
 
         private void CheckInvalid(string oid)
         {
+            Assert.False(Asn1RelativeOid.TryFromID(oid, out var ignore));
+
             try
             {
                 new Asn1RelativeOid(oid);