DistributionPointName.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
  7. {
  8. /**
  9. * The DistributionPointName object.
  10. * <pre>
  11. * DistributionPointName ::= CHOICE {
  12. * fullName [0] GeneralNames,
  13. * nameRelativeToCRLIssuer [1] RDN
  14. * }
  15. * </pre>
  16. */
  17. public class DistributionPointName
  18. : Asn1Encodable, IAsn1Choice
  19. {
  20. internal readonly Asn1Encodable name;
  21. internal readonly int type;
  22. public const int FullName = 0;
  23. public const int NameRelativeToCrlIssuer = 1;
  24. public static DistributionPointName GetInstance(
  25. Asn1TaggedObject obj,
  26. bool explicitly)
  27. {
  28. return GetInstance(Asn1TaggedObject.GetInstance(obj, true));
  29. }
  30. public static DistributionPointName GetInstance(
  31. object obj)
  32. {
  33. if (obj == null || obj is DistributionPointName)
  34. {
  35. return (DistributionPointName) obj;
  36. }
  37. if (obj is Asn1TaggedObject)
  38. {
  39. return new DistributionPointName((Asn1TaggedObject) obj);
  40. }
  41. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  42. }
  43. public DistributionPointName(
  44. int type,
  45. Asn1Encodable name)
  46. {
  47. this.type = type;
  48. this.name = name;
  49. }
  50. public DistributionPointName(
  51. GeneralNames name)
  52. : this(FullName, name)
  53. {
  54. }
  55. public int PointType
  56. {
  57. get { return type; }
  58. }
  59. public Asn1Encodable Name
  60. {
  61. get { return name; }
  62. }
  63. public DistributionPointName(
  64. Asn1TaggedObject obj)
  65. {
  66. this.type = obj.TagNo;
  67. if (type == FullName)
  68. {
  69. this.name = GeneralNames.GetInstance(obj, false);
  70. }
  71. else
  72. {
  73. this.name = Asn1Set.GetInstance(obj, false);
  74. }
  75. }
  76. public override Asn1Object ToAsn1Object()
  77. {
  78. return new DerTaggedObject(false, type, name);
  79. }
  80. public override string ToString()
  81. {
  82. string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
  83. StringBuilder buf = new StringBuilder();
  84. buf.Append("DistributionPointName: [");
  85. buf.Append(sep);
  86. if (type == FullName)
  87. {
  88. appendObject(buf, sep, "fullName", name.ToString());
  89. }
  90. else
  91. {
  92. appendObject(buf, sep, "nameRelativeToCRLIssuer", name.ToString());
  93. }
  94. buf.Append("]");
  95. buf.Append(sep);
  96. return buf.ToString();
  97. }
  98. private void appendObject(
  99. StringBuilder buf,
  100. string sep,
  101. string name,
  102. string val)
  103. {
  104. string indent = " ";
  105. buf.Append(indent);
  106. buf.Append(name);
  107. buf.Append(":");
  108. buf.Append(sep);
  109. buf.Append(indent);
  110. buf.Append(indent);
  111. buf.Append(val);
  112. buf.Append(sep);
  113. }
  114. }
  115. }
  116. #pragma warning restore
  117. #endif