GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ff3a63...584877 )
by Joni
04:52
created
lib/X509/CertificationPath/Policy/PolicyTree.php 1 patch
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -8,411 +8,411 @@
 block discarded – undo
8 8
 
9 9
 class PolicyTree
10 10
 {
11
-    /**
12
-     * Root node at depth zero.
13
-     *
14
-     * @var PolicyNode|null
15
-     */
16
-    protected $_root;
11
+	/**
12
+	 * Root node at depth zero.
13
+	 *
14
+	 * @var PolicyNode|null
15
+	 */
16
+	protected $_root;
17 17
     
18
-    /**
19
-     * Constructor.
20
-     *
21
-     * @param PolicyNode $root Initial root node
22
-     */
23
-    public function __construct(PolicyNode $root)
24
-    {
25
-        $this->_root = $root;
26
-    }
18
+	/**
19
+	 * Constructor.
20
+	 *
21
+	 * @param PolicyNode $root Initial root node
22
+	 */
23
+	public function __construct(PolicyNode $root)
24
+	{
25
+		$this->_root = $root;
26
+	}
27 27
     
28
-    /**
29
-     * Process policy information from the certificate.
30
-     *
31
-     * Certificate policies extension must be present.
32
-     *
33
-     * @param ValidatorState $state
34
-     * @param Certificate $cert
35
-     * @return ValidatorState
36
-     */
37
-    public function processPolicies(ValidatorState $state, Certificate $cert)
38
-    {
39
-        $policies = $cert->tbsCertificate()
40
-            ->extensions()
41
-            ->certificatePolicies();
42
-        $tree = clone $this;
43
-        // (d.1) for each policy P not equal to anyPolicy
44
-        foreach ($policies as $policy) {
45
-            if ($policy->isAnyPolicy()) {
46
-                $tree->_processAnyPolicy($policy, $cert, $state);
47
-            } else {
48
-                $tree->_processPolicy($policy, $state);
49
-            }
50
-        }
51
-        // if whole tree is pruned
52
-        if (!$tree->_pruneTree($state->index() - 1)) {
53
-            return $state->withoutValidPolicyTree();
54
-        }
55
-        return $state->withValidPolicyTree($tree);
56
-    }
28
+	/**
29
+	 * Process policy information from the certificate.
30
+	 *
31
+	 * Certificate policies extension must be present.
32
+	 *
33
+	 * @param ValidatorState $state
34
+	 * @param Certificate $cert
35
+	 * @return ValidatorState
36
+	 */
37
+	public function processPolicies(ValidatorState $state, Certificate $cert)
38
+	{
39
+		$policies = $cert->tbsCertificate()
40
+			->extensions()
41
+			->certificatePolicies();
42
+		$tree = clone $this;
43
+		// (d.1) for each policy P not equal to anyPolicy
44
+		foreach ($policies as $policy) {
45
+			if ($policy->isAnyPolicy()) {
46
+				$tree->_processAnyPolicy($policy, $cert, $state);
47
+			} else {
48
+				$tree->_processPolicy($policy, $state);
49
+			}
50
+		}
51
+		// if whole tree is pruned
52
+		if (!$tree->_pruneTree($state->index() - 1)) {
53
+			return $state->withoutValidPolicyTree();
54
+		}
55
+		return $state->withValidPolicyTree($tree);
56
+	}
57 57
     
58
-    /**
59
-     * Process policy mappings from the certificate.
60
-     *
61
-     * @param ValidatorState $state
62
-     * @param Certificate $cert
63
-     * @return ValidatorState
64
-     */
65
-    public function processMappings(ValidatorState $state, Certificate $cert)
66
-    {
67
-        $tree = clone $this;
68
-        if ($state->policyMapping() > 0) {
69
-            $tree->_applyMappings($cert, $state);
70
-        } else if ($state->policyMapping() == 0) {
71
-            $tree->_deleteMappings($cert, $state);
72
-        }
73
-        // if whole tree is pruned
74
-        if (!$tree->_root) {
75
-            return $state->withoutValidPolicyTree();
76
-        }
77
-        return $state->withValidPolicyTree($tree);
78
-    }
58
+	/**
59
+	 * Process policy mappings from the certificate.
60
+	 *
61
+	 * @param ValidatorState $state
62
+	 * @param Certificate $cert
63
+	 * @return ValidatorState
64
+	 */
65
+	public function processMappings(ValidatorState $state, Certificate $cert)
66
+	{
67
+		$tree = clone $this;
68
+		if ($state->policyMapping() > 0) {
69
+			$tree->_applyMappings($cert, $state);
70
+		} else if ($state->policyMapping() == 0) {
71
+			$tree->_deleteMappings($cert, $state);
72
+		}
73
+		// if whole tree is pruned
74
+		if (!$tree->_root) {
75
+			return $state->withoutValidPolicyTree();
76
+		}
77
+		return $state->withValidPolicyTree($tree);
78
+	}
79 79
     
80
-    /**
81
-     * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g.
82
-     *
83
-     * @param ValidatorState $state
84
-     * @param array $policies
85
-     * @return ValidatorState
86
-     */
87
-    public function calculateIntersection(ValidatorState $state, array $policies)
88
-    {
89
-        $tree = clone $this;
90
-        $valid_policy_node_set = $tree->_validPolicyNodeSet();
91
-        // 2. If the valid_policy of any node in the valid_policy_node_set
92
-        // is not in the user-initial-policy-set and is not anyPolicy,
93
-        // delete this node and all its children.
94
-        $valid_policy_node_set = array_filter($valid_policy_node_set,
95
-            function (PolicyNode $node) use ($policies) {
96
-                if ($node->isAnyPolicy()) {
97
-                    return true;
98
-                }
99
-                if (in_array($node->validPolicy(), $policies)) {
100
-                    return true;
101
-                }
102
-                $node->remove();
103
-                return false;
104
-            });
105
-        // array of valid policy OIDs
106
-        $valid_policy_set = array_map(
107
-            function (PolicyNode $node) {
108
-                return $node->validPolicy();
109
-            }, $valid_policy_node_set);
110
-        // 3. If the valid_policy_tree includes a node of depth n with
111
-        // the valid_policy anyPolicy and the user-initial-policy-set 
112
-        // is not any-policy
113
-        foreach ($tree->_nodesAtDepth($state->index()) as $node) {
114
-            if ($node->hasParent() && $node->isAnyPolicy()) {
115
-                // a. Set P-Q to the qualifier_set in the node of depth n
116
-                // with valid_policy anyPolicy.
117
-                $pq = $node->qualifiers();
118
-                // b. For each P-OID in the user-initial-policy-set that is not
119
-                // the valid_policy of a node in the valid_policy_node_set,
120
-                // create a child node whose parent is the node of depth n-1
121
-                // with the valid_policy anyPolicy.
122
-                $poids = array_diff($policies, $valid_policy_set);
123
-                foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) {
124
-                    if ($parent->isAnyPolicy()) {
125
-                        // Set the values in the child node as follows: 
126
-                        // set the valid_policy to P-OID, set the qualifier_set
127
-                        // to P-Q, and set the expected_policy_set to {P-OID}.
128
-                        foreach ($poids as $poid) {
129
-                            $parent->addChild(
130
-                                new PolicyNode($poid, $pq, array($poid)));
131
-                        }
132
-                        break;
133
-                    }
134
-                }
135
-                // c. Delete the node of depth n with the
136
-                // valid_policy anyPolicy.
137
-                $node->remove();
138
-            }
139
-        }
140
-        // 4. If there is a node in the valid_policy_tree of depth n-1 or less
141
-        // without any child nodes, delete that node. Repeat this step until
142
-        // there are no nodes of depth n-1 or less without children.
143
-        if (!$tree->_pruneTree($state->index() - 1)) {
144
-            return $state->withoutValidPolicyTree();
145
-        }
146
-        return $state->withValidPolicyTree($tree);
147
-    }
80
+	/**
81
+	 * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g.
82
+	 *
83
+	 * @param ValidatorState $state
84
+	 * @param array $policies
85
+	 * @return ValidatorState
86
+	 */
87
+	public function calculateIntersection(ValidatorState $state, array $policies)
88
+	{
89
+		$tree = clone $this;
90
+		$valid_policy_node_set = $tree->_validPolicyNodeSet();
91
+		// 2. If the valid_policy of any node in the valid_policy_node_set
92
+		// is not in the user-initial-policy-set and is not anyPolicy,
93
+		// delete this node and all its children.
94
+		$valid_policy_node_set = array_filter($valid_policy_node_set,
95
+			function (PolicyNode $node) use ($policies) {
96
+				if ($node->isAnyPolicy()) {
97
+					return true;
98
+				}
99
+				if (in_array($node->validPolicy(), $policies)) {
100
+					return true;
101
+				}
102
+				$node->remove();
103
+				return false;
104
+			});
105
+		// array of valid policy OIDs
106
+		$valid_policy_set = array_map(
107
+			function (PolicyNode $node) {
108
+				return $node->validPolicy();
109
+			}, $valid_policy_node_set);
110
+		// 3. If the valid_policy_tree includes a node of depth n with
111
+		// the valid_policy anyPolicy and the user-initial-policy-set 
112
+		// is not any-policy
113
+		foreach ($tree->_nodesAtDepth($state->index()) as $node) {
114
+			if ($node->hasParent() && $node->isAnyPolicy()) {
115
+				// a. Set P-Q to the qualifier_set in the node of depth n
116
+				// with valid_policy anyPolicy.
117
+				$pq = $node->qualifiers();
118
+				// b. For each P-OID in the user-initial-policy-set that is not
119
+				// the valid_policy of a node in the valid_policy_node_set,
120
+				// create a child node whose parent is the node of depth n-1
121
+				// with the valid_policy anyPolicy.
122
+				$poids = array_diff($policies, $valid_policy_set);
123
+				foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) {
124
+					if ($parent->isAnyPolicy()) {
125
+						// Set the values in the child node as follows: 
126
+						// set the valid_policy to P-OID, set the qualifier_set
127
+						// to P-Q, and set the expected_policy_set to {P-OID}.
128
+						foreach ($poids as $poid) {
129
+							$parent->addChild(
130
+								new PolicyNode($poid, $pq, array($poid)));
131
+						}
132
+						break;
133
+					}
134
+				}
135
+				// c. Delete the node of depth n with the
136
+				// valid_policy anyPolicy.
137
+				$node->remove();
138
+			}
139
+		}
140
+		// 4. If there is a node in the valid_policy_tree of depth n-1 or less
141
+		// without any child nodes, delete that node. Repeat this step until
142
+		// there are no nodes of depth n-1 or less without children.
143
+		if (!$tree->_pruneTree($state->index() - 1)) {
144
+			return $state->withoutValidPolicyTree();
145
+		}
146
+		return $state->withValidPolicyTree($tree);
147
+	}
148 148
     
