diff options
Diffstat (limited to 'crypto/src/asn1/DLSequence.cs')
-rw-r--r-- | crypto/src/asn1/DLSequence.cs | 66 |
1 files changed, 9 insertions, 57 deletions
diff --git a/crypto/src/asn1/DLSequence.cs b/crypto/src/asn1/DLSequence.cs index 0fede574a..8cf8d5bcb 100644 --- a/crypto/src/asn1/DLSequence.cs +++ b/crypto/src/asn1/DLSequence.cs @@ -12,8 +12,6 @@ namespace Org.BouncyCastle.Asn1 return elementVector.Count < 1 ? Empty : new DLSequence(elementVector); } - private int m_contentsLengthDL = -1; - /** * create an empty sequence */ @@ -48,73 +46,27 @@ namespace Org.BouncyCastle.Asn1 { } - internal override int EncodedLength(int encoding, bool withID) + internal override IAsn1Encoding GetEncoding(int encoding) { if (Asn1OutputStream.EncodingDer == encoding) - return base.EncodedLength(encoding, withID); + return base.GetEncoding(encoding); - return Asn1OutputStream.GetLengthOfEncodingDL(withID, GetContentsLengthDL()); + return new ConstructedDLEncoding(Asn1Tags.Universal, Asn1Tags.Sequence, + Asn1OutputStream.GetContentsEncodings(encoding, elements)); } - internal override void Encode(Asn1OutputStream asn1Out, bool withID) + internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo) { - if (Asn1OutputStream.EncodingDer == asn1Out.Encoding) - { - base.Encode(asn1Out, withID); - return; - } - - // TODO[asn1] Use DL encoding when supported - //asn1Out = asn1Out.GetDLSubStream(); - - asn1Out.WriteIdentifier(withID, Asn1Tags.Constructed | Asn1Tags.Sequence); - - int count = elements.Length; - if (m_contentsLengthDL >= 0 || count > 16) - { - asn1Out.WriteDL(GetContentsLengthDL()); - - for (int i = 0; i < count; ++i) - { - Asn1Object asn1Object = elements[i].ToAsn1Object(); - asn1Object.Encode(asn1Out, true); - } - } - else - { - int contentsLength = 0; - - Asn1Object[] asn1Objects = new Asn1Object[count]; - for (int i = 0; i < count; ++i) - { - Asn1Object asn1Object = elements[i].ToAsn1Object(); - asn1Objects[i] = asn1Object; - contentsLength += asn1Object.EncodedLength(asn1Out.Encoding, true); - } - - this.m_contentsLengthDL = contentsLength; - asn1Out.WriteDL(contentsLength); + if (Asn1OutputStream.EncodingDer == encoding) + return base.GetEncodingImplicit(encoding, tagClass, tagNo); - for (int i = 0; i < count; ++i) - { - asn1Objects[i].Encode(asn1Out, true); - } - } + return new ConstructedDLEncoding(tagClass, tagNo, + Asn1OutputStream.GetContentsEncodings(encoding, elements)); } internal override Asn1Set ToAsn1Set() { return new DLSet(false, elements); } - - private int GetContentsLengthDL() - { - if (m_contentsLengthDL < 0) - { - // TODO[asn1] Use DL encoding when supported - m_contentsLengthDL = CalculateContentsLength(Asn1OutputStream.EncodingBer); - } - return m_contentsLengthDL; - } } } |