diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-14 18:46:47 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-14 18:46:47 +0700 |
commit | c3a6083bace63a12515b08b30e4ffa42fc74a0a0 (patch) | |
tree | 694e96380bbf30b597462be7dcefe0dc4ceb7406 /crypto/src/asn1/Asn1OutputStream.cs | |
parent | Add WriteElements method (diff) | |
download | BouncyCastle.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.cs | 44 |
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]); } } } |