149
-    /**
150
-     * Get policies at given policy tree depth.
151
-     *
152
-     * @param int $i Depth in range 1..n
153
-     * @return PolicyInformation[]
154
-     */
155
-    public function policiesAtDepth($i)
156
-    {
157
-        $policies = array();
158
-        foreach ($this->_nodesAtDepth($i) as $node) {
159
-            $policies[] = new PolicyInformation($node->validPolicy(),
160
-                ...$node->qualifiers());
161
-        }
162
-        return $policies;
163
-    }
149
+	/**
150
+	 * Get policies at given policy tree depth.
151
+	 *
152
+	 * @param int $i Depth in range 1..n
153
+	 * @return PolicyInformation[]
154
+	 */
155
+	public function policiesAtDepth($i)
156
+	{
157
+		$policies = array();
158
+		foreach ($this->_nodesAtDepth($i) as $node) {
159
+			$policies[] = new PolicyInformation($node->validPolicy(),
160
+				...$node->qualifiers());
161
+		}
162
+		return $policies;
163
+	}
164 164
     
165
-    /**
166
-     * Process single policy information.
167
-     *
168
-     * @param PolicyInformation $policy
169
-     * @param ValidatorState $state
170
-     */
171
-    protected function _processPolicy(PolicyInformation $policy,
172
-        ValidatorState $state)
173
-    {
174
-        $p_oid = $policy->oid();
175
-        $i = $state->index();
176
-        $match_count = 0;
177
-        // (d.1.i) for each node of depth i-1 in the valid_policy_tree...
178
-        foreach ($this->_nodesAtDepth($i - 1) as $node) {
179
-            // ...where P-OID is in the expected_policy_set
180
-            if ($node->hasExpectedPolicy($p_oid)) {
181
-                $node->addChild(
182
-                    new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid)));
183
-                ++$match_count;
184
-            }
185
-        }
186
-        // (d.1.ii) if there was no match in step (i)...
187
-        if (!$match_count) {
188
-            // ...and the valid_policy_tree includes a node of depth i-1 with
189
-            // the valid_policy anyPolicy
190
-            foreach ($this->_nodesAtDepth($i - 1) as $node) {
191
-                if ($node->isAnyPolicy()) {
192
-                    $node->addChild(
193
-                        new PolicyNode($p_oid, $policy->qualifiers(),
194
-                            array($p_oid)));
195
-                }
196
-            }
197
-        }
198
-    }
165
+	/**
166
+	 * Process single policy information.
167
+	 *
168
+	 * @param PolicyInformation $policy
169
+	 * @param ValidatorState $state
170
+	 */
171
+	protected function _processPolicy(PolicyInformation $policy,
172
+		ValidatorState $state)
173
+	{
174
+		$p_oid = $policy->oid();
175
+		$i = $state->index();
176
+		$match_count = 0;
177
+		// (d.1.i) for each node of depth i-1 in the valid_policy_tree...
178
+		foreach ($this->_nodesAtDepth($i - 1) as $node) {
179
+			// ...where P-OID is in the expected_policy_set
180
+			if ($node->hasExpectedPolicy($p_oid)) {
181
+				$node->addChild(
182
+					new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid)));
183
+				++$match_count;
184
+			}
185
+		}
186
+		// (d.1.ii) if there was no match in step (i)...
187
+		if (!$match_count) {
188
+			// ...and the valid_policy_tree includes a node of depth i-1 with
189
+			// the valid_policy anyPolicy
190
+			foreach ($this->_nodesAtDepth($i - 1) as $node) {
191
+				if ($node->isAnyPolicy()) {
192
+					$node->addChild(
193
+						new PolicyNode($p_oid, $policy->qualifiers(),
194
+							array($p_oid)));
195
+				}
196
+			}
197
+		}
198
+	}
199 199
     
