summary refs log tree commit diff
path: root/crypto/test/src/asn1
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@gmail.com>2022-06-21 22:00:34 +0700
committerPeter Dettman <peter.dettman@gmail.com>2022-06-21 22:00:34 +0700
commit62b3de2a28363f721f1bc3ecb1b9aa8990596d2d (patch)
treec8f297b54bd1f336b9c27388b4f9b01afd0047a7 /crypto/test/src/asn1
parentRemove junk files (diff)
downloadBouncyCastle.NET-ed25519-62b3de2a28363f721f1bc3ecb1b9aa8990596d2d.tar.xz
Remove ApplicationSpecific classes
Diffstat (limited to 'crypto/test/src/asn1')
-rw-r--r--crypto/test/src/asn1/test/DERApplicationSpecificTest.cs145
-rw-r--r--crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs1
-rw-r--r--crypto/test/src/asn1/test/RegressionTest.cs1
-rw-r--r--crypto/test/src/asn1/test/TagTest.cs57
4 files changed, 28 insertions, 176 deletions
diff --git a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs b/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs
deleted file mode 100644
index e505acd9d..000000000
--- a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs
+++ /dev/null
@@ -1,145 +0,0 @@
-using System;
-using System.Text;
-
-using NUnit.Framework;
-
-using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Encoders;
-using Org.BouncyCastle.Utilities.Test;
-
-namespace Org.BouncyCastle.Asn1.Tests
-{
-	[TestFixture]
-	public class DerApplicationSpecificTest
-		: SimpleTest
-	{
-		private static readonly byte[] impData = Hex.Decode("430109");
-
-		private static readonly byte[] certData = Hex.Decode(
-			  "7F218201897F4E8201495F290100420E44454356434145504153533030317F49"
-			+ "81FD060A04007F00070202020202811CD7C134AA264366862A18302575D1D787"
-			+ "B09F075797DA89F57EC8C0FF821C68A5E62CA9CE6C1C299803A6C1530B514E18"
-			+ "2AD8B0042A59CAD29F43831C2580F63CCFE44138870713B1A92369E33E2135D2"
-			+ "66DBB372386C400B8439040D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C"
-			+ "1E6EFDEE12C07D58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D376"
-			+ "1402CD851CD7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A793"
-			+ "9F863904393EE8E06DB6C7F528F8B4260B49AA93309824D92CDB1807E5437EE2"
-			+ "E26E29B73A7111530FA86B350037CB9415E153704394463797139E148701015F"
-			+ "200E44454356434145504153533030317F4C0E060904007F0007030102015301"
-			+ "C15F25060007000400015F24060009000400015F37384CCF25C59F3612EEE188"
-			+ "75F6C5F2E2D21F0395683B532A26E4C189B71EFE659C3F26E0EB9AEAE9986310"
-			+ "7F9B0DADA16414FFA204516AEE2B");
-
-        private static readonly byte[] sampleData = Hex.Decode(
-            "613280020780a106060456000104a203020101a305a103020101be80288006025101020109a080b2800a01000000000000000000");
-
-        public override string Name
-		{
-			get { return "DerApplicationSpecific"; }
-		}
-
-        private void TestTaggedObject()
-        {
-            // boolean explicit, int tagNo, ASN1Encodable obj
-            bool isExplicit = false;
-
-            // Type1 ::= VisibleString
-            DerVisibleString type1 = new DerVisibleString("Jones");
-            if (!Arrays.AreEqual(Hex.Decode("1A054A6F6E6573"), type1.GetEncoded()))
-            {
-                Fail("ERROR: expected value doesn't match!");
-            }
-
-            // Type2 ::= [APPLICATION 3] IMPLICIT Type1
-            isExplicit = false;
-            DerApplicationSpecific type2 = new DerApplicationSpecific(isExplicit, 3, type1);
-            // type2.isConstructed()
-            if (!Arrays.AreEqual(Hex.Decode("43054A6F6E6573"), type2.GetEncoded()))
-            {
-                Fail("ERROR: expected value doesn't match!");
-            }
-
-            // Type3 ::= [2] Type2
-            isExplicit = true;
-            DerTaggedObject type3 = new DerTaggedObject(isExplicit, 2, type2);
-            if (!Arrays.AreEqual(Hex.Decode("A20743054A6F6E6573"), type3.GetEncoded()))
-            {
-                Fail("ERROR: expected value doesn't match!");
-            }
-
-            // Type4 ::= [APPLICATION 7] IMPLICIT Type3
-            isExplicit = false;
-            DerApplicationSpecific type4 = new DerApplicationSpecific(isExplicit, 7, type3);
-            if (!Arrays.AreEqual(Hex.Decode("670743054A6F6E6573"), type4.GetEncoded()))
-            {
-                Fail("ERROR: expected value doesn't match!");
-            }
-
-            // Type5 ::= [2] IMPLICIT Type2
-            isExplicit = false;
-            DerTaggedObject type5 = new DerTaggedObject(isExplicit, 2, type2);
-            // type5.isConstructed()
-            if (!Arrays.AreEqual(Hex.Decode("82054A6F6E6573"), type5.GetEncoded()))
-            {
-                Fail("ERROR: expected value doesn't match!");
-            }
-        }
-
-        public override void PerformTest()
-		{
-            TestTaggedObject();
-
-            DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData);
-
-            if (1 != appSpec.ApplicationTag)
-            {
-                Fail("wrong tag detected");
-            }
-
-            DerInteger val = new DerInteger(9);
-
-			DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val);
-
-			if (!AreEqual(impData, tagged.GetEncoded()))
-			{
-				Fail("implicit encoding failed");
-			}
-
-			DerInteger recVal = (DerInteger) tagged.GetObject(Asn1Tags.Integer);
-
-			if (!val.Equals(recVal))
-			{
-				Fail("implicit read back failed");
-			}
-
-			DerApplicationSpecific certObj = (DerApplicationSpecific)
-				Asn1Object.FromByteArray(certData);
-
-			if (!certObj.IsConstructed() || certObj.ApplicationTag != 33)
-			{
-				Fail("parsing of certificate data failed");
-			}
-
-			byte[] encoded = certObj.GetDerEncoded();
-
-			if (!Arrays.AreEqual(certData, encoded))
-			{
-				Fail("re-encoding of certificate data failed");
-			}
-		}
-
-		public static void Main(
-			string[] args)
-		{
-			RunTest(new DerApplicationSpecificTest());
-		}
-
-		[Test]
-		public void TestFunction()
-		{
-			string resultText = Perform().ToString();
-
-			Assert.AreEqual(Name + ": Okay", resultText);
-		}
-	}
-}
diff --git a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs
index 396268f4b..a296a806e 100644
--- a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs
+++ b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs
@@ -23,7 +23,6 @@ namespace Org.BouncyCastle.Asn1.Tests
                 new BerSequence(new DerPrintableString("hello world")),
                 new BerSet(new DerPrintableString("hello world")),
                 new BerTaggedObject(0, new DerPrintableString("hello world")),
