summary refs log tree commit diff
path: root/crypto/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/src/asn1
parentRemove junk files (diff)
downloadBouncyCastle.NET-ed25519-62b3de2a28363f721f1bc3ecb1b9aa8990596d2d.tar.xz
Remove ApplicationSpecific classes
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r--crypto/src/asn1/ASN1StreamParser.cs12
-rw-r--r--crypto/src/asn1/Asn1TaggedObject.cs88
-rw-r--r--crypto/src/asn1/BERTaggedObjectParser.cs4
-rw-r--r--crypto/src/asn1/BerApplicationSpecific.cs47
-rw-r--r--crypto/src/asn1/BerApplicationSpecificParser.cs19
-rw-r--r--crypto/src/asn1/DLApplicationSpecific.cs28
-rw-r--r--crypto/src/asn1/DLTaggedObjectParser.cs7
-rw-r--r--crypto/src/asn1/DerApplicationSpecific.cs235
-rw-r--r--crypto/src/asn1/IAsn1ApplicationSpecificParser.cs11
-rw-r--r--crypto/src/asn1/util/Asn1Dump.cs4
10 files changed, 3 insertions, 452 deletions
diff --git a/crypto/src/asn1/ASN1StreamParser.cs b/crypto/src/asn1/ASN1StreamParser.cs
index 3281310c0..f805f68a5 100644
--- a/crypto/src/asn1/ASN1StreamParser.cs
+++ b/crypto/src/asn1/ASN1StreamParser.cs
@@ -71,12 +71,7 @@ namespace Org.BouncyCastle.Asn1
 
                 int tagClass = tagHdr & Asn1Tags.Private;
                 if (0 != tagClass)
-                {
-                    if (Asn1Tags.Application == tagClass)
-                        return new BerApplicationSpecificParser(tagNo, sp);
-
                     return new BerTaggedObjectParser(tagClass, tagNo, sp);
-                }
 
                 return sp.ParseImplicitConstructedIL(tagNo);
 			}
@@ -94,13 +89,6 @@ namespace Org.BouncyCastle.Asn1
                 {
                     bool isConstructed = (tagHdr & Asn1Tags.Constructed) != 0;
 
-                    // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecific types removed.
-                    if (Asn1Tags.Application == tagClass)
-                    {
-                        // This cast is ensuring the current user-expected return type.
-                        return (DLApplicationSpecific)sp.LoadTaggedDL(tagClass, tagNo, isConstructed);
-                    }
-
                     return new DLTaggedObjectParser(tagClass, tagNo, isConstructed, sp);
                 }
 
diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs
index 3bc339c83..8882cdcb7 100644
--- a/crypto/src/asn1/Asn1TaggedObject.cs
+++ b/crypto/src/asn1/Asn1TaggedObject.cs
@@ -93,9 +93,6 @@ namespace Org.BouncyCastle.Asn1
 
         protected override bool Asn1Equals(Asn1Object asn1Object)
         {
-            if (asn1Object is DerApplicationSpecific)
-                return asn1Object.CallAsn1Equals(this);
-
             Asn1TaggedObject that = asn1Object as Asn1TaggedObject;
             if (null == that || this.tagNo != that.tagNo || this.tagClass != that.tagClass)
                 return false;
@@ -194,61 +191,6 @@ namespace Org.BouncyCastle.Asn1
         }
 
         /**
-         * Return the contents of this object as a byte[]
-         *
-         * @return the encoded contents of the object.
-         */
-        // TODO Need this public if/when DerApplicationSpecific extends Asn1TaggedObject
-        internal byte[] GetContents()
-        {
-            try
-            {
-                byte[] baseEncoding = obj.GetEncoded(Asn1Encoding);
-                if (IsExplicit())
-                    return baseEncoding;
-
-                MemoryStream input = new MemoryStream(baseEncoding, false);
-                int tag = input.ReadByte();
-                Asn1InputStream.ReadTagNumber(input, tag);
-                int length = Asn1InputStream.ReadLength(input, (int)(input.Length - input.Position), false);
-                int remaining = (int)(input.Length - input.Position);
-
-                // For indefinite form, account for end-of-contents octets
-                int contentsLength = length < 0 ? remaining - 2 : remaining;
-                if (contentsLength < 0)
-                    throw new InvalidOperationException("failed to get contents");
-
-                byte[] contents = new byte[contentsLength];
-                Array.Copy(baseEncoding, baseEncoding.Length - remaining, contents, 0, contentsLength);
-                return contents;
-            }
-            catch (IOException e)
-            {
-                throw new InvalidOperationException("failed to get contents", e);
-            }
-        }
-
-        internal bool IsConstructed()
-        {
-            switch (explicitness)
-            {
-            case DeclaredImplicit:
-            {
-                Asn1Object baseObject = obj.ToAsn1Object();
-                if (baseObject is Asn1Sequence || baseObject is Asn1Set)
-                    return true;
-
-                Asn1TaggedObject baseTagged = baseObject as Asn1TaggedObject;
-                return null != baseTagged && baseTagged.IsConstructed();
-            }
-            case ParsedImplicit:
-                return obj is Asn1Sequence;
-            default:
-                return true;
-            }
-        }
-
-        /**
          * return whatever was following the tag.
          * <p>
          * Note: tagged objects are generally context dependent if you're
@@ -420,49 +362,25 @@ namespace Org.BouncyCastle.Asn1
         {
             bool maybeExplicit = (contentsElements.Count == 1);
 
-            Asn1TaggedObject taggedObject = maybeExplicit
+            return maybeExplicit
                 ? new DLTaggedObject(ParsedExplicit, tagClass, tagNo, contentsElements[0])
                 : new DLTaggedObject(ParsedImplicit, tagClass, tagNo, DLSequence.FromVector(contentsElements));
-
-            switch (tagClass)
-            {
-            case Asn1Tags.Application:
-                return new DLApplicationSpecific(taggedObject);
-            default:
-                return taggedObject;
-            }
         }
 
         internal static Asn1Object CreateConstructedIL(int tagClass, int tagNo, Asn1EncodableVector contentsElements)
         {
             bool maybeExplicit = (contentsElements.Count == 1);
 
-            Asn1TaggedObject taggedObject = maybeExplicit
+            return maybeExplicit
                 ? new BerTaggedObject(ParsedExplicit, tagClass, tagNo, contentsElements[0])
                 : new BerTaggedObject(ParsedImplicit, tagClass, tagNo, BerSequence.FromVector(contentsElements));
-
-            switch (tagClass)
-            {
-            case Asn1Tags.Application:
-                return new BerApplicationSpecific(taggedObject);
-            default:
-                return taggedObject;
-            }
         }
 
         internal static Asn1Object CreatePrimitive(int tagClass, int tagNo, byte[] contentsOctets)
         {
             // Note: !CONSTRUCTED => IMPLICIT
-            Asn1TaggedObject taggedObject = new DLTaggedObject(ParsedImplicit, tagClass, tagNo,
+            return new DLTaggedObject(ParsedImplicit, tagClass, tagNo,
                 new DerOctetString(contentsOctets));
-
-            switch (tagClass)
-            {
-            case Asn1Tags.Application:
-                return new DLApplicationSpecific(taggedObject);
-            default:
-                return taggedObject;
-            }
         }
 
         private static Asn1TaggedObject CheckedCast(Asn1Object asn1Object)
diff --git a/crypto/src/asn1/BERTaggedObjectParser.cs b/crypto/src/asn1/BERTaggedObjectParser.cs
index 8fee8977f..522e0d22b 100644
--- a/crypto/src/asn1/BERTaggedObjectParser.cs
+++ b/crypto/src/asn1/BERTaggedObjectParser.cs
@@ -71,10 +71,6 @@ namespace Org.BouncyCastle.Asn1
 
         public virtual Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo)
         {
-            // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecificParser types removed.
-            if (Asn1Tags.Application == baseTagClass)
-                return new BerApplicationSpecificParser(baseTagNo, m_parser);
-
             return new BerTaggedObjectParser(baseTagClass, baseTagNo, m_parser);
         }
 
diff --git a/crypto/src/asn1/BerApplicationSpecific.cs b/crypto/src/asn1/BerApplicationSpecific.cs
deleted file mode 100644
index 2a874984f..000000000
--- a/crypto/src/asn1/BerApplicationSpecific.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Asn1
-{
-	public class BerApplicationSpecific
-		: DerApplicationSpecific
-	{
-        /**
-         * Create an application specific object with an explicit tag
-         *
-         * @param tagNo the tag number for this object.
-         * @param baseEncodable the object to be contained.
-         */
-        public BerApplicationSpecific(int tagNo, Asn1Encodable baseEncodable)
-            : this(true, tagNo, baseEncodable)
-        {
-        }
-
-        /**
-         * Create an application specific object with the tagging style given by the value of explicit.
-         *
-         * @param explicit true if the object is explicitly tagged.
-         * @param tagNo the tag number for this object.
-         * @param baseEncodable the object to be contained.
-         */
-        public BerApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable)
-            : base(new BerTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable))
-        {
-        }
-
-        /**
-         * Create an application specific object which is marked as constructed
-         *
-         * @param tagNo the tag number for this object.
-         * @param contentsElements the objects making up the application specific object.
-         */
-        public BerApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements)
-            : base(new BerTaggedObject(false, Asn1Tags.Application, tagNo, BerSequence.FromVector(contentsElements)))
-        {
-        }
-
-        internal BerApplicationSpecific(Asn1TaggedObject taggedObject)
-            : base(taggedObject)
-        {
-        }
-	}
-}
diff --git a/crypto/src/asn1/BerApplicationSpecificParser.cs b/crypto/src/asn1/BerApplicationSpecificParser.cs
deleted file mode 100644
index 343dc5d68..000000000
--- a/crypto/src/asn1/BerApplicationSpecificParser.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Asn1
-{
-	internal class BerApplicationSpecificParser
-		: BerTaggedObjectParser, IAsn1ApplicationSpecificParser
-	{
-		internal BerApplicationSpecificParser(int tagNo, Asn1StreamParser parser)
-            : base(Asn1Tags.Application, tagNo, parser)
-		{
-		}
-
-		public IAsn1Convertible ReadObject()
-		{
-            // NOTE: No way to say you're looking for an implicitly-tagged object via IAsn1ApplicationSpecificParser
-            return ParseExplicitBaseObject();
-        }
-	}
-}
diff --git a/crypto/src/asn1/DLApplicationSpecific.cs b/crypto/src/asn1/DLApplicationSpecific.cs
deleted file mode 100644
index 8fffcf65b..000000000
--- a/crypto/src/asn1/DLApplicationSpecific.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Asn1
-{
-    internal class DLApplicationSpecific
-        : DerApplicationSpecific
-    {
-        internal DLApplicationSpecific(int tagNo, Asn1Encodable baseEncodable)
-            : this(true, tagNo, baseEncodable)
-        {
-        }
-
-        internal DLApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable)
-            : base(new DLTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable))
-        {
-        }
-
-        internal DLApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements)
-            : base(new DLTaggedObject(false, Asn1Tags.Application, tagNo, DLSequence.FromVector(contentsElements)))
-        {
-        }
-
-        internal DLApplicationSpecific(Asn1TaggedObject taggedObject)
-            : base(taggedObject)
-        {
-        }
-    }
-}
diff --git a/crypto/src/asn1/DLTaggedObjectParser.cs b/crypto/src/asn1/DLTaggedObjectParser.cs
index 307a6342a..3a89a69cd 100644
--- a/crypto/src/asn1/DLTaggedObjectParser.cs
+++ b/crypto/src/asn1/DLTaggedObjectParser.cs
@@ -55,13 +55,6 @@ namespace Org.BouncyCastle.Asn1
 
         public override Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo)
         {
-            // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecificParser types removed.
-            if (Asn1Tags.Application == baseTagClass)
-            {
-                // This cast is ensuring the current user-expected return type.
-                return (DLApplicationSpecific)m_parser.LoadTaggedDL(baseTagClass, baseTagNo, m_constructed);
-            }
-
             return new DLTaggedObjectParser(baseTagClass, baseTagNo, m_constructed, m_parser);
         }
 
