summary refs log tree commit diff
path: root/crypto/src/asn1/BERTaggedObjectParser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/BERTaggedObjectParser.cs')
-rw-r--r--crypto/src/asn1/BERTaggedObjectParser.cs49
1 files changed, 41 insertions, 8 deletions
diff --git a/crypto/src/asn1/BERTaggedObjectParser.cs b/crypto/src/asn1/BERTaggedObjectParser.cs
index 55ad36d46..a54e3ce38 100644
--- a/crypto/src/asn1/BERTaggedObjectParser.cs
+++ b/crypto/src/asn1/BERTaggedObjectParser.cs
@@ -34,21 +34,54 @@ namespace Org.BouncyCastle.Asn1
 			get { return m_tagNo; }
 		}
 
-		public IAsn1Convertible GetObjectParser(int baseTagNo, bool declaredExplicit)
+        public bool HasContextTag(int tagNo)
+        {
+            return m_tagClass == Asn1Tags.ContextSpecific && m_tagNo == tagNo;
+        }
+
+        public bool HasTag(int tagClass, int tagNo)
+        {
+            return m_tagClass == tagClass && m_tagNo == tagNo;
+        }
+
+        [Obsolete("Use 'Parse...' methods instead, after checking this parser's TagClass and TagNo")]
+        public IAsn1Convertible GetObjectParser(int baseTagNo, bool declaredExplicit)
 		{
             if (Asn1Tags.ContextSpecific != TagClass)
                 throw new Asn1Exception("this method only valid for CONTEXT_SPECIFIC tags");
 
-            if (!declaredExplicit)
-                return m_parser.ReadImplicit(m_constructed, baseTagNo);
+            return ParseBaseUniversal(declaredExplicit, baseTagNo);
+		}
 
-			if (!m_constructed)
-				throw new IOException("Explicit tags must be constructed (see X.690 8.14.2)");
+        public IAsn1Convertible ParseBaseUniversal(bool declaredExplicit, int baseTagNo)
+        {
+            if (declaredExplicit)
+            {
+                if (!m_constructed)
+                    throw new IOException("Explicit tags must be constructed (see X.690 8.14.2)");
 
-	        return m_parser.ReadObject();
-		}
+                // TODO[asn1] Alternate parser method specific to this case
+                return m_parser.ReadObject();
+            }
+
+            return m_parser.ReadImplicit(m_constructed, baseTagNo);
+        }
+
+        public Asn1TaggedObjectParser ParseExplicitBaseTagged()
+        {
+            if (!m_constructed)
+                throw new IOException("Explicit tags must be constructed (see X.690 8.14.2)");
+
+            // TODO[asn1] Alternate parser method specific to this case
+            return (Asn1TaggedObjectParser)m_parser.ReadObject();
+        }
+
+        public Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo)
+        {
+            return new BerTaggedObjectParser(baseTagClass, baseTagNo, m_constructed, m_parser);
+        }
 
-		public Asn1Object ToAsn1Object()
+        public Asn1Object ToAsn1Object()
 		{
 			try
 			{