OCSPResp.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Ocsp
  8. {
  9. public class OcspResp
  10. {
  11. private OcspResponse resp;
  12. public OcspResp(
  13. OcspResponse resp)
  14. {
  15. this.resp = resp;
  16. }
  17. public OcspResp(
  18. byte[] resp)
  19. : this(new Asn1InputStream(resp))
  20. {
  21. }
  22. public OcspResp(
  23. Stream inStr)
  24. : this(new Asn1InputStream(inStr))
  25. {
  26. }
  27. private OcspResp(
  28. Asn1InputStream aIn)
  29. {
  30. try
  31. {
  32. this.resp = OcspResponse.GetInstance(aIn.ReadObject());
  33. }
  34. catch (Exception e)
  35. {
  36. throw new IOException("malformed response: " + e.Message, e);
  37. }
  38. }
  39. public int Status
  40. {
  41. get { return this.resp.ResponseStatus.IntValueExact; }
  42. }
  43. public object GetResponseObject()
  44. {
  45. ResponseBytes rb = this.resp.ResponseBytes;
  46. if (rb == null)
  47. return null;
  48. if (rb.ResponseType.Equals(OcspObjectIdentifiers.PkixOcspBasic))
  49. {
  50. try
  51. {
  52. return new BasicOcspResp(
  53. BasicOcspResponse.GetInstance(
  54. Asn1Object.FromByteArray(rb.Response.GetOctets())));
  55. }
  56. catch (Exception e)
  57. {
  58. throw new OcspException("problem decoding object: " + e, e);
  59. }
  60. }
  61. return rb.Response;
  62. }
  63. /**
  64. * return the ASN.1 encoded representation of this object.
  65. */
  66. public byte[] GetEncoded()
  67. {
  68. return resp.GetEncoded();
  69. }
  70. public override bool Equals(
  71. object obj)
  72. {
  73. if (obj == this)
  74. return true;
  75. OcspResp other = obj as OcspResp;
  76. if (other == null)
  77. return false;
  78. return resp.Equals(other.resp);
  79. }
  80. public override int GetHashCode()
  81. {
  82. return resp.GetHashCode();
  83. }
  84. }
  85. }
  86. #pragma warning restore
  87. #endif