LazyDLEnumerator.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1
  7. {
  8. internal class LazyDLEnumerator
  9. : IEnumerator<Asn1Encodable>
  10. {
  11. private readonly byte[] m_contents;
  12. private Asn1InputStream m_input;
  13. private Asn1Object m_current;
  14. internal LazyDLEnumerator(byte[] contents)
  15. {
  16. this.m_contents = contents;
  17. Reset();
  18. }
  19. object System.Collections.IEnumerator.Current
  20. {
  21. get { return Current; }
  22. }
  23. public Asn1Encodable Current
  24. {
  25. get
  26. {
  27. if (null == m_current)
  28. throw new InvalidOperationException();
  29. return m_current;
  30. }
  31. }
  32. public virtual void Dispose()
  33. {
  34. }
  35. public bool MoveNext()
  36. {
  37. return null != (this.m_current = ReadObject());
  38. }
  39. public void Reset()
  40. {
  41. this.m_input = new LazyAsn1InputStream(m_contents);
  42. this.m_current = null;
  43. }
  44. private Asn1Object ReadObject()
  45. {
  46. try
  47. {
  48. return m_input.ReadObject();
  49. }
  50. catch (IOException e)
  51. {
  52. throw new Asn1ParsingException("malformed ASN.1: " + e.Message, e);
  53. }
  54. }
  55. }
  56. }
  57. #pragma warning restore
  58. #endif