summary refs log tree commit diff
path: root/crypto/src/asn1/ASN1StreamParser.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-11 21:13:22 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-11 21:13:22 +0700
commit39f33f785250b544610c429fb9d4e50c521cd493 (patch)
treec7a55871f7c0038dcbc99e582826051cb3a180d0 /crypto/src/asn1/ASN1StreamParser.cs
parentTrim stack trace (diff)
downloadBouncyCastle.NET-ed25519-39f33f785250b544610c429fb9d4e50c521cd493.tar.xz
Refactor tagged object parsing
Diffstat (limited to 'crypto/src/asn1/ASN1StreamParser.cs')
-rw-r--r--crypto/src/asn1/ASN1StreamParser.cs30
1 files changed, 5 insertions, 25 deletions
diff --git a/crypto/src/asn1/ASN1StreamParser.cs b/crypto/src/asn1/ASN1StreamParser.cs
index 5c6854e1d..f896227f8 100644
--- a/crypto/src/asn1/ASN1StreamParser.cs
+++ b/crypto/src/asn1/ASN1StreamParser.cs
@@ -98,33 +98,13 @@ namespace Org.BouncyCastle.Asn1
             if (!constructed)
 			{
                 // Note: !CONSTRUCTED => IMPLICIT
-                DefiniteLengthInputStream defIn = (DefiniteLengthInputStream)_in;
-                byte[] contentsOctets = defIn.ToArray();
-
-                if (Asn1Tags.Application == tagClass)
-                    return new DerApplicationSpecific(false, tagNo, contentsOctets);
-
-                return new DLTaggedObject(false, tagNo, new DerOctetString(contentsOctets));
+                byte[] contentsOctets = ((DefiniteLengthInputStream)_in).ToArray();
+                return Asn1TaggedObject.CreatePrimitive(tagClass, tagNo, contentsOctets);
 			}
 
-			Asn1EncodableVector contentsElements = ReadVector();
-
-			if (_in is IndefiniteLengthInputStream)
-			{
-                if (Asn1Tags.Application == tagClass)
-                    return new BerApplicationSpecific(tagNo, contentsElements);
-
-                return contentsElements.Count == 1
-					?   new BerTaggedObject(true, tagNo, contentsElements[0])
-					:   new BerTaggedObject(false, tagNo, BerSequence.FromVector(contentsElements));
-			}
-
-            if (Asn1Tags.Application == tagClass)
-                return new DerApplicationSpecific(tagNo, contentsElements);
-
-            return contentsElements.Count == 1
-				?   new DLTaggedObject(true, tagNo, contentsElements[0])
-				:   new DLTaggedObject(false, tagNo, DLSequence.FromVector(contentsElements));
+            bool isIL = (_in is IndefiniteLengthInputStream);
+            Asn1EncodableVector contentsElements = ReadVector();
+            return Asn1TaggedObject.CreateConstructed(tagClass, tagNo, isIL, contentsElements);
 		}
 
 		public virtual IAsn1Convertible ReadObject()