200
-    /**
201
-     * Process anyPolicy policy information.
202
-     *
203
-     * @param PolicyInformation $policy
204
-     * @param Certificate $cert
205
-     * @param ValidatorState $state
206
-     */
207
-    protected function _processAnyPolicy(PolicyInformation $policy,
208
-        Certificate $cert, ValidatorState $state)
209
-    {
210
-        $i = $state->index();
211
-        // if (a) inhibit_anyPolicy is greater than 0 or
212
-        // (b) i<n and the certificate is self-issued
213
-        if (!($state->inhibitAnyPolicy() > 0 ||
214
-             ($i < $state->pathLength() && $cert->isSelfIssued()))) {
215
-            return;
216
-        }
217
-        // for each node in the valid_policy_tree of depth i-1
218
-        foreach ($this->_nodesAtDepth($i - 1) as $node) {
219
-            // for each value in the expected_policy_set
220
-            foreach ($node->expectedPolicies() as $p_oid) {
221
-                // that does not appear in a child node
222
-                if (!$node->hasChildWithValidPolicy($p_oid)) {
223
-                    $node->addChild(
224
-                        new PolicyNode($p_oid, $policy->qualifiers(),
225
-                            array($p_oid)));
226
-                }
227
-            }
228
-        }
229
-    }
200
+	/**
201
+	 * Process anyPolicy policy information.
202
+	 *
203
+	 * @param PolicyInformation $policy
204
+	 * @param Certificate $cert
205
+	 * @param ValidatorState $state
206
+	 */
207
+	protected function _processAnyPolicy(PolicyInformation $policy,
208
+		Certificate $cert, ValidatorState $state)
209
+	{
210
+		$i = $state->index();
211
+		// if (a) inhibit_anyPolicy is greater than 0 or
212
+		// (b) i<n and the certificate is self-issued
213
+		if (!($state->inhibitAnyPolicy() > 0 ||
214
+			 ($i < $state->pathLength() && $cert->isSelfIssued()))) {
215
+			return;
216
+		}
217
+		// for each node in the valid_policy_tree of depth i-1
218
+		foreach ($this->_nodesAtDepth($i - 1) as $node) {
219
+			// for each value in the expected_policy_set
220
+			foreach ($node->expectedPolicies() as $p_oid) {
221
+				// that does not appear in a child node
222
+				if (!$node->hasChildWithValidPolicy($p_oid)) {
223
+					$node->addChild(
224
+						new PolicyNode($p_oid, $policy->qualifiers(),
225
+							array($p_oid)));
226
+				}
227
+			}
228
+		}
229
+	}
230 230
     
