diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-01 17:22:34 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-08-01 17:22:34 +0700 |
commit | 4ecb2d166e5ad4edf544bc8bc60d03ef9f759e70 (patch) | |
tree | c67b646d569d11e0ba74fa9a5139d9e56e5d6cf8 /crypto/src/asn1 | |
parent | Cast to remove warning (diff) | |
download | BouncyCastle.NET-ed25519-4ecb2d166e5ad4edf544bc8bc60d03ef9f759e70.tar.xz |
Inline BuildEncodableVector to shrink recursive call stacks
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/Asn1InputStream.cs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs index a94ae5235..0c7461c98 100644 --- a/crypto/src/asn1/Asn1InputStream.cs +++ b/crypto/src/asn1/Asn1InputStream.cs @@ -98,13 +98,13 @@ namespace Org.BouncyCastle.Asn1 // // yes, people actually do this... // - return new BerOctetString(BuildDerEncodableVector(defIn)); + return new BerOctetString(ReadVector(defIn)); case Asn1Tags.Sequence: return CreateDerSequence(defIn); case Asn1Tags.Set: return CreateDerSet(defIn); case Asn1Tags.External: - return new DerExternal(BuildDerEncodableVector(defIn)); + return new DerExternal(ReadVector(defIn)); default: throw new IOException("unknown tag " + tagNo + " encountered"); } @@ -113,12 +113,15 @@ namespace Org.BouncyCastle.Asn1 return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers); } - internal Asn1EncodableVector BuildEncodableVector() + internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn) { - Asn1EncodableVector v = new Asn1EncodableVector(); + if (dIn.Remaining < 1) + return new Asn1EncodableVector(0); + Asn1InputStream subStream = new Asn1InputStream(dIn); + Asn1EncodableVector v = new Asn1EncodableVector(); Asn1Object o; - while ((o = ReadObject()) != null) + while ((o = subStream.ReadObject()) != null) { v.Add(o); } @@ -126,22 +129,16 @@ namespace Org.BouncyCastle.Asn1 return v; } - internal virtual Asn1EncodableVector BuildDerEncodableVector( - DefiniteLengthInputStream dIn) - { - return new Asn1InputStream(dIn).BuildEncodableVector(); - } - internal virtual DerSequence CreateDerSequence( DefiniteLengthInputStream dIn) { - return DerSequence.FromVector(BuildDerEncodableVector(dIn)); + return DerSequence.FromVector(ReadVector(dIn)); } internal virtual DerSet CreateDerSet( DefiniteLengthInputStream dIn) { - return DerSet.FromVector(BuildDerEncodableVector(dIn), false); + return DerSet.FromVector(ReadVector(dIn), false); } public Asn1Object ReadObject() |