ServiceLocator.cs 2.1 KB

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