summary refs log tree commit diff
path: root/crypto/src/asn1/Asn1OutputStream.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 18:46:47 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 18:46:47 +0700
commitc3a6083bace63a12515b08b30e4ffa42fc74a0a0 (patch)
tree694e96380bbf30b597462be7dcefe0dc4ceb7406 /crypto/src/asn1/Asn1OutputStream.cs
parentAdd WriteElements method (diff)
downloadBouncyCastle.NET-ed25519-c3a6083bace63a12515b08b30e4ffa42fc74a0a0.tar.xz
More ASN.1 updates from bc-java
Diffstat (limited to 'crypto/src/asn1/Asn1OutputStream.cs')
-rw-r--r--crypto/src/asn1/Asn1OutputStream.cs44
1 files changed, 28 insertions, 16 deletions
diff --git a/crypto/src/asn1/Asn1OutputStream.cs b/crypto/src/asn1/Asn1OutputStream.cs
index 5746d1c59..e6eec563e 100644
--- a/crypto/src/asn1/Asn1OutputStream.cs
+++ b/crypto/src/asn1/Asn1OutputStream.cs
@@ -29,6 +29,29 @@ namespace Org.BouncyCastle.Asn1
         {
         }
 
+        public override void WriteObject(Asn1Encodable encodable)
+        {
+            if (null == encodable)
+                throw new IOException("null object detected");
+
+            WritePrimitive(encodable.ToAsn1Object());
+            FlushInternal();
+        }
+
+        public override void WriteObject(Asn1Object primitive)
+        {
+            if (null == primitive)
+                throw new IOException("null object detected");
+
+            WritePrimitive(primitive);
+            FlushInternal();
+        }
+
+        internal void FlushInternal()
+        {
+            // Placeholder to support future internal buffering
+        }
+
         internal override bool IsBer
         {
             get { return true; }
@@ -42,27 +65,16 @@ namespace Org.BouncyCastle.Asn1
             }
         }
 
-        public override void WriteObject(Asn1Encodable obj)
+        internal virtual void WritePrimitive(Asn1Object primitive)
         {
-            if (obj == null)
-            {
-                WriteNull();
-            }
-            else
-            {
-                obj.ToAsn1Object().Encode(this);
-            }
+            primitive.Encode(this);
         }
 
-        public override void WriteObject(Asn1Object obj)
+        internal virtual void WritePrimitives(Asn1Object[] primitives)
         {
-            if (obj == null)
-            {
-                WriteNull();
-            }
-            else
+            for (int i = 0, count = primitives.Length; i < count; ++i)
             {
-                obj.Encode(this);
+                WritePrimitive(primitives[i]);
             }
         }
     }