summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 17:03:04 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-10-14 17:03:04 +0700
commit2b93d0982010321dbbc51ecbef9c3adfb22e7860 (patch)
tree38fbf7ced481c78429877eebd7bd05e5ac458765 /crypto
parentNull check and reformatting (diff)
downloadBouncyCastle.NET-ed25519-2b93d0982010321dbbc51ecbef9c3adfb22e7860.tar.xz
Add WriteElements method
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/asn1/Asn1OutputStream.cs8
-rw-r--r--crypto/src/asn1/BerSequence.cs5
-rw-r--r--crypto/src/asn1/BerSet.cs5
-rw-r--r--crypto/src/asn1/DerSequence.cs7
-rw-r--r--crypto/src/asn1/DerSet.cs7
5 files changed, 12 insertions, 20 deletions
diff --git a/crypto/src/asn1/Asn1OutputStream.cs b/crypto/src/asn1/Asn1OutputStream.cs
index 240c7891b..5746d1c59 100644
--- a/crypto/src/asn1/Asn1OutputStream.cs
+++ b/crypto/src/asn1/Asn1OutputStream.cs
@@ -34,6 +34,14 @@ namespace Org.BouncyCastle.Asn1
             get { return true; }
         }
 
+        internal virtual void WriteElements(Asn1Encodable[] elements)
+        {
+            for (int i = 0, count = elements.Length; i < count; ++i)
+            {
+                elements[i].ToAsn1Object().Encode(this);
+            }
+        }
+
         public override void WriteObject(Asn1Encodable obj)
         {
             if (obj == null)
diff --git a/crypto/src/asn1/BerSequence.cs b/crypto/src/asn1/BerSequence.cs
index 1f09ecada..b8ef12dd0 100644
--- a/crypto/src/asn1/BerSequence.cs
+++ b/crypto/src/asn1/BerSequence.cs
@@ -46,10 +46,7 @@ namespace Org.BouncyCastle.Asn1
 				asn1Out.WriteByte(Asn1Tags.Sequence | Asn1Tags.Constructed);
 				asn1Out.WriteByte(0x80);
 
-				foreach (Asn1Encodable o in this)
-				{
-                    o.ToAsn1Object().Encode(asn1Out);
-				}
+                asn1Out.WriteElements(elements);
 
 				asn1Out.WriteByte(0x00);
 				asn1Out.WriteByte(0x00);
diff --git a/crypto/src/asn1/BerSet.cs b/crypto/src/asn1/BerSet.cs
index 95214fea9..a3868dfa6 100644
--- a/crypto/src/asn1/BerSet.cs
+++ b/crypto/src/asn1/BerSet.cs
@@ -51,10 +51,7 @@ namespace Org.BouncyCastle.Asn1
                 asn1Out.WriteByte(Asn1Tags.Set | Asn1Tags.Constructed);
                 asn1Out.WriteByte(0x80);
 
-                foreach (Asn1Encodable o in this)
-				{
-                    o.ToAsn1Object().Encode(asn1Out);
-                }
+                asn1Out.WriteElements(elements);
 
                 asn1Out.WriteByte(0x00);
                 asn1Out.WriteByte(0x00);
diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs
index 9b4504cfe..05b6f4533 100644
--- a/crypto/src/asn1/DerSequence.cs
+++ b/crypto/src/asn1/DerSequence.cs
@@ -64,12 +64,7 @@ namespace Org.BouncyCastle.Asn1
             // TODO Intermediate buffer could be avoided if we could calculate expected length
             MemoryStream bOut = new MemoryStream();
             Asn1OutputStream dOut = Asn1OutputStream.Create(bOut, Der);
-
-            foreach (Asn1Encodable obj in this)
-            {
-                obj.ToAsn1Object().Encode(dOut);
-            }
-
+            dOut.WriteElements(elements);
             dOut.Flush();
 
 #if PORTABLE
diff --git a/crypto/src/asn1/DerSet.cs b/crypto/src/asn1/DerSet.cs
index 0808434d7..62d8873b8 100644
--- a/crypto/src/asn1/DerSet.cs
+++ b/crypto/src/asn1/DerSet.cs
@@ -81,12 +81,7 @@ namespace Org.BouncyCastle.Asn1
             // TODO Intermediate buffer could be avoided if we could calculate expected length
             MemoryStream bOut = new MemoryStream();
             Asn1OutputStream dOut = Asn1OutputStream.Create(bOut, Asn1Encodable.Der);
-
-            foreach (Asn1Encodable obj in this)
-            {
-                obj.ToAsn1Object().Encode(dOut);
-            }
-
+            dOut.WriteElements(elements);
             dOut.Flush();
 
 #if PORTABLE