DistributionPoint.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 DistributionPoint object.
  9. * <pre>
  10. * DistributionPoint ::= Sequence {
  11. * distributionPoint [0] DistributionPointName OPTIONAL,
  12. * reasons [1] ReasonFlags OPTIONAL,
  13. * cRLIssuer [2] GeneralNames OPTIONAL
  14. * }
  15. * </pre>
  16. */
  17. public class DistributionPoint
  18. : Asn1Encodable
  19. {
  20. internal readonly DistributionPointName distributionPoint;
  21. internal readonly ReasonFlags reasons;
  22. internal readonly GeneralNames cRLIssuer;
  23. public static DistributionPoint GetInstance(
  24. Asn1TaggedObject obj,
  25. bool explicitly)
  26. {
  27. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  28. }
  29. public static DistributionPoint GetInstance(
  30. object obj)
  31. {
  32. if(obj == null || obj is DistributionPoint)
  33. {
  34. return (DistributionPoint) obj;
  35. }
  36. if(obj is Asn1Sequence)
  37. {
  38. return new DistributionPoint((Asn1Sequence) obj);
  39. }
  40. throw new ArgumentException("Invalid DistributionPoint: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  41. }
  42. private DistributionPoint(
  43. Asn1Sequence seq)
  44. {
  45. for (int i = 0; i != seq.Count; i++)
  46. {
  47. Asn1TaggedObject t = Asn1TaggedObject.GetInstance(seq[i]);
  48. switch (t.TagNo)
  49. {
  50. case 0:
  51. distributionPoint = DistributionPointName.GetInstance(t, true);
  52. break;
  53. case 1:
  54. reasons = new ReasonFlags(DerBitString.GetInstance(t, false));
  55. break;
  56. case 2:
  57. cRLIssuer = GeneralNames.GetInstance(t, false);
  58. break;
  59. }
  60. }
  61. }
  62. public DistributionPoint(
  63. DistributionPointName distributionPointName,
  64. ReasonFlags reasons,
  65. GeneralNames crlIssuer)
  66. {
  67. this.distributionPoint = distributionPointName;
  68. this.reasons = reasons;
  69. this.cRLIssuer = crlIssuer;
  70. }
  71. public DistributionPointName DistributionPointName
  72. {
  73. get { return distributionPoint; }
  74. }
  75. public ReasonFlags Reasons
  76. {
  77. get { return reasons; }
  78. }
  79. public GeneralNames CrlIssuer
  80. {
  81. get { return cRLIssuer; }
  82. }
  83. public override Asn1Object ToAsn1Object()
  84. {
  85. Asn1EncodableVector v = new Asn1EncodableVector();
  86. if (distributionPoint != null)
  87. {
  88. //
  89. // as this is a CHOICE it must be explicitly tagged
  90. //
  91. v.Add(new DerTaggedObject(0, distributionPoint));
  92. }
  93. if (reasons != null)
  94. {
  95. v.Add(new DerTaggedObject(false, 1, reasons));
  96. }
  97. if (cRLIssuer != null)
  98. {
  99. v.Add(new DerTaggedObject(false, 2, cRLIssuer));
  100. }
  101. return new DerSequence(v);
  102. }
  103. public override string ToString()
  104. {
  105. string sep = Org.BouncyCastle.Utilities.Platform.NewLine;
  106. StringBuilder buf = new StringBuilder();
  107. buf.Append("DistributionPoint: [");
  108. buf.Append(sep);
  109. if (distributionPoint != null)
  110. {
  111. appendObject(buf, sep, "distributionPoint", distributionPoint.ToString());
  112. }
  113. if (reasons != null)
  114. {
  115. appendObject(buf, sep, "reasons", reasons.ToString());
  116. }
  117. if (cRLIssuer != null)
  118. {
  119. appendObject(buf, sep, "cRLIssuer", cRLIssuer.ToString());
  120. }
  121. buf.Append("]");
  122. buf.Append(sep);
  123. return buf.ToString();
  124. }
  125. private void appendObject(
  126. StringBuilder buf,
  127. string sep,
  128. string name,
  129. string val)
  130. {
  131. string indent = " ";
  132. buf.Append(indent);
  133. buf.Append(name);
  134. buf.Append(":");
  135. buf.Append(sep);
  136. buf.Append(indent);
  137. buf.Append(indent);
  138. buf.Append(val);
  139. buf.Append(sep);
  140. }
  141. }
  142. }
  143. #endif