CertResponse.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 CertResponse
  8. : Asn1Encodable
  9. {
  10. private readonly DerInteger certReqId;
  11. private readonly PkiStatusInfo status;
  12. private readonly CertifiedKeyPair certifiedKeyPair;
  13. private readonly Asn1OctetString rspInfo;
  14. private CertResponse(Asn1Sequence seq)
  15. {
  16. certReqId = DerInteger.GetInstance(seq[0]);
  17. status = PkiStatusInfo.GetInstance(seq[1]);
  18. if (seq.Count >= 3)
  19. {
  20. if (seq.Count == 3)
  21. {
  22. Asn1Encodable o = seq[2];
  23. if (o is Asn1OctetString)
  24. {
  25. rspInfo = Asn1OctetString.GetInstance(o);
  26. }
  27. else
  28. {
  29. certifiedKeyPair = CertifiedKeyPair.GetInstance(o);
  30. }
  31. }
  32. else
  33. {
  34. certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
  35. rspInfo = Asn1OctetString.GetInstance(seq[3]);
  36. }
  37. }
  38. }
  39. public static CertResponse GetInstance(object obj)
  40. {
  41. if (obj is CertResponse)
  42. return (CertResponse)obj;
  43. if (obj is Asn1Sequence)
  44. return new CertResponse((Asn1Sequence)obj);
  45. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  46. }
  47. public CertResponse(
  48. DerInteger certReqId,
  49. PkiStatusInfo status)
  50. : this(certReqId, status, null, null)
  51. {
  52. }
  53. public CertResponse(
  54. DerInteger certReqId,
  55. PkiStatusInfo status,
  56. CertifiedKeyPair certifiedKeyPair,
  57. Asn1OctetString rspInfo)
  58. {
  59. if (certReqId == null)
  60. throw new ArgumentNullException("certReqId");
  61. if (status == null)
  62. throw new ArgumentNullException("status");
  63. this.certReqId = certReqId;
  64. this.status = status;
  65. this.certifiedKeyPair = certifiedKeyPair;
  66. this.rspInfo = rspInfo;
  67. }
  68. public virtual DerInteger CertReqID
  69. {
  70. get { return certReqId; }
  71. }
  72. public virtual PkiStatusInfo Status
  73. {
  74. get { return status; }
  75. }
  76. public virtual CertifiedKeyPair CertifiedKeyPair
  77. {
  78. get { return certifiedKeyPair; }
  79. }
  80. /**
  81. * <pre>
  82. * CertResponse ::= SEQUENCE {
  83. * certReqId INTEGER,
  84. * -- to match this response with corresponding request (a value
  85. * -- of -1 is to be used if certReqId is not specified in the
  86. * -- corresponding request)
  87. * status PKIStatusInfo,
  88. * certifiedKeyPair CertifiedKeyPair OPTIONAL,
  89. * rspInfo OCTET STRING OPTIONAL
  90. * -- analogous to the id-regInfo-utf8Pairs string defined
  91. * -- for regInfo in CertReqMsg [CRMF]
  92. * }
  93. * </pre>
  94. * @return a basic ASN.1 object representation.
  95. */
  96. public override Asn1Object ToAsn1Object()
  97. {
  98. Asn1EncodableVector v = new Asn1EncodableVector(certReqId, status);
  99. v.AddOptional(certifiedKeyPair, rspInfo);
  100. return new DerSequence(v);
  101. }
  102. }
  103. }
  104. #pragma warning restore
  105. #endif