summary refs log tree commit diff
path: root/crypto/src/asn1/BerTaggedObject.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/BerTaggedObject.cs')
-rw-r--r--crypto/src/asn1/BerTaggedObject.cs63
1 files changed, 13 insertions, 50 deletions
diff --git a/crypto/src/asn1/BerTaggedObject.cs b/crypto/src/asn1/BerTaggedObject.cs
index a97a8e143..e613d98d9 100644
--- a/crypto/src/asn1/BerTaggedObject.cs
+++ b/crypto/src/asn1/BerTaggedObject.cs
@@ -59,69 +59,32 @@ namespace Org.BouncyCastle.Asn1
             get { return Ber; }
         }
 
-        internal override bool EncodeConstructed(int encoding)
+        internal override IAsn1Encoding GetEncoding(int encoding)
         {
             if (Asn1OutputStream.EncodingBer != encoding)
-                return base.EncodeConstructed(encoding);
+                return base.GetEncoding(encoding);
 
-            return IsExplicit() || GetBaseObject().ToAsn1Object().EncodeConstructed(encoding);
+            Asn1Object baseObject = GetBaseObject().ToAsn1Object();
+
+            if (!IsExplicit())
+                return baseObject.GetEncodingImplicit(encoding, TagClass, TagNo);
+
+            return new ConstructedILEncoding(TagClass, TagNo, new IAsn1Encoding[]{ baseObject.GetEncoding(encoding) });
         }
 
-        internal override int EncodedLength(int encoding, bool withID)
+        internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
         {
             if (Asn1OutputStream.EncodingBer != encoding)
-                return base.EncodedLength(encoding, withID);
+                return base.GetEncodingImplicit(encoding, tagClass, tagNo);
 
             Asn1Object baseObject = GetBaseObject().ToAsn1Object();
-            bool withBaseID = IsExplicit();
-
-            int length = baseObject.EncodedLength(encoding, withBaseID);
-
-            if (withBaseID)
-            {
-                length += 3;
-            }
 
-            length += withID ? Asn1OutputStream.GetLengthOfIdentifier(TagNo) : 0;
+            if (!IsExplicit())
+                return baseObject.GetEncodingImplicit(encoding, tagClass, tagNo);
 
-            return length;
+            return new ConstructedILEncoding(tagClass, tagNo, new IAsn1Encoding[]{ baseObject.GetEncoding(encoding) });
         }
 
-        internal override void Encode(Asn1OutputStream asn1Out, bool withID)
-		{
-            if (Asn1OutputStream.EncodingBer != asn1Out.Encoding)
-            {
-                base.Encode(asn1Out, withID);
-                return;
-            }
-
-            Asn1Object baseObject = GetBaseObject().ToAsn1Object();
-            bool withBaseID = IsExplicit();
-
-            if (withID)
-            {
-                int flags = TagClass;
-                if (withBaseID || baseObject.EncodeConstructed(asn1Out.Encoding))
-                {
-                    flags |= Asn1Tags.Constructed;
-                }
-
-                asn1Out.WriteIdentifier(true, flags, TagNo);
-            }
-
-            if (withBaseID)
-            {
-                asn1Out.WriteByte(0x80);
-                baseObject.Encode(asn1Out, true);
-                asn1Out.WriteByte(0x00);
-                asn1Out.WriteByte(0x00);
-            }
-            else
-            {
-                baseObject.Encode(asn1Out, false);
-            }
-		}
-
         internal override Asn1Sequence RebuildConstructed(Asn1Object asn1Object)
         {
             return new BerSequence(asn1Object);