diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-10 00:38:54 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-10 00:38:54 +0700 |
commit | 212ec41dd10152391c5218c0a6c98af31ff02d6f (patch) | |
tree | 5ebbddb7d80684c586884939b990e274f51d4558 /crypto/src | |
parent | Add DLSequence, DLSet for internal use (diff) | |
download | BouncyCastle.NET-ed25519-212ec41dd10152391c5218c0a6c98af31ff02d6f.tar.xz |
Handle high tag numbers
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/asn1/DerTaggedObject.cs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/crypto/src/asn1/DerTaggedObject.cs b/crypto/src/asn1/DerTaggedObject.cs index 125d30ff2..b75e0879d 100644 --- a/crypto/src/asn1/DerTaggedObject.cs +++ b/crypto/src/asn1/DerTaggedObject.cs @@ -64,25 +64,33 @@ namespace Org.BouncyCastle.Asn1 } internal override void Encode(Asn1OutputStream asn1Out, bool withID) - { - byte[] bytes = obj.GetDerEncoded(); + { + byte[] bytes = obj.GetDerEncoded(); + + if (explicitly) + { + asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | TagClass, TagNo, bytes); + } + else + { + int tagHdr = bytes[0], tagLen = 1; + if ((tagHdr & 0x1F) == 0x1F) + { + while ((bytes[tagLen++] & 0x80) != 0) + { + } + } - if (explicitly) - { - asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | TagClass, TagNo, bytes); - } - else - { if (withID) { - // need to mark constructed types... (preserve Constructed tag) - int flags = (bytes[0] & Asn1Tags.Constructed) | TagClass; + int flags = (tagHdr & Asn1Tags.Constructed) | TagClass; + asn1Out.WriteIdentifier(true, flags, TagNo); } - asn1Out.Write(bytes, 1, bytes.Length - 1); - } - } + asn1Out.Write(bytes, tagLen, bytes.Length - tagLen); + } + } internal override Asn1Sequence RebuildConstructed(Asn1Object asn1Object) { |