123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1
- {
- internal class LazyDLSet
- : DLSet
- {
- private byte[] encoded;
- internal LazyDLSet(byte[] encoded)
- : base()
- {
- if (null == encoded)
- throw new ArgumentNullException("encoded");
- this.encoded = encoded;
- }
- public override Asn1Encodable this[int index]
- {
- get
- {
- Force();
- return base[index];
- }
- }
- public override IEnumerator<Asn1Encodable> GetEnumerator()
- {
- byte[] encoded = GetContents();
- if (null != encoded)
- return new LazyDLEnumerator(encoded);
- return base.GetEnumerator();
- }
- public override int Count
- {
- get
- {
- Force();
- return base.Count;
- }
- }
- public override Asn1Encodable[] ToArray()
- {
- Force();
- return base.ToArray();
- }
- public override string ToString()
- {
- Force();
- return base.ToString();
- }
- internal override IAsn1Encoding GetEncoding(int encoding)
- {
- if (Asn1OutputStream.EncodingBer == encoding)
- {
- byte[] encoded = GetContents();
- if (null != encoded)
- return new ConstructedLazyDLEncoding(Asn1Tags.Universal, Asn1Tags.Set, encoded);
- }
- else
- {
- Force();
- }
- return base.GetEncoding(encoding);
- }
- internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
- {
- if (Asn1OutputStream.EncodingBer == encoding)
- {
- byte[] encoded = GetContents();
- if (null != encoded)
- return new ConstructedLazyDLEncoding(tagClass, tagNo, encoded);
- }
- else
- {
- Force();
- }
- return base.GetEncodingImplicit(encoding, tagClass, tagNo);
- }
- private void Force()
- {
- lock (this)
- {
- if (null != encoded)
- {
- Asn1InputStream input = new LazyAsn1InputStream(encoded);
- try
- {
- Asn1EncodableVector v = input.ReadVector();
- this.elements = v.TakeElements();
- this.isSorted = elements.Length < 2;
- this.encoded = null;
- }
- catch (IOException e)
- {
- throw new Asn1ParsingException("malformed ASN.1: " + e.Message, e);
- }
- }
- }
- }
- private byte[] GetContents()
- {
- lock (this) return encoded;
- }
- }
- }
- #pragma warning restore
- #endif
|