DistributionPointName.cs 3.0 KB

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