From 46230a012af2824a5e742db8e6dc5b23c720d696 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 11 Nov 2021 14:06:03 +0700 Subject: ASN.1: Update encoding in line with bc-java --- crypto/src/asn1/LazyDLSet.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'crypto/src/asn1/LazyDLSet.cs') diff --git a/crypto/src/asn1/LazyDLSet.cs b/crypto/src/asn1/LazyDLSet.cs index bdee0bc22..a426bb4cb 100644 --- a/crypto/src/asn1/LazyDLSet.cs +++ b/crypto/src/asn1/LazyDLSet.cs @@ -63,21 +63,25 @@ namespace Org.BouncyCastle.Asn1 return base.ToString(); } - internal override int EncodedLength(bool withID) + internal override int EncodedLength(int encoding, bool withID) { - // TODO This depends on knowing it's BER - byte[] encoded = GetContents(); - if (encoded != null) + if (Asn1OutputStream.EncodingBer == encoding) { - return Asn1OutputStream.GetLengthOfEncodingDL(withID, encoded.Length); + byte[] encoded = GetContents(); + if (null != encoded) + return Asn1OutputStream.GetLengthOfEncodingDL(withID, encoded.Length); + } + else + { + Force(); } - return base.EncodedLength(withID); + return base.EncodedLength(encoding, withID); } internal override void Encode(Asn1OutputStream asn1Out, bool withID) { - if (asn1Out.IsBer) + if (Asn1OutputStream.EncodingBer == asn1Out.Encoding) { byte[] encoded = GetContents(); if (encoded != null) -- cgit 1.4.1