CertRepMessage.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
  6. {
  7. public class CertRepMessage
  8. : Asn1Encodable
  9. {
  10. private readonly Asn1Sequence caPubs;
  11. private readonly Asn1Sequence response;
  12. private CertRepMessage(Asn1Sequence seq)
  13. {
  14. int index = 0;
  15. if (seq.Count > 1)
  16. {
  17. caPubs = Asn1Sequence.GetInstance((Asn1TaggedObject)seq[index++], true);
  18. }
  19. response = Asn1Sequence.GetInstance(seq[index]);
  20. }
  21. public static CertRepMessage GetInstance(object obj)
  22. {
  23. if (obj is CertRepMessage)
  24. return (CertRepMessage)obj;
  25. if (obj is Asn1Sequence)
  26. return new CertRepMessage((Asn1Sequence)obj);
  27. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  28. }
  29. public CertRepMessage(CmpCertificate[] caPubs, CertResponse[] response)
  30. {
  31. if (response == null)
  32. throw new ArgumentNullException("response");
  33. if (caPubs != null)
  34. {
  35. this.caPubs = new DerSequence(caPubs);
  36. }
  37. this.response = new DerSequence(response);
  38. }
  39. public virtual CmpCertificate[] GetCAPubs()
  40. {
  41. if (caPubs == null)
  42. return null;
  43. CmpCertificate[] results = new CmpCertificate[caPubs.Count];
  44. for (int i = 0; i != results.Length; ++i)
  45. {
  46. results[i] = CmpCertificate.GetInstance(caPubs[i]);
  47. }
  48. return results;
  49. }
  50. public virtual CertResponse[] GetResponse()
  51. {
  52. CertResponse[] results = new CertResponse[response.Count];
  53. for (int i = 0; i != results.Length; ++i)
  54. {
  55. results[i] = CertResponse.GetInstance(response[i]);
  56. }
  57. return results;
  58. }
  59. /**
  60. * <pre>
  61. * CertRepMessage ::= SEQUENCE {
  62. * caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  63. * OPTIONAL,
  64. * response SEQUENCE OF CertResponse
  65. * }
  66. * </pre>
  67. * @return a basic ASN.1 object representation.
  68. */
  69. public override Asn1Object ToAsn1Object()
  70. {
  71. Asn1EncodableVector v = new Asn1EncodableVector();
  72. v.AddOptionalTagged(true, 1, caPubs);
  73. v.Add(response);
  74. return new DerSequence(v);
  75. }
  76. }
  77. }
  78. #pragma warning restore
  79. #endif