diff --git a/crypto/src/asn1/DerApplicationSpecific.cs b/crypto/src/asn1/DerApplicationSpecific.cs
deleted file mode 100644
index d474034ed..000000000
--- a/crypto/src/asn1/DerApplicationSpecific.cs
+++ /dev/null
@@ -1,235 +0,0 @@
-using System;
-using System.IO;
-
-using Org.BouncyCastle.Utilities;
-
-namespace Org.BouncyCastle.Asn1
-{
-    /**
-     * Base class for an application specific object
-     */
-    public class DerApplicationSpecific
-        : Asn1Object, IAsn1ApplicationSpecificParser
-    {
-        public static DerApplicationSpecific GetInstance(object obj)
-        {
-            if (obj == null || obj is DerApplicationSpecific)
-            {
-                return (DerApplicationSpecific)obj;
-            }
-            else if (obj is byte[])
-            {
-                try
-                {
-                    return GetInstance(FromByteArray((byte[])obj));
-                }
-                catch (IOException e)
-                {
-                    throw new ArgumentException("failed to construct application-specific from byte[]: " + e.Message);
-                }
-            }
-
-            throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj");
-        }
-
-        internal readonly Asn1TaggedObject m_taggedObject;
-
-        /**
-         * Create an application specific object from the passed in data. This will assume
-         * the data does not represent a constructed object.
-         *
-         * @param tagNo the tag number for this object.
-         * @param contentsOctets the encoding of the object's body.
-         */
-        public DerApplicationSpecific(int tagNo, byte[] contentsOctets)
-            : this(new DerTaggedObject(false, Asn1Tags.Application, tagNo, new DerOctetString(contentsOctets)))
-        {
-        }
-
-        /**
-         * Create an application specific object with a tagging of explicit/constructed.
-         *
-         * @param tag the tag number for this object.
-         * @param object the object to be contained.
-         */
-        public DerApplicationSpecific(int tag, Asn1Encodable baseEncodable)
-            : this(true, tag, baseEncodable)
-        {
-        }
-
-        /**
-         * Create an application specific object with the tagging style given by the value of explicit.
-         *
-         * @param explicit true if the object is explicitly tagged.
-         * @param tagNo the tag number for this object.
-         * @param baseEncodable the object to be contained.
-         */
-        public DerApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable)
-            : this(new DerTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable))
-        {
-        }
-
-        /**
-         * Create an application specific object which is marked as constructed
-         *
-         * @param tagNo the tag number for this object.
-         * @param contentsElements   the objects making up the application specific object.
-         */
-        public DerApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements)
-            : this(new DerTaggedObject(false, Asn1Tags.Application, tagNo, DerSequence.FromVector(contentsElements)))
-        {
-        }
-
-        internal DerApplicationSpecific(Asn1TaggedObject taggedObject)
-            //: base(taggedObject.explicitness, CheckTagClass(taggedObject.tagClass), taggedObject.tagNo,
-            //      taggedObject.obj)
-        {
-            CheckTagClass(taggedObject.TagClass);
-
-            this.m_taggedObject = taggedObject;
-        }
-
-        public int ApplicationTag
-        {
-            get { return m_taggedObject.TagNo; }
-        }
-
-        [Obsolete("Will be removed")]
-        public byte[] GetContents()
-        {
-            return m_taggedObject.GetContents();
-        }
-
-        public Asn1Object GetEnclosedObject()
-        {
-            return m_taggedObject.GetBaseObject().ToAsn1Object();
-        }
-
-        [Obsolete("Use GetEnclosedObject instead")]
-        public Asn1Object GetObject()
-        {
-            return GetEnclosedObject();
-        }
-
-        public Asn1Object GetObject(int tagNo)
-        {
-            return m_taggedObject.GetBaseUniversal(false, tagNo);
-        }
-
-        public IAsn1Convertible GetObjectParser(int tag, bool isExplicit)
-        {
-            throw new Asn1Exception("this method only valid for CONTEXT_SPECIFIC tags");
-        }
-
-        public IAsn1Convertible ParseBaseUniversal(bool declaredExplicit, int baseTagNo)
-        {
-            return m_taggedObject.ParseBaseUniversal(declaredExplicit, baseTagNo);
-        }
-
-        public IAsn1Convertible ParseExplicitBaseObject()
-        {
-            return TaggedObject.ParseExplicitBaseObject();
-        }
-
-        public Asn1TaggedObjectParser ParseExplicitBaseTagged()
-        {
-            return m_taggedObject.ParseExplicitBaseTagged();
-        }
-
-        public Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo)
-        {
-            return m_taggedObject.ParseImplicitBaseTagged(baseTagClass, baseTagNo);
-        }
-
-        public bool HasApplicationTag(int tagNo)
-        {
-            return m_taggedObject.HasTag(Asn1Tags.Application, tagNo);
-        }
-
-        public bool HasContextTag(int tagNo)
-        {
-            return false;
-        }
-
-        public bool HasTag(int tagClass, int tagNo)
-        {
-            return m_taggedObject.HasTag(tagClass, tagNo);
-        }
-
-        [Obsolete("Will be removed")]
-        public bool IsConstructed()
-        {
-            return m_taggedObject.IsConstructed();
-        }
-
-        public IAsn1Convertible ReadObject()
-        {
-            // NOTE: No way to say you're looking for an implicitly-tagged object via IAsn1ApplicationSpecificParser
-            return ParseExplicitBaseObject();
-        }
-
-        public int TagClass
-        {
-            get { return m_taggedObject.TagClass; }
-        }
-
-        public int TagNo
-        {
-            get { return m_taggedObject.TagNo; }
-        }
-
-        /**
-         * DerApplicationSpecific uses an internal Asn1TaggedObject for the
-         * implementation, and will soon be deprecated in favour of using
-         * Asn1TaggedObject with a tag class of {@link Asn1Tags#Application}. This method
-         * lets you get the internal Asn1TaggedObject so that client code can begin the
-         * migration.
-         */
-        public Asn1TaggedObject TaggedObject
-        {
-            get { return m_taggedObject; }
-        }
-
-        protected override bool Asn1Equals(Asn1Object asn1Object)
-        {
-            Asn1TaggedObject that;
-            if (asn1Object is DerApplicationSpecific)
-            {
-                that = ((DerApplicationSpecific)asn1Object).m_taggedObject;
-            }
-            else if (asn1Object is Asn1TaggedObject)
-            {
-                that = (Asn1TaggedObject)asn1Object;
-            }
-            else
-            {
-                return false;
-            }
-
-            return m_taggedObject.Equals(that);
-        }
-
-        protected override int Asn1GetHashCode()
-        {
-            return m_taggedObject.CallAsn1GetHashCode();
-        }
-
-        internal override IAsn1Encoding GetEncoding(int encoding)
-        {
-            return m_taggedObject.GetEncoding(encoding);
-        }
-
-        internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
-        {
-            return m_taggedObject.GetEncodingImplicit(encoding, tagClass, tagNo);
-        }
-
-        private static int CheckTagClass(int tagClass)
-        {
-            if (Asn1Tags.Application != tagClass)
-                throw new ArgumentException();
-
-            return tagClass;
-        }
-    }
-}
diff --git a/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs b/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs
deleted file mode 100644
index f8dec2791..000000000
--- a/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.Asn1
-{
-    [Obsolete("Test for Asn1TaggedObjectParser with TagClass of Asn1Tags.Application instead")]
-	public interface IAsn1ApplicationSpecificParser
-    	: Asn1TaggedObjectParser
-    {
-    	IAsn1Convertible ReadObject();
-	}
-}
diff --git a/crypto/src/asn1/util/Asn1Dump.cs b/crypto/src/asn1/util/Asn1Dump.cs
index 0ba5c394f..406511a72 100644
--- a/crypto/src/asn1/util/Asn1Dump.cs
+++ b/crypto/src/asn1/util/Asn1Dump.cs
@@ -81,10 +81,6 @@ namespace Org.BouncyCastle.Asn1.Utilities
                     AsString(elementsIndent, verbose, set[i].ToAsn1Object(), buf);
                 }
             }
-            else if (obj is DerApplicationSpecific)
-            {
-                AsString(indent, verbose, ((DerApplicationSpecific)obj).TaggedObject, buf);
-            }
             else if (obj is Asn1TaggedObject)
             {
                 buf.Append(indent);