diff options
-rw-r--r-- | crypto/src/asn1/Asn1InputStream.cs | 8 | ||||
-rw-r--r-- | crypto/src/asn1/BEROctetStringParser.cs | 54 | ||||
-rw-r--r-- | crypto/src/asn1/BERSequenceParser.cs | 42 | ||||
-rw-r--r-- | crypto/src/asn1/BERSetParser.cs | 42 | ||||
-rw-r--r-- | crypto/src/asn1/DERExternalParser.cs | 11 |
5 files changed, 89 insertions, 68 deletions
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs index 8ce55a2b7..76bc3076d 100644 --- a/crypto/src/asn1/Asn1InputStream.cs +++ b/crypto/src/asn1/Asn1InputStream.cs @@ -215,13 +215,13 @@ namespace Org.BouncyCastle.Asn1 switch (tagNo) { case Asn1Tags.OctetString: - return new BerOctetStringParser(sp).ToAsn1Object(); + return BerOctetStringParser.Parse(sp); case Asn1Tags.Sequence: - return new BerSequenceParser(sp).ToAsn1Object(); + return BerSequenceParser.Parse(sp); case Asn1Tags.Set: - return new BerSetParser(sp).ToAsn1Object(); + return BerSetParser.Parse(sp); case Asn1Tags.External: - return new DerExternalParser(sp).ToAsn1Object(); + return DerExternalParser.Parse(sp); default: throw new IOException("unknown BER object encountered"); } diff --git a/crypto/src/asn1/BEROctetStringParser.cs b/crypto/src/asn1/BEROctetStringParser.cs index 3bfd2a98d..c8c344e11 100644 --- a/crypto/src/asn1/BEROctetStringParser.cs +++ b/crypto/src/asn1/BEROctetStringParser.cs @@ -5,32 +5,36 @@ using Org.BouncyCastle.Utilities.IO; namespace Org.BouncyCastle.Asn1 { - public class BerOctetStringParser - : Asn1OctetStringParser - { - private readonly Asn1StreamParser _parser; + public class BerOctetStringParser + : Asn1OctetStringParser + { + private readonly Asn1StreamParser _parser; - internal BerOctetStringParser( - Asn1StreamParser parser) - { - _parser = parser; - } + internal BerOctetStringParser(Asn1StreamParser parser) + { + _parser = parser; + } - public Stream GetOctetStream() - { - return new ConstructedOctetStream(_parser); - } + public Stream GetOctetStream() + { + return new ConstructedOctetStream(_parser); + } - public Asn1Object ToAsn1Object() - { - try - { - return new BerOctetString(Streams.ReadAll(GetOctetStream())); - } - catch (IOException e) - { - throw new Asn1ParsingException("IOException converting stream to byte array: " + e.Message, e); - } - } - } + public Asn1Object ToAsn1Object() + { + try + { + return Parse(_parser); + } + catch (IOException e) + { + throw new Asn1ParsingException("IOException converting stream to byte array: " + e.Message, e); + } + } + + internal static BerOctetString Parse(Asn1StreamParser sp) + { + return new BerOctetString(Streams.ReadAll(new ConstructedOctetStream(sp))); + } + } } diff --git a/crypto/src/asn1/BERSequenceParser.cs b/crypto/src/asn1/BERSequenceParser.cs index 8474b8d24..5fa1de8a6 100644 --- a/crypto/src/asn1/BERSequenceParser.cs +++ b/crypto/src/asn1/BERSequenceParser.cs @@ -1,24 +1,30 @@ +using System; + namespace Org.BouncyCastle.Asn1 { - public class BerSequenceParser - : Asn1SequenceParser - { - private readonly Asn1StreamParser _parser; + public class BerSequenceParser + : Asn1SequenceParser + { + private readonly Asn1StreamParser _parser; + + internal BerSequenceParser(Asn1StreamParser parser) + { + this._parser = parser; + } - internal BerSequenceParser( - Asn1StreamParser parser) - { - this._parser = parser; - } + public IAsn1Convertible ReadObject() + { + return _parser.ReadObject(); + } - public IAsn1Convertible ReadObject() - { - return _parser.ReadObject(); - } + public Asn1Object ToAsn1Object() + { + return Parse(_parser); + } - public Asn1Object ToAsn1Object() - { - return new BerSequence(_parser.ReadVector()); - } - } + internal static BerSequence Parse(Asn1StreamParser sp) + { + return new BerSequence(sp.ReadVector()); + } + } } diff --git a/crypto/src/asn1/BERSetParser.cs b/crypto/src/asn1/BERSetParser.cs index aa9ccbc12..9da964c61 100644 --- a/crypto/src/asn1/BERSetParser.cs +++ b/crypto/src/asn1/BERSetParser.cs @@ -1,24 +1,30 @@ +using System; + namespace Org.BouncyCastle.Asn1 { - public class BerSetParser - : Asn1SetParser - { - private readonly Asn1StreamParser _parser; + public class BerSetParser + : Asn1SetParser + { + private readonly Asn1StreamParser _parser; + + internal BerSetParser(Asn1StreamParser parser) + { + this._parser = parser; + } - internal BerSetParser( - Asn1StreamParser parser) - { - this._parser = parser; - } + public IAsn1Convertible ReadObject() + { + return _parser.ReadObject(); + } - public IAsn1Convertible ReadObject() - { - return _parser.ReadObject(); - } + public Asn1Object ToAsn1Object() + { + return Parse(_parser); + } - public Asn1Object ToAsn1Object() - { - return new BerSet(_parser.ReadVector(), false); - } - } + internal static BerSet Parse(Asn1StreamParser sp) + { + return new BerSet(sp.ReadVector()); + } + } } diff --git a/crypto/src/asn1/DERExternalParser.cs b/crypto/src/asn1/DERExternalParser.cs index 70e426fed..5e52e63c6 100644 --- a/crypto/src/asn1/DERExternalParser.cs +++ b/crypto/src/asn1/DERExternalParser.cs @@ -1,5 +1,4 @@ using System; -using System.IO; namespace Org.BouncyCastle.Asn1 { @@ -8,6 +7,7 @@ namespace Org.BouncyCastle.Asn1 { private readonly Asn1StreamParser _parser; + [Obsolete("Will be removed")] public DerExternalParser(Asn1StreamParser parser) { this._parser = parser; @@ -20,7 +20,12 @@ namespace Org.BouncyCastle.Asn1 public override Asn1Object ToAsn1Object() { - return new DerExternal(_parser.ReadVector()); + return Parse(_parser); } - } + + internal static DerExternal Parse(Asn1StreamParser sp) + { + return new DerExternal(sp.ReadVector()); + } + } } |