ResponderID.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp
  7. {
  8. public class ResponderID
  9. : Asn1Encodable, IAsn1Choice
  10. {
  11. private readonly Asn1Encodable id;
  12. public static ResponderID GetInstance(
  13. object obj)
  14. {
  15. if (obj == null || obj is ResponderID)
  16. {
  17. return (ResponderID)obj;
  18. }
  19. if (obj is DerOctetString)
  20. {
  21. return new ResponderID((DerOctetString)obj);
  22. }
  23. if (obj is Asn1TaggedObject)
  24. {
  25. Asn1TaggedObject o = (Asn1TaggedObject)obj;
  26. if (o.TagNo == 1)
  27. {
  28. return new ResponderID(X509Name.GetInstance(o, true));
  29. }
  30. return new ResponderID(Asn1OctetString.GetInstance(o, true));
  31. }
  32. return new ResponderID(X509Name.GetInstance(obj));
  33. }
  34. public ResponderID(
  35. Asn1OctetString id)
  36. {
  37. if (id == null)
  38. throw new ArgumentNullException("id");
  39. this.id = id;
  40. }
  41. public ResponderID(
  42. X509Name id)
  43. {
  44. if (id == null)
  45. throw new ArgumentNullException("id");
  46. this.id = id;
  47. }
  48. public static ResponderID GetInstance(
  49. Asn1TaggedObject obj,
  50. bool isExplicit)
  51. {
  52. return GetInstance(obj.GetObject()); // must be explicitly tagged
  53. }
  54. public virtual byte[] GetKeyHash()
  55. {
  56. if (id is Asn1OctetString)
  57. {
  58. return ((Asn1OctetString)id).GetOctets();
  59. }
  60. return null;
  61. }
  62. public virtual X509Name Name
  63. {
  64. get
  65. {
  66. if (id is Asn1OctetString)
  67. {
  68. return null;
  69. }
  70. return X509Name.GetInstance(id);
  71. }
  72. }
  73. /**
  74. * Produce an object suitable for an Asn1OutputStream.
  75. * <pre>
  76. * ResponderID ::= CHOICE {
  77. * byName [1] Name,
  78. * byKey [2] KeyHash }
  79. * </pre>
  80. */
  81. public override Asn1Object ToAsn1Object()
  82. {
  83. if (id is Asn1OctetString)
  84. {
  85. return new DerTaggedObject(true, 2, id);
  86. }
  87. return new DerTaggedObject(true, 1, id);
  88. }
  89. }
  90. }
  91. #pragma warning restore
  92. #endif