231
-    /**
232
-     * Apply policy mappings to the policy tree.
233
-     *
234
-     * @param Certificate $cert
235
-     * @param ValidatorState $state
236
-     */
237
-    protected function _applyMappings(Certificate $cert, ValidatorState $state)
238
-    {
239
-        $policy_mappings = $cert->tbsCertificate()
240
-            ->extensions()
241
-            ->policyMappings();
242
-        // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i...
243
-        foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) {
244
-            $match_count = 0;
245
-            foreach ($this->_nodesAtDepth($state->index()) as $node) {
246
-                // ...where ID-P is the valid_policy
247
-                if ($node->validPolicy() == $idp) {
248
-                    // set expected_policy_set to the set of subjectDomainPolicy
249
-                    // values that are specified as equivalent to ID-P by
250
-                    // the policy mappings extension
251
-                    $node->setExpectedPolicies(...$sdps);
252
-                    ++$match_count;
253
-                }
254
-            }
255
-            // if no node of depth i in the valid_policy_tree has
256
-            // a valid_policy of ID-P...
257
-            if (!$match_count) {
258
-                $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps);
259
-            }
260
-        }
261
-    }
231
+	/**
232
+	 * Apply policy mappings to the policy tree.
233
+	 *
234
+	 * @param Certificate $cert
235
+	 * @param ValidatorState $state
236
+	 */
237
+	protected function _applyMappings(Certificate $cert, ValidatorState $state)
238
+	{
239
+		$policy_mappings = $cert->tbsCertificate()
240
+			->extensions()
241
+			->policyMappings();
242
+		// (6.1.4. b.1.) for each node in the valid_policy_tree of depth i...
243
+		foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) {
244
+			$match_count = 0;
245
+			foreach ($this->_nodesAtDepth($state->index()) as $node) {
246
+				// ...where ID-P is the valid_policy
247
+				if ($node->validPolicy() == $idp) {
248
+					// set expected_policy_set to the set of subjectDomainPolicy
249
+					// values that are specified as equivalent to ID-P by
250
+					// the policy mappings extension
251
+					$node->setExpectedPolicies(...$sdps);
252
+					++$match_count;
253
+				}
254
+			}
255
+			// if no node of depth i in the valid_policy_tree has
256
+			// a valid_policy of ID-P...
257
+			if (!$match_count) {
258
+				$this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps);
259
+			}
260
+		}
261
+	}
262 262
     
