OriginatorInformation.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  9. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
  10. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
  11. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
  12. {
  13. public class OriginatorInformation
  14. {
  15. private readonly OriginatorInfo originatorInfo;
  16. internal OriginatorInformation(OriginatorInfo originatorInfo)
  17. {
  18. this.originatorInfo = originatorInfo;
  19. }
  20. /**
  21. * Return the certificates stored in the underlying OriginatorInfo object.
  22. *
  23. * @return a Store of X509CertificateHolder objects.
  24. */
  25. public virtual IX509Store GetCertificates()
  26. {
  27. Asn1Set certSet = originatorInfo.Certificates;
  28. if (certSet != null)
  29. {
  30. IList certList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(certSet.Count);
  31. foreach (Asn1Encodable enc in certSet)
  32. {
  33. Asn1Object obj = enc.ToAsn1Object();
  34. if (obj is Asn1Sequence)
  35. {
  36. certList.Add(new X509Certificate(X509CertificateStructure.GetInstance(obj)));
  37. }
  38. }
  39. return X509StoreFactory.Create(
  40. "Certificate/Collection",
  41. new X509CollectionStoreParameters(certList));
  42. }
  43. return X509StoreFactory.Create(
  44. "Certificate/Collection",
  45. new X509CollectionStoreParameters(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList()));
  46. }
  47. /**
  48. * Return the CRLs stored in the underlying OriginatorInfo object.
  49. *
  50. * @return a Store of X509CRLHolder objects.
  51. */
  52. public virtual IX509Store GetCrls()
  53. {
  54. Asn1Set crlSet = originatorInfo.Certificates;
  55. if (crlSet != null)
  56. {
  57. IList crlList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(crlSet.Count);
  58. foreach (Asn1Encodable enc in crlSet)
  59. {
  60. Asn1Object obj = enc.ToAsn1Object();
  61. if (obj is Asn1Sequence)
  62. {
  63. crlList.Add(new X509Crl(CertificateList.GetInstance(obj)));
  64. }
  65. }
  66. return X509StoreFactory.Create(
  67. "CRL/Collection",
  68. new X509CollectionStoreParameters(crlList));
  69. }
  70. return X509StoreFactory.Create(
  71. "CRL/Collection",
  72. new X509CollectionStoreParameters(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList()));
  73. }
  74. /**
  75. * Return the underlying ASN.1 object defining this SignerInformation object.
  76. *
  77. * @return a OriginatorInfo.
  78. */
  79. public virtual OriginatorInfo ToAsn1Structure()
  80. {
  81. return originatorInfo;
  82. }
  83. }
  84. }
  85. #pragma warning restore
  86. #endif