ServiceLocator.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. v.AddOptional(locator);
  75. return new DerSequence(v);
  76. }
  77. }
  78. }
  79. #pragma warning restore
  80. #endif