-				new DerApplicationSpecific(0, data),
                 new DerBitString(data),
                 new DerBmpString("hello world"),
                 DerBoolean.True,
diff --git a/crypto/test/src/asn1/test/RegressionTest.cs b/crypto/test/src/asn1/test/RegressionTest.cs
index 7bc10b079..fe612ba1b 100644
--- a/crypto/test/src/asn1/test/RegressionTest.cs
+++ b/crypto/test/src/asn1/test/RegressionTest.cs
@@ -24,7 +24,6 @@ namespace Org.BouncyCastle.Asn1.Tests
 			new CscaMasterListTest(),
 			new DataGroupHashUnitTest(),
 			new DeclarationOfMajorityUnitTest(),
-			new DerApplicationSpecificTest(),
 			new DerUtf8StringTest(),
 			new EncryptedPrivateKeyInfoTest(),
 			new EqualsAndHashCodeTest(),
diff --git a/crypto/test/src/asn1/test/TagTest.cs b/crypto/test/src/asn1/test/TagTest.cs
index fd6995c44..44b4fd4f1 100644
--- a/crypto/test/src/asn1/test/TagTest.cs
+++ b/crypto/test/src/asn1/test/TagTest.cs
@@ -38,54 +38,54 @@ namespace Org.BouncyCastle.Asn1.Tests
 		{
             Asn1InputStream aIn = new Asn1InputStream(longTagged);
 
-            DerApplicationSpecific app = (DerApplicationSpecific)aIn.ReadObject();
-
-            aIn = new Asn1InputStream(app.GetContents());
-
-            app = (DerApplicationSpecific)aIn.ReadObject();
+			Asn1TaggedObject app = (Asn1TaggedObject)aIn.ReadObject();
+			if (!app.HasTag(Asn1Tags.Application, 5))
+			{
+				Fail("unexpected tag value found - not 5");
+			}
 
-            aIn = new Asn1InputStream(app.GetContents());
+			app = app.GetExplicitBaseTagged();
+			if (!app.HasTag(Asn1Tags.Application, 19))
+			{
+				Fail("unexpected tag value found - not 19");
+			}
 
-            Asn1TaggedObject tagged = (Asn1TaggedObject)aIn.ReadObject();
+			Asn1Sequence seq = (Asn1Sequence)app.GetBaseUniversal(false, Asn1Tags.Sequence);
 
-			if (tagged.TagNo != 32)
+			Asn1TaggedObject tagged = (Asn1TaggedObject)seq[0];
+			if (!tagged.HasContextTag(32))
 			{
 				Fail("unexpected tag value found - not 32");
 			}
 
-			tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded());
-
-			if (tagged.TagNo != 32)
+            tagged = (Asn1TaggedObject)Asn1Object.FromByteArray(tagged.GetEncoded());
+			if (!tagged.HasContextTag(32))
 			{
 				Fail("unexpected tag value found on recode - not 32");
 			}
 
