diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-02-19 21:03:22 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-02-19 21:03:22 +0700 |
commit | ad0b6c99d34da50d5473a9c14837a9ce199d0200 (patch) | |
tree | fbe5e81540f15b7a3cca0401380d33bd9fbb9cc6 /crypto/src/asn1/ConstructedOctetStream.cs | |
parent | Case-insensitive check of boolean env. var. (diff) | |
download | BouncyCastle.NET-ed25519-ad0b6c99d34da50d5473a9c14837a9ce199d0200.tar.xz |
ASN.1 updates from bc-java
Diffstat (limited to 'crypto/src/asn1/ConstructedOctetStream.cs')
-rw-r--r-- | crypto/src/asn1/ConstructedOctetStream.cs | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/crypto/src/asn1/ConstructedOctetStream.cs b/crypto/src/asn1/ConstructedOctetStream.cs index 1773b22cc..829a9a427 100644 --- a/crypto/src/asn1/ConstructedOctetStream.cs +++ b/crypto/src/asn1/ConstructedOctetStream.cs @@ -1,5 +1,6 @@ using System.IO; +using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.IO; namespace Org.BouncyCastle.Asn1 @@ -25,13 +26,12 @@ namespace Org.BouncyCastle.Asn1 if (!_first) return 0; - Asn1OctetStringParser s = (Asn1OctetStringParser)_parser.ReadObject(); - - if (s == null) - return 0; + Asn1OctetStringParser next = GetNextParser(); + if (next == null) + return 0; _first = false; - _currentStream = s.GetOctetStream(); + _currentStream = next.GetOctetStream(); } int totalRead = 0; @@ -49,15 +49,14 @@ namespace Org.BouncyCastle.Asn1 } else { - Asn1OctetStringParser aos = (Asn1OctetStringParser)_parser.ReadObject(); - - if (aos == null) + Asn1OctetStringParser next = GetNextParser(); + if (next == null) { _currentStream = null; return totalRead; } - _currentStream = aos.GetOctetStream(); + _currentStream = next.GetOctetStream(); } } } @@ -69,13 +68,12 @@ namespace Org.BouncyCastle.Asn1 if (!_first) return 0; - Asn1OctetStringParser s = (Asn1OctetStringParser)_parser.ReadObject(); - - if (s == null) + Asn1OctetStringParser next = GetNextParser(); + if (next == null) return 0; _first = false; - _currentStream = s.GetOctetStream(); + _currentStream = next.GetOctetStream(); } for (;;) @@ -83,20 +81,29 @@ namespace Org.BouncyCastle.Asn1 int b = _currentStream.ReadByte(); if (b >= 0) - { return b; - } - - Asn1OctetStringParser aos = (Asn1OctetStringParser)_parser.ReadObject(); - if (aos == null) + Asn1OctetStringParser next = GetNextParser(); + if (next == null) { _currentStream = null; return -1; } - _currentStream = aos.GetOctetStream(); + _currentStream = next.GetOctetStream(); } } + + private Asn1OctetStringParser GetNextParser() + { + IAsn1Convertible asn1Obj = _parser.ReadObject(); + if (asn1Obj == null) + return null; + + if (asn1Obj is Asn1OctetStringParser) + return (Asn1OctetStringParser)asn1Obj; + + throw new IOException("unknown object encountered: " + Platform.GetTypeName(asn1Obj)); + } } } |