123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Collections;
- using System.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.X509
- {
- public class X509CertPairParser
- {
- private Stream currentStream;
- private X509CertificatePair ReadDerCrossCertificatePair(
- Stream inStream)
- {
- Asn1InputStream dIn = new Asn1InputStream(inStream);//, ProviderUtil.getReadLimit(in));
- Asn1Sequence seq = (Asn1Sequence)dIn.ReadObject();
- CertificatePair pair = CertificatePair.GetInstance(seq);
- return new X509CertificatePair(pair);
- }
- /// <summary>
- /// Create loading data from byte array.
- /// </summary>
- /// <param name="input"></param>
- public X509CertificatePair ReadCertPair(
- byte[] input)
- {
- return ReadCertPair(new MemoryStream(input, false));
- }
- /// <summary>
- /// Create loading data from byte array.
- /// </summary>
- /// <param name="input"></param>
- public ICollection ReadCertPairs(
- byte[] input)
- {
- return ReadCertPairs(new MemoryStream(input, false));
- }
- public X509CertificatePair ReadCertPair(
- Stream inStream)
- {
- if (inStream == null)
- throw new ArgumentNullException("inStream");
- if (!inStream.CanRead)
- throw new ArgumentException("inStream must be read-able", "inStream");
- if (currentStream == null)
- {
- currentStream = inStream;
- }
- else if (currentStream != inStream) // reset if input stream has changed
- {
- currentStream = inStream;
- }
- try
- {
- PushbackStream pis = new PushbackStream(inStream);
- int tag = pis.ReadByte();
- if (tag < 0)
- return null;
- pis.Unread(tag);
- return ReadDerCrossCertificatePair(pis);
- }
- catch (Exception e)
- {
- throw new CertificateException(e.ToString());
- }
- }
- public ICollection ReadCertPairs(
- Stream inStream)
- {
- X509CertificatePair certPair;
- IList certPairs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- while ((certPair = ReadCertPair(inStream)) != null)
- {
- certPairs.Add(certPair);
- }
- return certPairs;
- }
- }
- }
- #pragma warning restore
- #endif
|