-			tagged = (Asn1TaggedObject) aIn.ReadObject();
-
-			if (tagged.TagNo != 33)
+			tagged = (Asn1TaggedObject)seq[1];
+			if (!tagged.HasContextTag(33))
 			{
 				Fail("unexpected tag value found - not 33");
 			}
 
 			tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded());
-
-			if (tagged.TagNo != 33)
+			if (!tagged.HasContextTag(33))
 			{
 				Fail("unexpected tag value found on recode - not 33");
 			}
 
 			aIn = new Asn1InputStream(longAppSpecificTag);
 
-			app = (DerApplicationSpecific)aIn.ReadObject();
-
-			if (app.ApplicationTag != 97)
+			app = (Asn1TaggedObject)aIn.ReadObject();
+			if (!app.HasTag(Asn1Tags.Application, 97))
 			{
 				Fail("incorrect tag number read");
 			}
 
-			app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded());
-
-			if (app.ApplicationTag != 97)
+			app = (Asn1TaggedObject)Asn1Object.FromByteArray(app.GetEncoded());
+			if (!app.HasTag(Asn1Tags.Application, 97))
 			{
 				Fail("incorrect tag number read on recode");
 			}
@@ -94,17 +94,16 @@ namespace Org.BouncyCastle.Asn1.Tests
 			for (int i = 0; i < 100; ++i)
 			{
 				int testTag = (sr.NextInt() & int.MaxValue) >> sr.Next(26);
-				app = new DerApplicationSpecific(testTag, new byte[]{ 1 });
-				app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded());
+				app = new DerTaggedObject(false, Asn1Tags.Application, testTag, new DerOctetString(new byte[]{ 1 }));
+				app = (Asn1TaggedObject)Asn1Object.FromByteArray(app.GetEncoded());
 
-				if (app.ApplicationTag != testTag)
+				if (!app.HasTag(Asn1Tags.Application, testTag))
 				{
-					Fail("incorrect tag number read on recode (random test value: " + testTag + ")");
-				}
+                    Fail("incorrect tag number read on recode (random test value: " + testTag + ")");
+                }
 			}
 
-            tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, new DerInteger(1)));
-
+			tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, new DerInteger(1)));
             if (!AreEqual(taggedInteger, tagged.GetEncoded()))
             {
                 Fail("incorrect encoding for implicit explicit tagged integer");