summary refs log tree commit diff
path: root/crypto/src/asn1/ConstructedDLEncoding.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-16 22:37:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-16 22:37:52 +0700
commitbe15049124860ccb7335b92215e8b8dfa1821bf9 (patch)
tree7a86ed2110021307465a617076d601ca812c69ed /crypto/src/asn1/ConstructedDLEncoding.cs
parentMake cast more specific (diff)
downloadBouncyCastle.NET-ed25519-be15049124860ccb7335b92215e8b8dfa1821bf9.tar.xz
ASN.1: Staged encoding
Diffstat (limited to 'crypto/src/asn1/ConstructedDLEncoding.cs')
-rw-r--r--crypto/src/asn1/ConstructedDLEncoding.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/crypto/src/asn1/ConstructedDLEncoding.cs b/crypto/src/asn1/ConstructedDLEncoding.cs
new file mode 100644
index 000000000..f7d8bec5d
--- /dev/null
+++ b/crypto/src/asn1/ConstructedDLEncoding.cs
@@ -0,0 +1,35 @@
+using System;
+
+namespace Org.BouncyCastle.Asn1
+{
+    internal class ConstructedDLEncoding
+        : IAsn1Encoding
+    {
+        private readonly int m_tagClass;
+        private readonly int m_tagNo;
+        private readonly IAsn1Encoding[] m_contentsElements;
+        private readonly int m_contentsLength;
+
+        internal ConstructedDLEncoding(int tagClass, int tagNo, IAsn1Encoding[] contentsElements)
+        {
+            m_tagClass = tagClass;
+            m_tagNo = tagNo;
+            m_contentsElements = contentsElements;
+            m_contentsLength = Asn1OutputStream.GetLengthOfContents(contentsElements);
+        }
+
+        void IAsn1Encoding.Encode(Asn1OutputStream asn1Out)
+        {
+            asn1Out.WriteIdentifier(Asn1Tags.Constructed | m_tagClass, m_tagNo);
+            asn1Out.WriteDL(m_contentsLength);
+            asn1Out.EncodeContents(m_contentsElements);
+        }
+
+        int IAsn1Encoding.GetLength()
+        {
+            return Asn1OutputStream.GetLengthOfIdentifier(m_tagNo)
+                +  Asn1OutputStream.GetLengthOfDL(m_contentsLength)
+                +  m_contentsLength;
+        }
+    }
+}