LazyDERSequence.cs 1.2 KB

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