OCSPResponse.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Utilities;
  4. namespace Org.BouncyCastle.Asn1.Ocsp
  5. {
  6. public class OcspResponse
  7. : Asn1Encodable
  8. {
  9. private readonly OcspResponseStatus responseStatus;
  10. private readonly ResponseBytes responseBytes;
  11. public static OcspResponse GetInstance(
  12. Asn1TaggedObject obj,
  13. bool explicitly)
  14. {
  15. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  16. }
  17. public static OcspResponse GetInstance(
  18. object obj)
  19. {
  20. if (obj == null || obj is OcspResponse)
  21. {
  22. return (OcspResponse)obj;
  23. }
  24. if (obj is Asn1Sequence)
  25. {
  26. return new OcspResponse((Asn1Sequence)obj);
  27. }
  28. throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  29. }
  30. public OcspResponse(
  31. OcspResponseStatus responseStatus,
  32. ResponseBytes responseBytes)
  33. {
  34. if (responseStatus == null)
  35. throw new ArgumentNullException("responseStatus");
  36. this.responseStatus = responseStatus;
  37. this.responseBytes = responseBytes;
  38. }
  39. private OcspResponse(
  40. Asn1Sequence seq)
  41. {
  42. responseStatus = new OcspResponseStatus(
  43. DerEnumerated.GetInstance(seq[0]));
  44. if (seq.Count == 2)
  45. {
  46. responseBytes = ResponseBytes.GetInstance(
  47. (Asn1TaggedObject)seq[1], true);
  48. }
  49. }
  50. public OcspResponseStatus ResponseStatus
  51. {
  52. get { return responseStatus; }
  53. }
  54. public ResponseBytes ResponseBytes
  55. {
  56. get { return responseBytes; }
  57. }
  58. /**
  59. * Produce an object suitable for an Asn1OutputStream.
  60. * <pre>
  61. * OcspResponse ::= Sequence {
  62. * responseStatus OcspResponseStatus,
  63. * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
  64. * </pre>
  65. */
  66. public override Asn1Object ToAsn1Object()
  67. {
  68. Asn1EncodableVector v = new Asn1EncodableVector(responseStatus);
  69. if (responseBytes != null)
  70. {
  71. v.Add(new DerTaggedObject(true, 0, responseBytes));
  72. }
  73. return new DerSequence(v);
  74. }
  75. }
  76. }
  77. #endif