263
-    /**
264
-     * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1).
265
-     *
266
-     * @param Certificate $cert
267
-     * @param ValidatorState $state
268
-     * @param string $idp OID of the issuer domain policy
269
-     * @param array $sdps Array of subject domain policy OIDs
270
-     */
271
-    protected function _applyAnyPolicyMapping(Certificate $cert,
272
-        ValidatorState $state, $idp, array $sdps)
273
-    {
274
-        // (6.1.4. b.1.) ...but there is a node of depth i with
275
-        // a valid_policy of anyPolicy
276
-        foreach ($this->_nodesAtDepth($state->index()) as $node) {
277
-            if ($node->isAnyPolicy()) {
278
-                // then generate a child node of the node of depth i-1
279
-                // that has a valid_policy of anyPolicy as follows...
280
-                foreach ($this->_nodesAtDepth($state->index() - 1) as $node) {
281
-                    if ($node->isAnyPolicy()) {
282
-                        // try to fetch qualifiers of anyPolicy certificate policy
283
-                        $qualifiers = array();
284
-                        try {
285
-                            $qualifiers = $cert->tbsCertificate()
286
-                                ->extensions()
287
-                                ->certificatePolicies()
288
-                                ->anyPolicy()
289
-                                ->qualifiers();
290
-                        } catch (\LogicException $e) {
291
-                            // if there's no policies or no qualifiers
292
-                        }
293
-                        $node->addChild(
294
-                            new PolicyNode($idp, $qualifiers, $sdps));
295
-                        // bail after first anyPolicy has been processed
296
-                        break;
297
-                    }
298
-                }
299
-                // bail after first anyPolicy has been processed
300
-                break;
301
-            }
302
-        }
303
-    }
263
+	/**
264
+	 * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1).
265
+	 *
266
+	 * @param Certificate $cert
267
+	 * @param ValidatorState $state
268
+	 * @param string $idp OID of the issuer domain policy
269
+	 * @param array $sdps Array of subject domain policy OIDs
270
+	 */
271
+	protected function _applyAnyPolicyMapping(Certificate $cert,
272
+		ValidatorState $state, $idp, array $sdps)
273
+	{
274
+		// (6.1.4. b.1.) ...but there is a node of depth i with
275
+		// a valid_policy of anyPolicy
276
+		foreach ($this->_nodesAtDepth($state->index()) as $node) {
277
+			if ($node->isAnyPolicy()) {
278
+				// then generate a child node of the node of depth i-1
279
+				// that has a valid_policy of anyPolicy as follows...
280
+				foreach ($this->_nodesAtDepth($state->index() - 1) as $node) {
281
+					if ($node->isAnyPolicy()) {
282
+						// try to fetch qualifiers of anyPolicy certificate policy
283
+						$qualifiers = array();
284
+						try {
285
+							$qualifiers = $cert->tbsCertificate()
286
+								->extensions()
287
+								->certificatePolicies()
288
+								->anyPolicy()
289
+								->qualifiers();
290
+						} catch (\LogicException $e) {
291
+							// if there's no policies or no qualifiers
292
+						}
293
+						$node->addChild(
294
+							new PolicyNode($idp, $qualifiers, $sdps));
295
+						// bail after first anyPolicy has been processed
296
+						break;
297
+					}
298
+				}
299
+				// bail after first anyPolicy has been processed
300
+				break;
301
+			}
302
+		}
303
+	}
304 304
     
