OriginatorInfoGenerator.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System.Collections.Generic;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.X509;
  8. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms
  9. {
  10. public class OriginatorInfoGenerator
  11. {
  12. private readonly List<Asn1Encodable> origCerts;
  13. private readonly List<Asn1Encodable> origCrls;
  14. public OriginatorInfoGenerator(X509Certificate origCert)
  15. {
  16. this.origCerts = new List<Asn1Encodable>{ origCert.CertificateStructure };
  17. this.origCrls = null;
  18. }
  19. public OriginatorInfoGenerator(IStore<X509Certificate> x509Certs)
  20. : this(x509Certs, null, null, null)
  21. {
  22. }
  23. public OriginatorInfoGenerator(IStore<X509Certificate> x509Certs, IStore<X509Crl> x509Crls)
  24. : this(x509Certs, x509Crls, null, null)
  25. {
  26. }
  27. public OriginatorInfoGenerator(IStore<X509Certificate> x509Certs, IStore<X509Crl> x509Crls,
  28. IStore<X509V2AttributeCertificate> x509AttrCerts, IStore<OtherRevocationInfoFormat> otherRevocationInfos)
  29. {
  30. List<Asn1Encodable> certificates = null;
  31. if (x509Certs != null || x509AttrCerts != null)
  32. {
  33. certificates = new List<Asn1Encodable>();
  34. if (x509Certs != null)
  35. {
  36. certificates.AddRange(CmsUtilities.GetCertificatesFromStore(x509Certs));
  37. }
  38. if (x509AttrCerts != null)
  39. {
  40. certificates.AddRange(CmsUtilities.GetAttributeCertificatesFromStore(x509AttrCerts));
  41. }
  42. }
  43. List<Asn1Encodable> revocations = null;
  44. if (x509Crls != null || otherRevocationInfos != null)
  45. {
  46. revocations = new List<Asn1Encodable>();
  47. if (x509Crls != null)
  48. {
  49. revocations.AddRange(CmsUtilities.GetCrlsFromStore(x509Crls));
  50. }
  51. if (otherRevocationInfos != null)
  52. {
  53. revocations.AddRange(CmsUtilities.GetOtherRevocationInfosFromStore(otherRevocationInfos));
  54. }
  55. }
  56. this.origCerts = certificates;
  57. this.origCrls = revocations;
  58. }
  59. public virtual OriginatorInfo Generate()
  60. {
  61. Asn1Set certSet = origCerts == null ? null : CmsUtilities.CreateDerSetFromList(origCerts);
  62. Asn1Set crlSet = origCrls == null ? null : CmsUtilities.CreateDerSetFromList(origCrls);
  63. return new OriginatorInfo(certSet, crlSet);
  64. }
  65. }
  66. }
  67. #pragma warning restore
  68. #endif