OtherSigningCertificate.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  8. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf
  9. {
  10. /// <remarks>
  11. /// <code>
  12. /// OtherSigningCertificate ::= SEQUENCE {
  13. /// certs SEQUENCE OF OtherCertID,
  14. /// policies SEQUENCE OF PolicyInformation OPTIONAL
  15. /// }
  16. /// </code>
  17. /// </remarks>
  18. public class OtherSigningCertificate
  19. : Asn1Encodable
  20. {
  21. private readonly Asn1Sequence certs;
  22. private readonly Asn1Sequence policies;
  23. public static OtherSigningCertificate GetInstance(
  24. object obj)
  25. {
  26. if (obj == null || obj is OtherSigningCertificate)
  27. return (OtherSigningCertificate) obj;
  28. if (obj is Asn1Sequence)
  29. return new OtherSigningCertificate((Asn1Sequence) obj);
  30. throw new ArgumentException(
  31. "Unknown object in 'OtherSigningCertificate' factory: "
  32. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj),
  33. "obj");
  34. }
  35. private OtherSigningCertificate(
  36. Asn1Sequence seq)
  37. {
  38. if (seq == null)
  39. throw new ArgumentNullException("seq");
  40. if (seq.Count < 1 || seq.Count > 2)
  41. throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
  42. this.certs = Asn1Sequence.GetInstance(seq[0].ToAsn1Object());
  43. if (seq.Count > 1)
  44. {
  45. this.policies = Asn1Sequence.GetInstance(seq[1].ToAsn1Object());
  46. }
  47. }
  48. public OtherSigningCertificate(
  49. params OtherCertID[] certs)
  50. : this(certs, null)
  51. {
  52. }
  53. public OtherSigningCertificate(
  54. OtherCertID[] certs,
  55. params PolicyInformation[] policies)
  56. {
  57. if (certs == null)
  58. throw new ArgumentNullException("certs");
  59. this.certs = new DerSequence(certs);
  60. if (policies != null)
  61. {
  62. this.policies = new DerSequence(policies);
  63. }
  64. }
  65. public OtherSigningCertificate(
  66. IEnumerable certs)
  67. : this(certs, null)
  68. {
  69. }
  70. public OtherSigningCertificate(
  71. IEnumerable certs,
  72. IEnumerable policies)
  73. {
  74. if (certs == null)
  75. throw new ArgumentNullException("certs");
  76. if (!CollectionUtilities.CheckElementsAreOfType(certs, typeof(OtherCertID)))
  77. throw new ArgumentException("Must contain only 'OtherCertID' objects", "certs");
  78. this.certs = new DerSequence(
  79. Asn1EncodableVector.FromEnumerable(certs));
  80. if (policies != null)
  81. {
  82. if (!CollectionUtilities.CheckElementsAreOfType(policies, typeof(PolicyInformation)))
  83. throw new ArgumentException("Must contain only 'PolicyInformation' objects", "policies");
  84. this.policies = new DerSequence(
  85. Asn1EncodableVector.FromEnumerable(policies));
  86. }
  87. }
  88. public OtherCertID[] GetCerts()
  89. {
  90. OtherCertID[] cs = new OtherCertID[certs.Count];
  91. for (int i = 0; i < certs.Count; ++i)
  92. {
  93. cs[i] = OtherCertID.GetInstance(certs[i].ToAsn1Object());
  94. }
  95. return cs;
  96. }
  97. public PolicyInformation[] GetPolicies()
  98. {
  99. if (policies == null)
  100. return null;
  101. PolicyInformation[] ps = new PolicyInformation[policies.Count];
  102. for (int i = 0; i < policies.Count; ++i)
  103. {
  104. ps[i] = PolicyInformation.GetInstance(policies[i].ToAsn1Object());
  105. }
  106. return ps;
  107. }
  108. public override Asn1Object ToAsn1Object()
  109. {
  110. Asn1EncodableVector v = new Asn1EncodableVector(certs);
  111. if (policies != null)
  112. {
  113. v.Add(policies);
  114. }
  115. return new DerSequence(v);
  116. }
  117. }
  118. }
  119. #pragma warning restore
  120. #endif