From 61605407b72d584c94daeafe4ea4c2b1cad3914e Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 14 Oct 2021 20:33:18 +0700 Subject: Add withID to Encode method - refactor Asn1OutputStream utility methods --- crypto/src/asn1/DerTaggedObject.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'crypto/src/asn1/DerTaggedObject.cs') diff --git a/crypto/src/asn1/DerTaggedObject.cs b/crypto/src/asn1/DerTaggedObject.cs index 40776ace3..7f1541c15 100644 --- a/crypto/src/asn1/DerTaggedObject.cs +++ b/crypto/src/asn1/DerTaggedObject.cs @@ -42,7 +42,7 @@ namespace Org.BouncyCastle.Asn1 { } - internal override void Encode(Asn1OutputStream asn1Out) + internal override void Encode(Asn1OutputStream asn1Out, bool withID) { if (!IsEmpty()) { @@ -50,21 +50,26 @@ namespace Org.BouncyCastle.Asn1 if (explicitly) { - asn1Out.WriteEncoded(Asn1Tags.Constructed | Asn1Tags.Tagged, tagNo, bytes); + asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | Asn1Tags.Tagged, tagNo, bytes); } else { // // need to mark constructed types... (preserve Constructed tag) // - int flags = (bytes[0] & Asn1Tags.Constructed) | Asn1Tags.Tagged; - asn1Out.WriteIdentifier(true, flags, tagNo); - asn1Out.Write(bytes, 1, bytes.Length - 1); + if (withID) + { + int flags = (bytes[0] & Asn1Tags.Constructed) | Asn1Tags.Tagged; + asn1Out.WriteIdentifier(true, flags, tagNo); + } + + asn1Out.Write(bytes, 1, bytes.Length - 1); } } else { - asn1Out.WriteEncoded(Asn1Tags.Constructed | Asn1Tags.Tagged, tagNo, new byte[0]); + asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | Asn1Tags.Tagged, tagNo, + Asn1OctetString.EmptyOctets); } } } -- cgit 1.4.1