ResponseBytes.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 ResponseBytes
  7. : Asn1Encodable
  8. {
  9. private readonly DerObjectIdentifier responseType;
  10. private readonly Asn1OctetString response;
  11. public static ResponseBytes GetInstance(
  12. Asn1TaggedObject obj,
  13. bool explicitly)
  14. {
  15. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  16. }
  17. public static ResponseBytes GetInstance(
  18. object obj)
  19. {
  20. if (obj == null || obj is ResponseBytes)
  21. {
  22. return (ResponseBytes)obj;
  23. }
  24. if (obj is Asn1Sequence)
  25. {
  26. return new ResponseBytes((Asn1Sequence)obj);
  27. }
  28. throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  29. }
  30. public ResponseBytes(
  31. DerObjectIdentifier responseType,
  32. Asn1OctetString response)
  33. {
  34. if (responseType == null)
  35. throw new ArgumentNullException("responseType");
  36. if (response == null)
  37. throw new ArgumentNullException("response");
  38. this.responseType = responseType;
  39. this.response = response;
  40. }
  41. private ResponseBytes(
  42. Asn1Sequence seq)
  43. {
  44. if (seq.Count != 2)
  45. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  46. this.responseType = DerObjectIdentifier.GetInstance(seq[0]);
  47. this.response = Asn1OctetString.GetInstance(seq[1]);
  48. }
  49. public DerObjectIdentifier ResponseType
  50. {
  51. get { return responseType; }
  52. }
  53. public Asn1OctetString Response
  54. {
  55. get { return response; }
  56. }
  57. /**
  58. * Produce an object suitable for an Asn1OutputStream.
  59. * <pre>
  60. * ResponseBytes ::= Sequence {
  61. * responseType OBJECT IDENTIFIER,
  62. * response OCTET STRING }
  63. * </pre>
  64. */
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return new DerSequence(responseType, response);
  68. }
  69. }
  70. }
  71. #endif