summary refs log tree commit diff
path: root/crypto/src/pkix/PkixPolicyNode.cs
blob: 0ea80b25838562ab281299eea7b77b488c72fb4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Text;

using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Collections;

namespace Org.BouncyCastle.Pkix
{
	/// <summary>
	/// Summary description for PkixPolicyNode.
	/// </summary>
	public class PkixPolicyNode
//		: IPolicyNode
	{
		protected IList<PkixPolicyNode> mChildren;
		protected int				mDepth;
		protected ISet<string>		mExpectedPolicies;
		protected PkixPolicyNode	mParent;
		protected ISet<PolicyQualifierInfo> mPolicyQualifiers;
		protected string			mValidPolicy;
		protected bool				mCritical;

		public virtual int Depth
		{
			get { return this.mDepth; }
		}

		public virtual IEnumerable<PkixPolicyNode> Children
		{
			get { return CollectionUtilities.Proxy(mChildren); }
		}

		public virtual bool IsCritical
		{
			get { return this.mCritical; }
			set { this.mCritical = value; }
		}

		public virtual ISet<PolicyQualifierInfo> PolicyQualifiers
		{
			get { return new HashSet<PolicyQualifierInfo>(this.mPolicyQualifiers); }
		}

		public virtual string ValidPolicy
		{
			get { return this.mValidPolicy; }
		}

		public virtual bool HasChildren
		{
			get { return mChildren.Count != 0; }
		}

		public virtual ISet<string> ExpectedPolicies
		{
			get { return new HashSet<string>(this.mExpectedPolicies); }
			set { this.mExpectedPolicies = new HashSet<string>(value); }
		}

		public virtual PkixPolicyNode Parent
		{
			get { return this.mParent; }
			set { this.mParent = value; }
		}

		/// Constructors
		public PkixPolicyNode(
			IEnumerable<PkixPolicyNode> children,
			int				depth,
			ISet<string>	expectedPolicies,
			PkixPolicyNode	parent,
			ISet<PolicyQualifierInfo> policyQualifiers,
			string			validPolicy,
			bool			critical)
		{
            if (children == null)
            {
				this.mChildren = new List<PkixPolicyNode>();
            }
            else
            {
				this.mChildren = new List<PkixPolicyNode>(children);
            }

            this.mDepth = depth;
			this.mExpectedPolicies = expectedPolicies;
			this.mParent = parent;
			this.mPolicyQualifiers = policyQualifiers;
			this.mValidPolicy = validPolicy;
			this.mCritical = critical;
		}

		public virtual void AddChild(
			PkixPolicyNode child)
		{
			child.Parent = this;
			mChildren.Add(child);
		}

		public virtual void RemoveChild(
			PkixPolicyNode child)
		{
			mChildren.Remove(child);
		}

		public override string ToString()
		{
			return ToString("");
		}

		public virtual string ToString(
			string indent)
		{
			StringBuilder buf = new StringBuilder();
			buf.Append(indent);
			buf.Append(mValidPolicy);
			buf.Append(" {");
			buf.Append(Platform.NewLine);

			foreach (PkixPolicyNode child in mChildren)
			{
				buf.Append(child.ToString(indent + "    "));
			}

			buf.Append(indent);
			buf.Append("}");
			buf.Append(Platform.NewLine);
			return buf.ToString();
		}

		public virtual object Clone()
		{
			return Copy();
		}

		public virtual PkixPolicyNode Copy()
		{
			PkixPolicyNode node = new PkixPolicyNode(
				new List<PkixPolicyNode>(),
				mDepth,
				new HashSet<string>(mExpectedPolicies),
				null,
				new HashSet<PolicyQualifierInfo>(mPolicyQualifiers),
				mValidPolicy,
				mCritical);

			foreach (PkixPolicyNode child in mChildren)
			{
				PkixPolicyNode copy = child.Copy();
				copy.Parent = node;
				node.AddChild(copy);
			}

			return node;
		}
	}
}