DistributionPointName.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Text;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.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: " + 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. StringBuilder buf = new StringBuilder();
  83. buf.AppendLine("DistributionPointName: [");
  84. if (type == FullName)
  85. {
  86. AppendObject(buf, "fullName", name.ToString());
  87. }
  88. else
  89. {
  90. AppendObject(buf, "nameRelativeToCRLIssuer", name.ToString());
  91. }
  92. buf.AppendLine("]");
  93. return buf.ToString();
  94. }
  95. private void AppendObject(StringBuilder buf, string name, string val)
  96. {
  97. string indent = " ";
  98. buf.Append(indent);
  99. buf.Append(name);
  100. buf.AppendLine(":");
  101. buf.Append(indent);
  102. buf.Append(indent);
  103. buf.Append(val);
  104. buf.AppendLine();
  105. }
  106. }
  107. }
  108. #pragma warning restore
  109. #endif