ResponseBytes.cs 2.2 KB

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