PkixPolicyNode.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
  9. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Pkix
  10. {
  11. /// <summary>
  12. /// Summary description for PkixPolicyNode.
  13. /// </summary>
  14. public class PkixPolicyNode
  15. // : IPolicyNode
  16. {
  17. protected IList<PkixPolicyNode> mChildren;
  18. protected int mDepth;
  19. protected ISet<string> mExpectedPolicies;
  20. protected PkixPolicyNode mParent;
  21. protected ISet<PolicyQualifierInfo> mPolicyQualifiers;
  22. protected string mValidPolicy;
  23. protected bool mCritical;
  24. public virtual int Depth
  25. {
  26. get { return this.mDepth; }
  27. }
  28. public virtual IEnumerable<PkixPolicyNode> Children
  29. {
  30. get { return CollectionUtilities.Proxy(mChildren); }
  31. }
  32. public virtual bool IsCritical
  33. {
  34. get { return this.mCritical; }
  35. set { this.mCritical = value; }
  36. }
  37. public virtual ISet<PolicyQualifierInfo> PolicyQualifiers
  38. {
  39. get { return new HashSet<PolicyQualifierInfo>(this.mPolicyQualifiers); }
  40. }
  41. public virtual string ValidPolicy
  42. {
  43. get { return this.mValidPolicy; }
  44. }
  45. public virtual bool HasChildren
  46. {
  47. get { return mChildren.Count != 0; }
  48. }
  49. public virtual ISet<string> ExpectedPolicies
  50. {
  51. get { return new HashSet<string>(this.mExpectedPolicies); }
  52. set { this.mExpectedPolicies = new HashSet<string>(value); }
  53. }
  54. public virtual PkixPolicyNode Parent
  55. {
  56. get { return this.mParent; }
  57. set { this.mParent = value; }
  58. }
  59. /// Constructors
  60. public PkixPolicyNode(
  61. IEnumerable<PkixPolicyNode> children,
  62. int depth,
  63. ISet<string> expectedPolicies,
  64. PkixPolicyNode parent,
  65. ISet<PolicyQualifierInfo> policyQualifiers,
  66. string validPolicy,
  67. bool critical)
  68. {
  69. if (children == null)
  70. {
  71. this.mChildren = new List<PkixPolicyNode>();
  72. }
  73. else
  74. {
  75. this.mChildren = new List<PkixPolicyNode>(children);
  76. }
  77. this.mDepth = depth;
  78. this.mExpectedPolicies = expectedPolicies;
  79. this.mParent = parent;
  80. this.mPolicyQualifiers = policyQualifiers;
  81. this.mValidPolicy = validPolicy;
  82. this.mCritical = critical;
  83. }
  84. public virtual void AddChild(
  85. PkixPolicyNode child)
  86. {
  87. child.Parent = this;
  88. mChildren.Add(child);
  89. }
  90. public virtual void RemoveChild(
  91. PkixPolicyNode child)
  92. {
  93. mChildren.Remove(child);
  94. }
  95. public override string ToString()
  96. {
  97. return ToString("");
  98. }
  99. public virtual string ToString(string indent)
  100. {
  101. StringBuilder buf = new StringBuilder();
  102. buf.Append(indent);
  103. buf.Append(mValidPolicy);
  104. buf.AppendLine(" {");
  105. foreach (PkixPolicyNode child in mChildren)
  106. {
  107. buf.Append(child.ToString(indent + " "));
  108. }
  109. buf.Append(indent);
  110. buf.AppendLine("}");
  111. return buf.ToString();
  112. }
  113. public virtual object Clone()
  114. {
  115. return Copy();
  116. }
  117. public virtual PkixPolicyNode Copy()
  118. {
  119. PkixPolicyNode node = new PkixPolicyNode(
  120. new List<PkixPolicyNode>(),
  121. mDepth,
  122. new HashSet<string>(mExpectedPolicies),
  123. null,
  124. new HashSet<PolicyQualifierInfo>(mPolicyQualifiers),
  125. mValidPolicy,
  126. mCritical);
  127. foreach (PkixPolicyNode child in mChildren)
  128. {
  129. PkixPolicyNode copy = child.Copy();
  130. copy.Parent = node;
  131. node.AddChild(copy);
  132. }
  133. return node;
  134. }
  135. }
  136. }
  137. #pragma warning restore
  138. #endif