LazyDERSequence.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. namespace Org.BouncyCastle.Asn1
  6. {
  7. internal class LazyDerSequence
  8. : DerSequence
  9. {
  10. private byte[] encoded;
  11. internal LazyDerSequence(
  12. byte[] encoded)
  13. {
  14. this.encoded = encoded;
  15. }
  16. private void Parse()
  17. {
  18. lock (this)
  19. {
  20. if (encoded != null)
  21. {
  22. Asn1InputStream e = new LazyAsn1InputStream(encoded);
  23. Asn1Object o;
  24. while ((o = e.ReadObject()) != null)
  25. {
  26. AddObject(o);
  27. }
  28. encoded = null;
  29. }
  30. }
  31. }
  32. public override Asn1Encodable this[int index]
  33. {
  34. get
  35. {
  36. Parse();
  37. return base[index];
  38. }
  39. }
  40. public override IEnumerator GetEnumerator()
  41. {
  42. Parse();
  43. return base.GetEnumerator();
  44. }
  45. public override int Count
  46. {
  47. get
  48. {
  49. Parse();
  50. return base.Count;
  51. }
  52. }
  53. internal override void Encode(
  54. DerOutputStream derOut)
  55. {
  56. lock (this)
  57. {
  58. if (encoded == null)
  59. {
  60. base.Encode(derOut);
  61. }
  62. else
  63. {
  64. derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, encoded);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. #endif