SigningCertificate.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ess
  7. {
  8. public class SigningCertificate
  9. : Asn1Encodable
  10. {
  11. private Asn1Sequence certs, policies;
  12. public static SigningCertificate GetInstance(
  13. object o)
  14. {
  15. if (o == null || o is SigningCertificate)
  16. {
  17. return (SigningCertificate) o;
  18. }
  19. if (o is Asn1Sequence)
  20. {
  21. return new SigningCertificate((Asn1Sequence) o);
  22. }
  23. throw new ArgumentException(
  24. "unknown object in 'SigningCertificate' factory : "
  25. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(o) + ".");
  26. }
  27. /**
  28. * constructors
  29. */
  30. public SigningCertificate(
  31. Asn1Sequence seq)
  32. {
  33. if (seq.Count < 1 || seq.Count > 2)
  34. {
  35. throw new ArgumentException("Bad sequence size: " + seq.Count);
  36. }
  37. this.certs = Asn1Sequence.GetInstance(seq[0]);
  38. if (seq.Count > 1)
  39. {
  40. this.policies = Asn1Sequence.GetInstance(seq[1]);
  41. }
  42. }
  43. public SigningCertificate(
  44. EssCertID essCertID)
  45. {
  46. certs = new DerSequence(essCertID);
  47. }
  48. public EssCertID[] GetCerts()
  49. {
  50. EssCertID[] cs = new EssCertID[certs.Count];
  51. for (int i = 0; i != certs.Count; i++)
  52. {
  53. cs[i] = EssCertID.GetInstance(certs[i]);
  54. }
  55. return cs;
  56. }
  57. public PolicyInformation[] GetPolicies()
  58. {
  59. if (policies == null)
  60. {
  61. return null;
  62. }
  63. PolicyInformation[] ps = new PolicyInformation[policies.Count];
  64. for (int i = 0; i != policies.Count; i++)
  65. {
  66. ps[i] = PolicyInformation.GetInstance(policies[i]);
  67. }
  68. return ps;
  69. }
  70. /**
  71. * The definition of SigningCertificate is
  72. * <pre>
  73. * SigningCertificate ::= SEQUENCE {
  74. * certs SEQUENCE OF EssCertID,
  75. * policies SEQUENCE OF PolicyInformation OPTIONAL
  76. * }
  77. * </pre>
  78. * id-aa-signingCertificate OBJECT IDENTIFIER ::= { iso(1)
  79. * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9)
  80. * smime(16) id-aa(2) 12 }
  81. */
  82. public override Asn1Object ToAsn1Object()
  83. {
  84. Asn1EncodableVector v = new Asn1EncodableVector(certs);
  85. if (policies != null)
  86. {
  87. v.Add(policies);
  88. }
  89. return new DerSequence(v);
  90. }
  91. }
  92. }
  93. #pragma warning restore
  94. #endif