305
-    /**
306
-     * Delete nodes as specified in 6.1.4 (b)(2).
307
-     *
308
-     * @param Certificate $cert
309
-     * @param ValidatorState $state
310
-     */
311
-    protected function _deleteMappings(Certificate $cert, ValidatorState $state)
312
-    {
313
-        $idps = $cert->tbsCertificate()
314
-            ->extensions()
315
-            ->policyMappings()
316
-            ->issuerDomainPolicies();
317
-        // delete each node of depth i in the valid_policy_tree
318
-        // where ID-P is the valid_policy
319
-        foreach ($this->_nodesAtDepth($state->index()) as $node) {
320
-            if (in_array($node->validPolicy(), $idps)) {
321
-                $node->remove();
322
-            }
323
-        }
324
-        $this->_pruneTree($state->index() - 1);
325
-    }
305
+	/**
306
+	 * Delete nodes as specified in 6.1.4 (b)(2).
307
+	 *
308
+	 * @param Certificate $cert
309
+	 * @param ValidatorState $state
310
+	 */
311
+	protected function _deleteMappings(Certificate $cert, ValidatorState $state)
312
+	{
313
+		$idps = $cert->tbsCertificate()
314
+			->extensions()
315
+			->policyMappings()
316
+			->issuerDomainPolicies();
317
+		// delete each node of depth i in the valid_policy_tree
318
+		// where ID-P is the valid_policy
319
+		foreach ($this->_nodesAtDepth($state->index()) as $node) {
320
+			if (in_array($node->validPolicy(), $idps)) {
321
+				$node->remove();
322
+			}
323
+		}
324
+		$this->_pruneTree($state->index() - 1);
325
+	}
326 326
     
327
-    /**
328
-     * Prune tree starting from given depth.
329
-     *
330
-     * @param int $depth
331
-     * @return int The number of nodes left in a tree
332
-     */
333
-    protected function _pruneTree($depth)
334
-    {
335
-        for ($i = $depth; $i > 0; --$i) {
336
-            foreach ($this->_nodesAtDepth($i) as $node) {
337
-                if (!count($node)) {
338
-                    $node->remove();
339
-                }
340
-            }
341
-        }
342
-        // if root has no children left
343
-        if (!count($this->_root)) {
344
-            $this->_root = null;
345
-            return 0;
346
-        }
347
-        return $this->_root->nodeCount();
348
-    }
327
+	/**
328
+	 * Prune tree starting from given depth.
329
+	 *
330
+	 * @param int $depth
331
+	 * @return int The number of nodes left in a tree
332
+	 */
333
+	protected function _pruneTree($depth)
334
+	{
335
+		for ($i = $depth; $i > 0; --$i) {
336
+			foreach ($this->_nodesAtDepth($i) as $node) {
337
+				if (!count($node)) {
338
+					$node->remove();
339
+				}
340
+			}
341
+		}
342
+		// if root has no children left
343
+		if (!count($this->_root)) {
344
+			$this->_root = null;
345
+			return 0;
346
+		}
347
+		return $this->_root->nodeCount();
348
+	}
349 349
     
