OtherSigningCertificate.cs 3.1 KB

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