350
-    /**
351
-     * Get all nodes at given depth.
352
-     *
353
-     * @param int $i
354
-     * @return PolicyNode[]
355
-     */
356
-    protected function _nodesAtDepth($i)
357
-    {
358
-        if (!$this->_root) {
359
-            return array();
360
-        }
361
-        $depth = 0;
362
-        $nodes = array($this->_root);
363
-        while ($depth < $i) {
364
-            $nodes = self::_gatherChildren(...$nodes);
365
-            if (!count($nodes)) {
366
-                break;
367
-            }
368
-            ++$depth;
369
-        }
370
-        return $nodes;
371
-    }
350
+	/**
351
+	 * Get all nodes at given depth.
352
+	 *
353
+	 * @param int $i
354
+	 * @return PolicyNode[]
355
+	 */
356
+	protected function _nodesAtDepth($i)
357
+	{
358
+		if (!$this->_root) {
359
+			return array();
360
+		}
361
+		$depth = 0;
362
+		$nodes = array($this->_root);
363
+		while ($depth < $i) {
364
+			$nodes = self::_gatherChildren(...$nodes);
365
+			if (!count($nodes)) {
366
+				break;
367
+			}
368
+			++$depth;
369
+		}
370
+		return $nodes;
371
+	}
372 372
     
373
-    /**
374
-     * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1.
375
-     *
376
-     * @return PolicyNode[]
377
-     */
378
-    protected function _validPolicyNodeSet()
379
-    {
380
-        // 1. Determine the set of policy nodes whose parent nodes have
381
-        // a valid_policy of anyPolicy. This is the valid_policy_node_set.
382
-        $set = array();
383
-        if (!$this->_root) {
384
-            return $set;
385
-        }
386
-        // for each node in a tree
387
-        $this->_root->walkNodes(
388
-            function (PolicyNode $node) use (&$set) {
389
-                $parents = $node->parents();
390
-                // node has parents
391
-                if (count($parents)) {
392
-                    // check that each ancestor is an anyPolicy node
393
-                    foreach ($parents as $ancestor) {
394
-                        if (!$ancestor->isAnyPolicy()) {
395
-                            return;
396
-                        }
397
-                    }
398
-                    $set[] = $node;
399
-                }
400
-            });
401
-        return $set;
402
-    }
373
+	/**
374
+	 * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1.
375
+	 *
376
+	 * @return PolicyNode[]
377
+	 */
378
+	protected function _validPolicyNodeSet()
379
+	{
380
+		// 1. Determine the set of policy nodes whose parent nodes have
381
+		// a valid_policy of anyPolicy. This is the valid_policy_node_set.
382
+		$set = array();
383
+		if (!$this->_root) {
384
+			return $set;
385
+		}
386
+		// for each node in a tree
387
+		$this->_root->walkNodes(
388
+			function (PolicyNode $node) use (&$set) {
389
+				$parents = $node->parents();
390
+				// node has parents
391
+				if (count($parents)) {
392
+					// check that each ancestor is an anyPolicy node
393
+					foreach ($parents as $ancestor) {
394
+						if (!$ancestor->isAnyPolicy()) {
395
+							return;
396
+						}
397
+					}
398
+					$set[] = $node;
399
+				}
400
+			});
401
+		return $set;
402
+	}
403 403
     
404
-    /**
405
-     * Gather all children of given nodes to a flattened array.
406
-     *
407
-     * @param PolicyNode ...$nodes
408
-     * @return PolicyNode[]
409
-     */
410
-    private static function _gatherChildren(PolicyNode ...$nodes)
411
-    {
412
-        $children = array();
413
-        foreach ($nodes as $node) {
414
-            $children = array_merge($children, $node->children());
415
-        }
416
-        return $children;
417
-    }
404
+	/**
405
+	 * Gather all children of given nodes to a flattened array.
406
+	 *
407
+	 * @param PolicyNode ...$nodes
408
+	 * @return PolicyNode[]
409
+	 */
410
+	private static function _gatherChildren(PolicyNode ...$nodes)
411
+	{
412
+		$children = array();
413
+		foreach ($nodes as $node) {
414
+			$children = array_merge($children, $node->children());
415
+		}
416
+		return $children;
417
+	}
418 418
 }
Please login to merge, or discard this patch.