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.
Test Failed
Pull Request — master (#1)
by thomas
05:34
created
lib/X509/CertificationPath/PathValidation/PathValidator.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -50,6 +50,7 @@
 block discarded – undo
50 50
      * @param PathValidationConfig $config Validation config
51 51
      * @param Certificate ...$certificates Certificates from the trust anchor to
52 52
      *            the end-entity certificate
53
+     * @param Certificate[] $certificates
53 54
      */
54 55
     public function __construct(Crypto $crypto, PathValidationConfig $config,
55 56
         Certificate ...$certificates)
Please login to merge, or discard this patch.
Indentation   +553 added lines, -553 removed lines patch added patch discarded remove patch
@@ -17,584 +17,584 @@
 block discarded – undo
17 17
  */
18 18
 class PathValidator
19 19
 {
20
-    /**
21
-     * Crypto engine.
22
-     *
23
-     * @var Crypto $_crypto
24
-     */
25
-    protected $_crypto;
20
+	/**
21
+	 * Crypto engine.
22
+	 *
23
+	 * @var Crypto $_crypto
24
+	 */
25
+	protected $_crypto;
26 26
     
27
-    /**
28
-     * Path validation configuration.
29
-     *
30
-     * @var PathValidationConfig $_config
31
-     */
32
-    protected $_config;
27
+	/**
28
+	 * Path validation configuration.
29
+	 *
30
+	 * @var PathValidationConfig $_config
31
+	 */
32
+	protected $_config;
33 33
     
34
-    /**
35
-     * Certification path.
36
-     *
37
-     * @var Certificate[] $_certificates
38
-     */
39
-    protected $_certificates;
34
+	/**
35
+	 * Certification path.
36
+	 *
37
+	 * @var Certificate[] $_certificates
38
+	 */
39
+	protected $_certificates;
40 40
     
41
-    /**
42
-     * Certification path trust anchor.
43
-     *
44
-     * @var Certificate $_trustAnchor
45
-     */
46
-    protected $_trustAnchor;
41
+	/**
42
+	 * Certification path trust anchor.
43
+	 *
44
+	 * @var Certificate $_trustAnchor
45
+	 */
46
+	protected $_trustAnchor;
47 47
     
48
-    /**
49
-     * Constructor.
50
-     *
51
-     * @param Crypto $crypto Crypto engine
52
-     * @param PathValidationConfig $config Validation config
53
-     * @param Certificate ...$certificates Certificates from the trust anchor to
54
-     *            the end-entity certificate
55
-     */
56
-    public function __construct(Crypto $crypto, PathValidationConfig $config,
57
-        Certificate ...$certificates)
58
-    {
59
-        if (!count($certificates)) {
60
-            throw new \LogicException("No certificates.");
61
-        }
62
-        $this->_crypto = $crypto;
63
-        $this->_config = $config;
64
-        $this->_certificates = $certificates;
65
-        // if trust anchor is explicitly given in configuration
66
-        if ($config->hasTrustAnchor()) {
67
-            $this->_trustAnchor = $config->trustAnchor();
68
-        } else {
69
-            $this->_trustAnchor = $certificates[0];
70
-        }
71
-    }
48
+	/**
49
+	 * Constructor.
50
+	 *
51
+	 * @param Crypto $crypto Crypto engine
52
+	 * @param PathValidationConfig $config Validation config
53
+	 * @param Certificate ...$certificates Certificates from the trust anchor to
54
+	 *            the end-entity certificate
55
+	 */
56
+	public function __construct(Crypto $crypto, PathValidationConfig $config,
57
+		Certificate ...$certificates)
58
+	{
59
+		if (!count($certificates)) {
60
+			throw new \LogicException("No certificates.");
61
+		}
62
+		$this->_crypto = $crypto;
63
+		$this->_config = $config;
64
+		$this->_certificates = $certificates;
65
+		// if trust anchor is explicitly given in configuration
66
+		if ($config->hasTrustAnchor()) {
67
+			$this->_trustAnchor = $config->trustAnchor();
68
+		} else {
69
+			$this->_trustAnchor = $certificates[0];
70
+		}
71
+	}
72 72
     
73
-    /**
74
-     * Validate certification path.
75
-     *
76
-     * @throws PathValidationException
77
-     * @return PathValidationResult
78
-     */
79
-    public function validate()
80
-    {
81
-        $n = count($this->_certificates);
82
-        $state = ValidatorState::initialize($this->_config, $this->_trustAnchor,
83
-            $n);
84
-        for ($i = 0; $i < $n; ++$i) {
85
-            $state = $state->withIndex($i + 1);
86
-            $cert = $this->_certificates[$i];
87
-            // process certificate (section 6.1.3.)
88
-            $state = $this->_processCertificate($state, $cert);
89
-            if (!$state->isFinal()) {
90
-                // prepare next certificate (section 6.1.4.)
91
-                $state = $this->_prepareNext($state, $cert);
92
-            }
93
-        }
94
-        if (!isset($cert)) {
95
-            throw new \LogicException("No certificates.");
96
-        }
97
-        // wrap-up (section 6.1.5.)
98
-        $state = $this->_wrapUp($state, $cert);
99
-        // return outputs
100
-        return $state->getResult($this->_certificates);
101
-    }
73
+	/**
74
+	 * Validate certification path.
75
+	 *
76
+	 * @throws PathValidationException
77
+	 * @return PathValidationResult
78
+	 */
79
+	public function validate()
80
+	{
81
+		$n = count($this->_certificates);
82
+		$state = ValidatorState::initialize($this->_config, $this->_trustAnchor,
83
+			$n);
84
+		for ($i = 0; $i < $n; ++$i) {
85
+			$state = $state->withIndex($i + 1);
86
+			$cert = $this->_certificates[$i];
87
+			// process certificate (section 6.1.3.)
88
+			$state = $this->_processCertificate($state, $cert);
89
+			if (!$state->isFinal()) {
90
+				// prepare next certificate (section 6.1.4.)
91
+				$state = $this->_prepareNext($state, $cert);
92
+			}
93
+		}
94
+		if (!isset($cert)) {
95
+			throw new \LogicException("No certificates.");
96
+		}
97
+		// wrap-up (section 6.1.5.)
98
+		$state = $this->_wrapUp($state, $cert);
99
+		// return outputs
100
+		return $state->getResult($this->_certificates);
101
+	}
102 102
     
103
-    /**
104
-     * Apply basic certificate processing according to RFC 5280 section 6.1.3.
105
-     *
106
-     * @link https://tools.ietf.org/html/rfc5280#section-6.1.3
107
-     * @param ValidatorState $state
108
-     * @param Certificate $cert
109
-     * @throws PathValidationException
110
-     * @return ValidatorState
111
-     */
112
-    private function _processCertificate(ValidatorState $state, Certificate $cert)
113
-    {
114
-        // (a.1) verify signature
115
-        $this->_verifySignature($state, $cert);
116
-        // (a.2) check validity period
117
-        $this->_checkValidity($cert);
118
-        // (a.3) check that certificate is not revoked
119
-        $this->_checkRevocation($cert);
120
-        // (a.4) check issuer
121
-        $this->_checkIssuer($state, $cert);
122
-        // (b)(c) if certificate is self-issued and it is not
123
-        // the final certificate in the path, skip this step
124
-        if (!($cert->isSelfIssued() && !$state->isFinal())) {
125
-            // (b) check permitted subtrees
126
-            $this->_checkPermittedSubtrees($state, $cert);
127
-            // (c) check excluded subtrees
128
-            $this->_checkExcludedSubtrees($state, $cert);
129
-        }
130
-        $extensions = $cert->tbsCertificate()->extensions();
131
-        if ($extensions->hasCertificatePolicies()) {
132
-            // (d) process policy information
133
-            if ($state->hasValidPolicyTree()) {
134
-                $state = $state->validPolicyTree()->processPolicies($state,
135
-                    $cert);
136
-            }
137
-        } else {
138
-            // (e) certificate policies extension not present,
139
-            // set the valid_policy_tree to NULL
140
-            $state = $state->withoutValidPolicyTree();
141
-        }
142
-        // (f) check that explicit_policy > 0 or valid_policy_tree is set
143
-        if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
144
-            throw new PathValidationException("No valid policies.");
145
-        }
146
-        return $state;
147
-    }
103
+	/**
104
+	 * Apply basic certificate processing according to RFC 5280 section 6.1.3.
105
+	 *
106
+	 * @link https://tools.ietf.org/html/rfc5280#section-6.1.3
107
+	 * @param ValidatorState $state
108
+	 * @param Certificate $cert
109
+	 * @throws PathValidationException
110
+	 * @return ValidatorState
111
+	 */
112
+	private function _processCertificate(ValidatorState $state, Certificate $cert)
113
+	{
114
+		// (a.1) verify signature
115
+		$this->_verifySignature($state, $cert);
116
+		// (a.2) check validity period
117
+		$this->_checkValidity($cert);
118
+		// (a.3) check that certificate is not revoked
119
+		$this->_checkRevocation($cert);
120
+		// (a.4) check issuer
121
+		$this->_checkIssuer($state, $cert);
122
+		// (b)(c) if certificate is self-issued and it is not
123
+		// the final certificate in the path, skip this step
124
+		if (!($cert->isSelfIssued() && !$state->isFinal())) {
125
+			// (b) check permitted subtrees
126
+			$this->_checkPermittedSubtrees($state, $cert);
127
+			// (c) check excluded subtrees
128
+			$this->_checkExcludedSubtrees($state, $cert);
129
+		}
130
+		$extensions = $cert->tbsCertificate()->extensions();
131
+		if ($extensions->hasCertificatePolicies()) {
132
+			// (d) process policy information
133
+			if ($state->hasValidPolicyTree()) {
134
+				$state = $state->validPolicyTree()->processPolicies($state,
135
+					$cert);
136
+			}
137
+		} else {
138
+			// (e) certificate policies extension not present,
139
+			// set the valid_policy_tree to NULL
140
+			$state = $state->withoutValidPolicyTree();
141
+		}
142
+		// (f) check that explicit_policy > 0 or valid_policy_tree is set
143
+		if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
144
+			throw new PathValidationException("No valid policies.");
145
+		}
146
+		return $state;
147
+	}
148 148
     
149
-    /**
150
-     * Apply preparation for the certificate i+1 according to rfc5280 section
151
-     * 6.1.4.
152
-     *
153
-     * @link https://tools.ietf.org/html/rfc5280#section-6.1.4
154
-     * @param ValidatorState $state
155
-     * @param Certificate $cert
156
-     * @return ValidatorState
157
-     */
158
-    private function _prepareNext(ValidatorState $state, Certificate $cert)
159
-    {
160
-        // (a)(b) if policy mappings extension is present
161
-        $state = $this->_preparePolicyMappings($state, $cert);
162
-        // (c) assign working_issuer_name
163
-        $state = $state->withWorkingIssuerName(
164
-            $cert->tbsCertificate()
165
-                ->subject());
166
-        // (d)(e)(f)
167
-        $state = $this->_setPublicKeyState($state, $cert);
168
-        // (g) if name constraints extension is present
169
-        $state = $this->_prepareNameConstraints($state, $cert);
170
-        // (h) if certificate is not self-issued
171
-        if (!$cert->isSelfIssued()) {
172
-            $state = $this->_prepareNonSelfIssued($state);
173
-        }
174
-        // (i) if policy constraints extension is present
175
-        $state = $this->_preparePolicyConstraints($state, $cert);
176
-        // (j) if inhibit any policy extension is present
177
-        $state = $this->_prepareInhibitAnyPolicy($state, $cert);
178
-        // (k) check basic constraints
179
-        $this->_processBasicContraints($cert);
180
-        // (l) verify max_path_length
181
-        $state = $this->_verifyMaxPathLength($state, $cert);
182
-        // (m) check pathLenContraint
183
-        $state = $this->_processPathLengthContraint($state, $cert);
184
-        // (n) check key usage
185
-        $this->_checkKeyUsage($cert);
186
-        // (o) process relevant extensions
187
-        $state = $this->_processExtensions($state, $cert);
188
-        return $state;
189
-    }
149
+	/**
150
+	 * Apply preparation for the certificate i+1 according to rfc5280 section
151
+	 * 6.1.4.
152
+	 *
153
+	 * @link https://tools.ietf.org/html/rfc5280#section-6.1.4
154
+	 * @param ValidatorState $state
155
+	 * @param Certificate $cert
156
+	 * @return ValidatorState
157
+	 */
158
+	private function _prepareNext(ValidatorState $state, Certificate $cert)
159
+	{
160
+		// (a)(b) if policy mappings extension is present
161
+		$state = $this->_preparePolicyMappings($state, $cert);
162
+		// (c) assign working_issuer_name
163
+		$state = $state->withWorkingIssuerName(
164
+			$cert->tbsCertificate()
165
+				->subject());
166
+		// (d)(e)(f)
167
+		$state = $this->_setPublicKeyState($state, $cert);
168
+		// (g) if name constraints extension is present
169
+		$state = $this->_prepareNameConstraints($state, $cert);
170
+		// (h) if certificate is not self-issued
171
+		if (!$cert->isSelfIssued()) {
172
+			$state = $this->_prepareNonSelfIssued($state);
173
+		}
174
+		// (i) if policy constraints extension is present
175
+		$state = $this->_preparePolicyConstraints($state, $cert);
176
+		// (j) if inhibit any policy extension is present
177
+		$state = $this->_prepareInhibitAnyPolicy($state, $cert);
178
+		// (k) check basic constraints
179
+		$this->_processBasicContraints($cert);
180
+		// (l) verify max_path_length
181
+		$state = $this->_verifyMaxPathLength($state, $cert);
182
+		// (m) check pathLenContraint
183
+		$state = $this->_processPathLengthContraint($state, $cert);
184
+		// (n) check key usage
185
+		$this->_checkKeyUsage($cert);
186
+		// (o) process relevant extensions
187
+		$state = $this->_processExtensions($state, $cert);
188
+		return $state;
189
+	}
190 190
     
191
-    /**
192
-     * Apply wrap-up procedure according to RFC 5280 section 6.1.5.
193
-     *
194
-     * @link https://tools.ietf.org/html/rfc5280#section-6.1.5
195
-     * @param ValidatorState $state
196
-     * @param Certificate $cert
197
-     * @throws PathValidationException
198
-     */
199
-    private function _wrapUp(ValidatorState $state, Certificate $cert)
200
-    {
201
-        $tbs_cert = $cert->tbsCertificate();
202
-        $extensions = $tbs_cert->extensions();
203
-        // (a)
204
-        if ($state->explicitPolicy() > 0) {
205
-            $state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
206
-        }
207
-        // (b)
208
-        if ($extensions->hasPolicyConstraints()) {
209
-            $ext = $extensions->policyConstraints();
210
-            if ($ext->hasRequireExplicitPolicy() &&
211
-                 $ext->requireExplicitPolicy() == 0) {
212
-                $state = $state->withExplicitPolicy(0);
213
-            }
214
-        }
215
-        // (c)(d)(e)
216
-        $state = $this->_setPublicKeyState($state, $cert);
217
-        // (f) process relevant extensions
218
-        $state = $this->_processExtensions($state, $cert);
219
-        // (g) intersection of valid_policy_tree and the initial-policy-set
220
-        $state = $this->_calculatePolicyIntersection($state);
221
-        // check that explicit_policy > 0 or valid_policy_tree is set
222
-        if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
223
-            throw new PathValidationException("No valid policies.");
224
-        }
225
-        // path validation succeeded
226
-        return $state;
227
-    }
191
+	/**
192
+	 * Apply wrap-up procedure according to RFC 5280 section 6.1.5.
193
+	 *
194
+	 * @link https://tools.ietf.org/html/rfc5280#section-6.1.5
195
+	 * @param ValidatorState $state
196
+	 * @param Certificate $cert
197
+	 * @throws PathValidationException
198
+	 */
199
+	private function _wrapUp(ValidatorState $state, Certificate $cert)
200
+	{
201
+		$tbs_cert = $cert->tbsCertificate();
202
+		$extensions = $tbs_cert->extensions();
203
+		// (a)
204
+		if ($state->explicitPolicy() > 0) {
205
+			$state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
206
+		}
207
+		// (b)
208
+		if ($extensions->hasPolicyConstraints()) {
209
+			$ext = $extensions->policyConstraints();
210
+			if ($ext->hasRequireExplicitPolicy() &&
211
+				 $ext->requireExplicitPolicy() == 0) {
212
+				$state = $state->withExplicitPolicy(0);
213
+			}
214
+		}
215
+		// (c)(d)(e)
216
+		$state = $this->_setPublicKeyState($state, $cert);
217
+		// (f) process relevant extensions
218
+		$state = $this->_processExtensions($state, $cert);
219
+		// (g) intersection of valid_policy_tree and the initial-policy-set
220
+		$state = $this->_calculatePolicyIntersection($state);
221
+		// check that explicit_policy > 0 or valid_policy_tree is set
222
+		if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
223
+			throw new PathValidationException("No valid policies.");
224
+		}
225
+		// path validation succeeded
226
+		return $state;
227
+	}
228 228
     
229
-    /**
230
-     * Update working_public_key, working_public_key_parameters and
231
-     * working_public_key_algorithm state variables from certificate.
232
-     *
233
-     * @param ValidatorState $state
234
-     * @param Certificate $cert
235
-     * @return ValidatorState
236
-     */
237
-    private function _setPublicKeyState(ValidatorState $state, Certificate $cert)
238
-    {
239
-        $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo();
240
-        // assign working_public_key
241
-        $state = $state->withWorkingPublicKey($pk_info);
242
-        // assign working_public_key_parameters
243
-        $params = ValidatorState::getAlgorithmParameters(
244
-            $pk_info->algorithmIdentifier());
245
-        if (null !== $params) {
246
-            $state = $state->withWorkingPublicKeyParameters($params);
247
-        } else {
248
-            // if algorithms differ, set parameters to null
249
-            if ($pk_info->algorithmIdentifier()->oid() !==
250
-                 $state->workingPublicKeyAlgorithm()->oid()) {
251
-                $state = $state->withWorkingPublicKeyParameters(null);
252
-            }
253
-        }
254
-        // assign working_public_key_algorithm
255
-        $state = $state->withWorkingPublicKeyAlgorithm(
256
-            $pk_info->algorithmIdentifier());
257
-        return $state;
258
-    }
229
+	/**
230
+	 * Update working_public_key, working_public_key_parameters and
231
+	 * working_public_key_algorithm state variables from certificate.
232
+	 *
233
+	 * @param ValidatorState $state
234
+	 * @param Certificate $cert
235
+	 * @return ValidatorState
236
+	 */
237
+	private function _setPublicKeyState(ValidatorState $state, Certificate $cert)
238
+	{
239
+		$pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo();
240
+		// assign working_public_key
241
+		$state = $state->withWorkingPublicKey($pk_info);
242
+		// assign working_public_key_parameters
243
+		$params = ValidatorState::getAlgorithmParameters(
244
+			$pk_info->algorithmIdentifier());
245
+		if (null !== $params) {
246
+			$state = $state->withWorkingPublicKeyParameters($params);
247
+		} else {
248
+			// if algorithms differ, set parameters to null
249
+			if ($pk_info->algorithmIdentifier()->oid() !==
250
+				 $state->workingPublicKeyAlgorithm()->oid()) {
251
+				$state = $state->withWorkingPublicKeyParameters(null);
252
+			}
253
+		}
254
+		// assign working_public_key_algorithm
255
+		$state = $state->withWorkingPublicKeyAlgorithm(
256
+			$pk_info->algorithmIdentifier());
257
+		return $state;
258
+	}
259 259
     
260
-    /**
261
-     * Verify certificate signature.
262
-     *
263
-     * @param ValidatorState $state
264
-     * @param Certificate $cert
265
-     * @throws PathValidationException
266
-     */
267
-    private function _verifySignature(ValidatorState $state, Certificate $cert)
268
-    {
269
-        try {
270
-            $valid = $cert->verify($state->workingPublicKey(), $this->_crypto);
271
-        } catch (\RuntimeException $e) {
272
-            throw new PathValidationException(
273
-                "Failed to verify signature: " . $e->getMessage(), 0, $e);
274
-        }
275
-        if (!$valid) {
276
-            throw new PathValidationException(
277
-                "Certificate signature doesn't match.");
278
-        }
279
-    }
260
+	/**
261
+	 * Verify certificate signature.
262
+	 *
263
+	 * @param ValidatorState $state
264
+	 * @param Certificate $cert
265
+	 * @throws PathValidationException
266
+	 */
267
+	private function _verifySignature(ValidatorState $state, Certificate $cert)
268
+	{
269
+		try {
270
+			$valid = $cert->verify($state->workingPublicKey(), $this->_crypto);
271
+		} catch (\RuntimeException $e) {
272
+			throw new PathValidationException(
273
+				"Failed to verify signature: " . $e->getMessage(), 0, $e);
274
+		}
275
+		if (!$valid) {
276
+			throw new PathValidationException(
277
+				"Certificate signature doesn't match.");
278
+		}
279
+	}
280 280
     
281
-    /**
282
-     * Check certificate validity.
283
-     *
284
-     * @param Certificate $cert
285
-     * @throws PathValidationException
286
-     */
287
-    private function _checkValidity(Certificate $cert)
288
-    {
289
-        $refdt = $this->_config->dateTime();
290
-        $validity = $cert->tbsCertificate()->validity();
291
-        if ($validity->notBefore()
292
-            ->dateTime()
293
-            ->diff($refdt)->invert) {
294
-            throw new PathValidationException(
295
-                "Certificate validity period has not started.");
296
-        }
297
-        if ($refdt->diff($validity->notAfter()
298
-            ->dateTime())->invert) {
299
-            throw new PathValidationException("Certificate has expired.");
300
-        }
301
-    }
281
+	/**
282
+	 * Check certificate validity.
283
+	 *
284
+	 * @param Certificate $cert
285
+	 * @throws PathValidationException
286
+	 */
287
+	private function _checkValidity(Certificate $cert)
288
+	{
289
+		$refdt = $this->_config->dateTime();
290
+		$validity = $cert->tbsCertificate()->validity();
291
+		if ($validity->notBefore()
292
+			->dateTime()
293
+			->diff($refdt)->invert) {
294
+			throw new PathValidationException(
295
+				"Certificate validity period has not started.");
296
+		}
297
+		if ($refdt->diff($validity->notAfter()
298
+			->dateTime())->invert) {
299
+			throw new PathValidationException("Certificate has expired.");
300
+		}
301
+	}
302 302
     
303
-    /**
304
-     * Check certificate revocation.
305
-     *
306
-     * @param Certificate $cert
307
-     */
308
-    private function _checkRevocation(Certificate $cert)
309
-    {
310
-        // @todo Implement CRL handling
311
-    }
303
+	/**
304
+	 * Check certificate revocation.
305
+	 *
306
+	 * @param Certificate $cert
307
+	 */
308
+	private function _checkRevocation(Certificate $cert)
309
+	{
310
+		// @todo Implement CRL handling
311
+	}
312 312
     
313
-    /**
314
-     * Check certificate issuer.
315
-     *
316
-     * @param ValidatorState $state
317
-     * @param Certificate $cert
318
-     * @throws PathValidationException
319
-     */
320
-    private function _checkIssuer(ValidatorState $state, Certificate $cert)
321
-    {
322
-        if (!$cert->tbsCertificate()
323
-            ->issuer()
324
-            ->equals($state->workingIssuerName())) {
325
-            throw new PathValidationException("Certification issuer mismatch.");
326
-        }
327
-    }
313
+	/**
314
+	 * Check certificate issuer.
315
+	 *
316
+	 * @param ValidatorState $state
317
+	 * @param Certificate $cert
318
+	 * @throws PathValidationException
319
+	 */
320
+	private function _checkIssuer(ValidatorState $state, Certificate $cert)
321
+	{
322
+		if (!$cert->tbsCertificate()
323
+			->issuer()
324
+			->equals($state->workingIssuerName())) {
325
+			throw new PathValidationException("Certification issuer mismatch.");
326
+		}
327
+	}
328 328
     
329
-    /**
330
-     *
331
-     * @param ValidatorState $state
332
-     * @param Certificate $cert
333
-     */
334
-    private function _checkPermittedSubtrees(ValidatorState $state,
335
-        Certificate $cert)
336
-    {
337
-        // @todo Implement
338
-        $state->permittedSubtrees();
339
-    }
329
+	/**
330
+	 *
331
+	 * @param ValidatorState $state
332
+	 * @param Certificate $cert
333
+	 */
334
+	private function _checkPermittedSubtrees(ValidatorState $state,
335
+		Certificate $cert)
336
+	{
337
+		// @todo Implement
338
+		$state->permittedSubtrees();
339
+	}
340 340
     
341
-    /**
342
-     *
343
-     * @param ValidatorState $state
344
-     * @param Certificate $cert
345
-     */
346
-    private function _checkExcludedSubtrees(ValidatorState $state,
347
-        Certificate $cert)
348
-    {
349
-        // @todo Implement
350
-        $state->excludedSubtrees();
351
-    }
341
+	/**
342
+	 *
343
+	 * @param ValidatorState $state
344
+	 * @param Certificate $cert
345
+	 */
346
+	private function _checkExcludedSubtrees(ValidatorState $state,
347
+		Certificate $cert)
348
+	{
349
+		// @todo Implement
350
+		$state->excludedSubtrees();
351
+	}
352 352
     
353
-    /**
354
-     * Apply policy mappings handling for the preparation step.
355
-     *
356
-     * @param ValidatorState $state
357
-     * @param Certificate $cert
358
-     * @throws PathValidationException
359
-     * @return ValidatorState
360
-     */
361
-    private function _preparePolicyMappings(ValidatorState $state,
362
-        Certificate $cert)
363
-    {
364
-        $extensions = $cert->tbsCertificate()->extensions();
365
-        if ($extensions->hasPolicyMappings()) {
366
-            // (a) verify that anyPolicy mapping is not used
367
-            if ($extensions->policyMappings()->hasAnyPolicyMapping()) {
368
-                throw new PathValidationException("anyPolicy mapping found.");
369
-            }
370
-            // (b) process policy mappings
371
-            if ($state->hasValidPolicyTree()) {
372
-                $state = $state->validPolicyTree()->processMappings($state,
373
-                    $cert);
374
-            }
375
-        }
376
-        return $state;
377
-    }
353
+	/**
354
+	 * Apply policy mappings handling for the preparation step.
355
+	 *
356
+	 * @param ValidatorState $state
357
+	 * @param Certificate $cert
358
+	 * @throws PathValidationException
359
+	 * @return ValidatorState
360
+	 */
361
+	private function _preparePolicyMappings(ValidatorState $state,
362
+		Certificate $cert)
363
+	{
364
+		$extensions = $cert->tbsCertificate()->extensions();
365
+		if ($extensions->hasPolicyMappings()) {
366
+			// (a) verify that anyPolicy mapping is not used
367
+			if ($extensions->policyMappings()->hasAnyPolicyMapping()) {
368
+				throw new PathValidationException("anyPolicy mapping found.");
369
+			}
370
+			// (b) process policy mappings
371
+			if ($state->hasValidPolicyTree()) {
372
+				$state = $state->validPolicyTree()->processMappings($state,
373
+					$cert);
374
+			}
375
+		}
376
+		return $state;
377
+	}
378 378
     
379
-    /**
380
-     * Apply name constraints handling for the preparation step.
381
-     *
382
-     * @param ValidatorState $state
383
-     * @param Certificate $cert
384
-     * @return ValidatorState
385
-     */
386
-    private function _prepareNameConstraints(ValidatorState $state,
387
-        Certificate $cert)
388
-    {
389
-        $extensions = $cert->tbsCertificate()->extensions();
390
-        if ($extensions->hasNameConstraints()) {
391
-            $state = $this->_processNameConstraints($state, $cert);
392
-        }
393
-        return $state;
394
-    }
379
+	/**
380
+	 * Apply name constraints handling for the preparation step.
381
+	 *
382
+	 * @param ValidatorState $state
383
+	 * @param Certificate $cert
384
+	 * @return ValidatorState
385
+	 */
386
+	private function _prepareNameConstraints(ValidatorState $state,
387
+		Certificate $cert)
388
+	{
389
+		$extensions = $cert->tbsCertificate()->extensions();
390
+		if ($extensions->hasNameConstraints()) {
391
+			$state = $this->_processNameConstraints($state, $cert);
392
+		}
393
+		return $state;
394
+	}
395 395
     
396
-    /**
397
-     * Apply preparation for a non-self-signed certificate.
398
-     *
399
-     * @param ValidatorState $state
400
-     * @return ValidatorState
401
-     */
402
-    private function _prepareNonSelfIssued(ValidatorState $state)
403
-    {
404
-        // (h.1)
405
-        if ($state->explicitPolicy() > 0) {
406
-            $state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
407
-        }
408
-        // (h.2)
409
-        if ($state->policyMapping() > 0) {
410
-            $state = $state->withPolicyMapping($state->policyMapping() - 1);
411
-        }
412
-        // (h.3)
413
-        if ($state->inhibitAnyPolicy() > 0) {
414
-            $state = $state->withInhibitAnyPolicy(
415
-                $state->inhibitAnyPolicy() - 1);
416
-        }
417
-        return $state;
418
-    }
396
+	/**
397
+	 * Apply preparation for a non-self-signed certificate.
398
+	 *
399
+	 * @param ValidatorState $state
400
+	 * @return ValidatorState
401
+	 */
402
+	private function _prepareNonSelfIssued(ValidatorState $state)
403
+	{
404
+		// (h.1)
405
+		if ($state->explicitPolicy() > 0) {
406
+			$state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
407
+		}
408
+		// (h.2)
409
+		if ($state->policyMapping() > 0) {
410
+			$state = $state->withPolicyMapping($state->policyMapping() - 1);
411
+		}
412
+		// (h.3)
413
+		if ($state->inhibitAnyPolicy() > 0) {
414
+			$state = $state->withInhibitAnyPolicy(
415
+				$state->inhibitAnyPolicy() - 1);
416
+		}
417
+		return $state;
418
+	}
419 419
     
420
-    /**
421
-     * Apply policy constraints handling for the preparation step.
422
-     *
423
-     * @param ValidatorState $state
424
-     * @param Certificate $cert
425
-     * @return ValidatorState
426
-     */
427
-    private function _preparePolicyConstraints(ValidatorState $state,
428
-        Certificate $cert)
429
-    {
430
-        $extensions = $cert->tbsCertificate()->extensions();
431
-        if (!$extensions->hasPolicyConstraints()) {
432
-            return $state;
433
-        }
434
-        $ext = $extensions->policyConstraints();
435
-        // (i.1)
436
-        if ($ext->hasRequireExplicitPolicy() &&
437
-             $ext->requireExplicitPolicy() < $state->explicitPolicy()) {
438
-            $state = $state->withExplicitPolicy($ext->requireExplicitPolicy());
439
-        }
440
-        // (i.2)
441
-        if ($ext->hasInhibitPolicyMapping() &&
442
-             $ext->inhibitPolicyMapping() < $state->policyMapping()) {
443
-            $state = $state->withPolicyMapping($ext->inhibitPolicyMapping());
444
-        }
445
-        return $state;
446
-    }
420
+	/**
421
+	 * Apply policy constraints handling for the preparation step.
422
+	 *
423
+	 * @param ValidatorState $state
424
+	 * @param Certificate $cert
425
+	 * @return ValidatorState
426
+	 */
427
+	private function _preparePolicyConstraints(ValidatorState $state,
428
+		Certificate $cert)
429
+	{
430
+		$extensions = $cert->tbsCertificate()->extensions();
431
+		if (!$extensions->hasPolicyConstraints()) {
432
+			return $state;
433
+		}
434
+		$ext = $extensions->policyConstraints();
435
+		// (i.1)
436
+		if ($ext->hasRequireExplicitPolicy() &&
437
+			 $ext->requireExplicitPolicy() < $state->explicitPolicy()) {
438
+			$state = $state->withExplicitPolicy($ext->requireExplicitPolicy());
439
+		}
440
+		// (i.2)
441
+		if ($ext->hasInhibitPolicyMapping() &&
442
+			 $ext->inhibitPolicyMapping() < $state->policyMapping()) {
443
+			$state = $state->withPolicyMapping($ext->inhibitPolicyMapping());
444
+		}
445
+		return $state;
446
+	}
447 447
     
448
-    /**
449
-     * Apply inhibit any-policy handling for the preparation step.
450
-     *
451
-     * @param ValidatorState $state
452
-     * @param Certificate $cert
453
-     * @return ValidatorState
454
-     */
455
-    private function _prepareInhibitAnyPolicy(ValidatorState $state,
456
-        Certificate $cert)
457
-    {
458
-        $extensions = $cert->tbsCertificate()->extensions();
459
-        if ($extensions->hasInhibitAnyPolicy()) {
460
-            $ext = $extensions->inhibitAnyPolicy();
461
-            if ($ext->skipCerts() < $state->inhibitAnyPolicy()) {
462
-                $state = $state->withInhibitAnyPolicy($ext->skipCerts());
463
-            }
464
-        }
465
-        return $state;
466
-    }
448
+	/**
449
+	 * Apply inhibit any-policy handling for the preparation step.
450
+	 *
451
+	 * @param ValidatorState $state
452
+	 * @param Certificate $cert
453
+	 * @return ValidatorState
454
+	 */
455
+	private function _prepareInhibitAnyPolicy(ValidatorState $state,
456
+		Certificate $cert)
457
+	{
458
+		$extensions = $cert->tbsCertificate()->extensions();
459
+		if ($extensions->hasInhibitAnyPolicy()) {
460
+			$ext = $extensions->inhibitAnyPolicy();
461
+			if ($ext->skipCerts() < $state->inhibitAnyPolicy()) {
462
+				$state = $state->withInhibitAnyPolicy($ext->skipCerts());
463
+			}
464
+		}
465
+		return $state;
466
+	}
467 467
     
468
-    /**
469
-     * Verify maximum certification path length for the preparation step.
470
-     *
471
-     * @param ValidatorState $state
472
-     * @param Certificate $cert
473
-     * @throws PathValidationException
474
-     * @return ValidatorState
475
-     */
476
-    private function _verifyMaxPathLength(ValidatorState $state,
477
-        Certificate $cert): ValidatorState
478
-    {
479
-        if (!$cert->isSelfIssued()) {
480
-            if ($state->maxPathLength() <= 0) {
481
-                throw new PathValidationException(
482
-                    "Certification path length exceeded.");
483
-            }
484
-            $state = $state->withMaxPathLength($state->maxPathLength() - 1);
485
-        }
486
-        return $state;
487
-    }
468
+	/**
469
+	 * Verify maximum certification path length for the preparation step.
470
+	 *
471
+	 * @param ValidatorState $state
472
+	 * @param Certificate $cert
473
+	 * @throws PathValidationException
474
+	 * @return ValidatorState
475
+	 */
476
+	private function _verifyMaxPathLength(ValidatorState $state,
477
+		Certificate $cert): ValidatorState
478
+	{
479
+		if (!$cert->isSelfIssued()) {
480
+			if ($state->maxPathLength() <= 0) {
481
+				throw new PathValidationException(
482
+					"Certification path length exceeded.");
483
+			}
484
+			$state = $state->withMaxPathLength($state->maxPathLength() - 1);
485
+		}
486
+		return $state;
487
+	}
488 488
     
489
-    /**
490
-     * Check key usage extension for the preparation step.
491
-     *
492
-     * @param Certificate $cert
493
-     * @throws PathValidationException
494
-     */
495
-    private function _checkKeyUsage(Certificate $cert)
496
-    {
497
-        $extensions = $cert->tbsCertificate()->extensions();
498
-        if ($extensions->hasKeyUsage()) {
499
-            $ext = $extensions->keyUsage();
500
-            if (!$ext->isKeyCertSign()) {
501
-                throw new PathValidationException("keyCertSign usage not set.");
502
-            }
503
-        }
504
-    }
489
+	/**
490
+	 * Check key usage extension for the preparation step.
491
+	 *
492
+	 * @param Certificate $cert
493
+	 * @throws PathValidationException
494
+	 */
495
+	private function _checkKeyUsage(Certificate $cert)
496
+	{
497
+		$extensions = $cert->tbsCertificate()->extensions();
498
+		if ($extensions->hasKeyUsage()) {
499
+			$ext = $extensions->keyUsage();
500
+			if (!$ext->isKeyCertSign()) {
501
+				throw new PathValidationException("keyCertSign usage not set.");
502
+			}
503
+		}
504
+	}
505 505
     
506
-    /**
507
-     *
508
-     * @param ValidatorState $state
509
-     * @param Certificate $cert
510
-     * @return ValidatorState
511
-     */
512
-    private function _processNameConstraints(ValidatorState $state,
513
-        Certificate $cert): ValidatorState
514
-    {
515
-        // @todo Implement
516
-        return $state;
517
-    }
506
+	/**
507
+	 *
508
+	 * @param ValidatorState $state
509
+	 * @param Certificate $cert
510
+	 * @return ValidatorState
511
+	 */
512
+	private function _processNameConstraints(ValidatorState $state,
513
+		Certificate $cert): ValidatorState
514
+	{
515
+		// @todo Implement
516
+		return $state;
517
+	}
518 518
     
519
-    /**
520
-     * Process basic constraints extension.
521
-     *
522
-     * @param Certificate $cert
523
-     * @throws PathValidationException
524
-     */
525
-    private function _processBasicContraints(Certificate $cert)
526
-    {
527
-        if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) {
528
-            $extensions = $cert->tbsCertificate()->extensions();
529
-            if (!$extensions->hasBasicConstraints()) {
530
-                throw new PathValidationException(
531
-                    "v3 certificate must have basicConstraints extension.");
532
-            }
533
-            // verify that cA is set to TRUE
534
-            if (!$extensions->basicConstraints()->isCA()) {
535
-                throw new PathValidationException(
536
-                    "Certificate is not a CA certificate.");
537
-            }
538
-        }
539
-    }
519
+	/**
520
+	 * Process basic constraints extension.
521
+	 *
522
+	 * @param Certificate $cert
523
+	 * @throws PathValidationException
524
+	 */
525
+	private function _processBasicContraints(Certificate $cert)
526
+	{
527
+		if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) {
528
+			$extensions = $cert->tbsCertificate()->extensions();
529
+			if (!$extensions->hasBasicConstraints()) {
530
+				throw new PathValidationException(
531
+					"v3 certificate must have basicConstraints extension.");
532
+			}
533
+			// verify that cA is set to TRUE
534
+			if (!$extensions->basicConstraints()->isCA()) {
535
+				throw new PathValidationException(
536
+					"Certificate is not a CA certificate.");
537
+			}
538
+		}
539
+	}
540 540
     
541
-    /**
542
-     * Process pathLenConstraint.
543
-     *
544
-     * @param ValidatorState $state
545
-     * @param Certificate $cert
546
-     * @return ValidatorState
547
-     */
548
-    private function _processPathLengthContraint(ValidatorState $state,
549
-        Certificate $cert): ValidatorState
550
-    {
551
-        $extensions = $cert->tbsCertificate()->extensions();
552
-        if ($extensions->hasBasicConstraints()) {
553
-            $ext = $extensions->basicConstraints();
554
-            if ($ext->hasPathLen()) {
555
-                if ($ext->pathLen() < $state->maxPathLength()) {
556
-                    $state = $state->withMaxPathLength($ext->pathLen());
557
-                }
558
-            }
559
-        }
560
-        return $state;
561
-    }
541
+	/**
542
+	 * Process pathLenConstraint.
543
+	 *
544
+	 * @param ValidatorState $state
545
+	 * @param Certificate $cert
546
+	 * @return ValidatorState
547
+	 */
548
+	private function _processPathLengthContraint(ValidatorState $state,
549
+		Certificate $cert): ValidatorState
550
+	{
551
+		$extensions = $cert->tbsCertificate()->extensions();
552
+		if ($extensions->hasBasicConstraints()) {
553
+			$ext = $extensions->basicConstraints();
554
+			if ($ext->hasPathLen()) {
555
+				if ($ext->pathLen() < $state->maxPathLength()) {
556
+					$state = $state->withMaxPathLength($ext->pathLen());
557
+				}
558
+			}
559
+		}
560
+		return $state;
561
+	}
562 562
     
563
-    /**
564
-     *
565
-     * @param ValidatorState $state
566
-     * @param Certificate $cert
567
-     * @return ValidatorState
568
-     */
569
-    private function _processExtensions(ValidatorState $state, Certificate $cert): ValidatorState
570
-    {
571
-        // @todo Implement
572
-        return $state;
573
-    }
563
+	/**
564
+	 *
565
+	 * @param ValidatorState $state
566
+	 * @param Certificate $cert
567
+	 * @return ValidatorState
568
+	 */
569
+	private function _processExtensions(ValidatorState $state, Certificate $cert): ValidatorState
570
+	{
571
+		// @todo Implement
572
+		return $state;
573
+	}
574 574
     
575
-    /**
576
-     *
577
-     * @param ValidatorState $state
578
-     * @return ValidatorState
579
-     */
580
-    private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState
581
-    {
582
-        // (i) If the valid_policy_tree is NULL, the intersection is NULL
583
-        if (!$state->hasValidPolicyTree()) {
584
-            return $state;
585
-        }
586
-        // (ii) If the valid_policy_tree is not NULL and
587
-        // the user-initial-policy-set is any-policy, the intersection
588
-        // is the entire valid_policy_tree
589
-        $initial_policies = $this->_config->policySet();
590
-        if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) {
591
-            return $state;
592
-        }
593
-        // (iii) If the valid_policy_tree is not NULL and the
594
-        // user-initial-policy-set is not any-policy, calculate
595
-        // the intersection of the valid_policy_tree and the
596
-        // user-initial-policy-set as follows
597
-        return $state->validPolicyTree()->calculateIntersection($state,
598
-            $initial_policies);
599
-    }
575
+	/**
576
+	 *
577
+	 * @param ValidatorState $state
578
+	 * @return ValidatorState
579
+	 */
580
+	private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState
581
+	{
582
+		// (i) If the valid_policy_tree is NULL, the intersection is NULL
583
+		if (!$state->hasValidPolicyTree()) {
584
+			return $state;
585
+		}
586
+		// (ii) If the valid_policy_tree is not NULL and
587
+		// the user-initial-policy-set is any-policy, the intersection
588
+		// is the entire valid_policy_tree
589
+		$initial_policies = $this->_config->policySet();
590
+		if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) {
591
+			return $state;
592
+		}
593
+		// (iii) If the valid_policy_tree is not NULL and the
594
+		// user-initial-policy-set is not any-policy, calculate
595
+		// the intersection of the valid_policy_tree and the
596
+		// user-initial-policy-set as follows
597
+		return $state->validPolicyTree()->calculateIntersection($state,
598
+			$initial_policies);
599
+	}
600 600
 }
Please login to merge, or discard this patch.
lib/X509/GeneralName/GeneralName.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,147 +13,147 @@
 block discarded – undo
13 13
  */
14 14
 abstract class GeneralName
15 15
 {
16
-    // GeneralName CHOICE tags
17
-    const TAG_OTHER_NAME = 0;
18
-    const TAG_RFC822_NAME = 1;
19
-    const TAG_DNS_NAME = 2;
20
-    const TAG_X400_ADDRESS = 3;
21
-    const TAG_DIRECTORY_NAME = 4;
22
-    const TAG_EDI_PARTY_NAME = 5;
23
-    const TAG_URI = 6;
24
-    const TAG_IP_ADDRESS = 7;
25
-    const TAG_REGISTERED_ID = 8;
16
+	// GeneralName CHOICE tags
17
+	const TAG_OTHER_NAME = 0;
18
+	const TAG_RFC822_NAME = 1;
19
+	const TAG_DNS_NAME = 2;
20
+	const TAG_X400_ADDRESS = 3;
21
+	const TAG_DIRECTORY_NAME = 4;
22
+	const TAG_EDI_PARTY_NAME = 5;
23
+	const TAG_URI = 6;
24
+	const TAG_IP_ADDRESS = 7;
25
+	const TAG_REGISTERED_ID = 8;
26 26
     
27
-    /**
28
-     * Chosen tag.
29
-     *
30
-     * @var int $_tag
31
-     */
32
-    protected $_tag;
27
+	/**
28
+	 * Chosen tag.
29
+	 *
30
+	 * @var int $_tag
31
+	 */
32
+	protected $_tag;
33 33
     
34
-    /**
35
-     * Get string value of the type.
36
-     *
37
-     * @return string
38
-     */
39
-    abstract public function string();
34
+	/**
35
+	 * Get string value of the type.
36
+	 *
37
+	 * @return string
38
+	 */
39
+	abstract public function string();
40 40
     
41
-    /**
42
-     * Get ASN.1 value in GeneralName CHOICE context.
43
-     *
44
-     * @return TaggedType
45
-     */
46
-    abstract protected function _choiceASN1();
41
+	/**
42
+	 * Get ASN.1 value in GeneralName CHOICE context.
43
+	 *
44
+	 * @return TaggedType
45
+	 */
46
+	abstract protected function _choiceASN1();
47 47
     
48
-    /**
49
-     * Initialize concrete object from the chosen ASN.1 element.
50
-     *
51
-     * @param UnspecifiedType $el
52
-     * @return self
53
-     */
54
-    public static function fromChosenASN1(UnspecifiedType $el)
55
-    {
56
-        throw new \BadMethodCallException(
57
-            __FUNCTION__ . " must be implemented in the derived class.");
58
-    }
48
+	/**
49
+	 * Initialize concrete object from the chosen ASN.1 element.
50
+	 *
51
+	 * @param UnspecifiedType $el
52
+	 * @return self
53
+	 */
54
+	public static function fromChosenASN1(UnspecifiedType $el)
55
+	{
56
+		throw new \BadMethodCallException(
57
+			__FUNCTION__ . " must be implemented in the derived class.");
58
+	}
59 59
     
60
-    /**
61
-     * Initialize from ASN.1.
62
-     *
63
-     * @param TaggedType $el
64
-     * @throws \UnexpectedValueException
65
-     * @return self
66
-     */
67
-    public static function fromASN1(TaggedType $el)
68
-    {
69
-        switch ($el->tag()) {
70
-            // otherName
71
-            case self::TAG_OTHER_NAME:
72
-                return OtherName::fromChosenASN1(
73
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
74
-            // rfc822Name
75
-            case self::TAG_RFC822_NAME:
76
-                return RFC822Name::fromChosenASN1(
77
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
78
-            // dNSName
79
-            case self::TAG_DNS_NAME:
80
-                return DNSName::fromChosenASN1(
81
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
82
-            // x400Address
83
-            case self::TAG_X400_ADDRESS:
84
-                return X400Address::fromChosenASN1(
85
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
86
-            // directoryName
87
-            case self::TAG_DIRECTORY_NAME:
88
-                // because Name is a CHOICE, albeit having only one option,
89
-                // explicit tagging must be used
90
-                // (see X.680 07/2002 30.6.c)
91
-                return DirectoryName::fromChosenASN1($el->asExplicit());
92
-            // ediPartyName
93
-            case self::TAG_EDI_PARTY_NAME:
94
-                return EDIPartyName::fromChosenASN1(
95
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
96
-            // uniformResourceIdentifier
97
-            case self::TAG_URI:
98
-                return UniformResourceIdentifier::fromChosenASN1(
99
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
100
-            // iPAddress
101
-            case self::TAG_IP_ADDRESS:
102
-                return IPAddress::fromChosenASN1(
103
-                    $el->asImplicit(Element::TYPE_OCTET_STRING));
104
-            // registeredID
105
-            case self::TAG_REGISTERED_ID:
106
-                return RegisteredID::fromChosenASN1(
107
-                    $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
108
-        }
109
-        throw new \UnexpectedValueException(
110
-            "GeneralName type " . $el->tag() . " not supported.");
111
-    }
60
+	/**
61
+	 * Initialize from ASN.1.
62
+	 *
63
+	 * @param TaggedType $el
64
+	 * @throws \UnexpectedValueException
65
+	 * @return self
66
+	 */
67
+	public static function fromASN1(TaggedType $el)
68
+	{
69
+		switch ($el->tag()) {
70
+			// otherName
71
+			case self::TAG_OTHER_NAME:
72
+				return OtherName::fromChosenASN1(
73
+					$el->asImplicit(Element::TYPE_SEQUENCE));
74
+			// rfc822Name
75
+			case self::TAG_RFC822_NAME:
76
+				return RFC822Name::fromChosenASN1(
77
+					$el->asImplicit(Element::TYPE_IA5_STRING));
78
+			// dNSName
79
+			case self::TAG_DNS_NAME:
80
+				return DNSName::fromChosenASN1(
81
+					$el->asImplicit(Element::TYPE_IA5_STRING));
82
+			// x400Address
83
+			case self::TAG_X400_ADDRESS:
84
+				return X400Address::fromChosenASN1(
85
+					$el->asImplicit(Element::TYPE_SEQUENCE));
86
+			// directoryName
87
+			case self::TAG_DIRECTORY_NAME:
88
+				// because Name is a CHOICE, albeit having only one option,
89
+				// explicit tagging must be used
90
+				// (see X.680 07/2002 30.6.c)
91
+				return DirectoryName::fromChosenASN1($el->asExplicit());
92
+			// ediPartyName
93
+			case self::TAG_EDI_PARTY_NAME:
94
+				return EDIPartyName::fromChosenASN1(
95
+					$el->asImplicit(Element::TYPE_SEQUENCE));
96
+			// uniformResourceIdentifier
97
+			case self::TAG_URI:
98
+				return UniformResourceIdentifier::fromChosenASN1(
99
+					$el->asImplicit(Element::TYPE_IA5_STRING));
100
+			// iPAddress
101
+			case self::TAG_IP_ADDRESS:
102
+				return IPAddress::fromChosenASN1(
103
+					$el->asImplicit(Element::TYPE_OCTET_STRING));
104
+			// registeredID
105
+			case self::TAG_REGISTERED_ID:
106
+				return RegisteredID::fromChosenASN1(
107
+					$el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
108
+		}
109
+		throw new \UnexpectedValueException(
110
+			"GeneralName type " . $el->tag() . " not supported.");
111
+	}
112 112
     
113
-    /**
114
-     * Get type tag.
115
-     *
116
-     * @return int
117
-     */
118
-    public function tag()
119
-    {
120
-        return $this->_tag;
121
-    }
113
+	/**
114
+	 * Get type tag.
115
+	 *
116
+	 * @return int
117
+	 */
118
+	public function tag()
119
+	{
120
+		return $this->_tag;
121
+	}
122 122
     
123
-    /**
124
-     * Generate ASN.1 element.
125
-     *
126
-     * @return Element
127
-     */
128
-    public function toASN1()
129
-    {
130
-        return $this->_choiceASN1();
131
-    }
123
+	/**
124
+	 * Generate ASN.1 element.
125
+	 *
126
+	 * @return Element
127
+	 */
128
+	public function toASN1()
129
+	{
130
+		return $this->_choiceASN1();
131
+	}
132 132
     
133
-    /**
134
-     * Check whether GeneralName is equal to other.
135
-     *
136
-     * @param GeneralName $other GeneralName to compare to
137
-     * @return boolean True if names are equal
138
-     */
139
-    public function equals(GeneralName $other)
140
-    {
141
-        if ($this->_tag != $other->_tag) {
142
-            return false;
143
-        }
144
-        if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) {
145
-            return false;
146
-        }
147
-        return true;
148
-    }
133
+	/**
134
+	 * Check whether GeneralName is equal to other.
135
+	 *
136
+	 * @param GeneralName $other GeneralName to compare to
137
+	 * @return boolean True if names are equal
138
+	 */
139
+	public function equals(GeneralName $other)
140
+	{
141
+		if ($this->_tag != $other->_tag) {
142
+			return false;
143
+		}
144
+		if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) {
145
+			return false;
146
+		}
147
+		return true;
148
+	}
149 149
     
150
-    /**
151
-     * Get general name as a string.
152
-     *
153
-     * @return string
154
-     */
155
-    public function __toString()
156
-    {
157
-        return $this->string();
158
-    }
150
+	/**
151
+	 * Get general name as a string.
152
+	 *
153
+	 * @return string
154
+	 */
155
+	public function __toString()
156
+	{
157
+		return $this->string();
158
+	}
159 159
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/NameConstraints/GeneralSubtree.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -16,91 +16,91 @@
 block discarded – undo
16 16
  */
17 17
 class GeneralSubtree
18 18
 {
19
-    /**
20
-     * Constraint.
21
-     *
22
-     * @var GeneralName
23
-     */
24
-    protected $_base;
19
+	/**
20
+	 * Constraint.
21
+	 *
22
+	 * @var GeneralName
23
+	 */
24
+	protected $_base;
25 25
     
26
-    /**
27
-     * Not used, must be zero.
28
-     *
29
-     * @var int $_min
30
-     */
31
-    protected $_min;
26
+	/**
27
+	 * Not used, must be zero.
28
+	 *
29
+	 * @var int $_min
30
+	 */
31
+	protected $_min;
32 32
     
33
-    /**
34
-     * Not used, must be null.
35
-     *
36
-     * @var int|null $_max
37
-     */
38
-    protected $_max;
33
+	/**
34
+	 * Not used, must be null.
35
+	 *
36
+	 * @var int|null $_max
37
+	 */
38
+	protected $_max;
39 39
     
40
-    /**
41
-     * Constructor.
42
-     *
43
-     * @param GeneralName $base
44
-     * @param int $min
45
-     * @param int|null $max
46
-     */
47
-    public function __construct(GeneralName $base, $min = 0, $max = null)
48
-    {
49
-        $this->_base = $base;
50
-        $this->_min = $min;
51
-        $this->_max = $max;
52
-    }
40
+	/**
41
+	 * Constructor.
42
+	 *
43
+	 * @param GeneralName $base
44
+	 * @param int $min
45
+	 * @param int|null $max
46
+	 */
47
+	public function __construct(GeneralName $base, $min = 0, $max = null)
48
+	{
49
+		$this->_base = $base;
50
+		$this->_min = $min;
51
+		$this->_max = $max;
52
+	}
53 53
     
54
-    /**
55
-     * Initialize from ASN.1.
56
-     *
57
-     * @param Sequence $seq
58
-     * @return self
59
-     */
60
-    public static function fromASN1(Sequence $seq)
61
-    {
62
-        $base = GeneralName::fromASN1($seq->at(0)->asTagged());
63
-        $min = 0;
64
-        $max = null;
65
-        if ($seq->hasTagged(0)) {
66
-            $min = $seq->getTagged(0)
67
-                ->asImplicit(Element::TYPE_INTEGER)
68
-                ->asInteger()
69
-                ->number();
70
-        }
71
-        if ($seq->hasTagged(1)) {
72
-            $max = $seq->getTagged(1)
73
-                ->asImplicit(Element::TYPE_INTEGER)
74
-                ->asInteger()
75
-                ->number();
76
-        }
77
-        return new self($base, $min, $max);
78
-    }
54
+	/**
55
+	 * Initialize from ASN.1.
56
+	 *
57
+	 * @param Sequence $seq
58
+	 * @return self
59
+	 */
60
+	public static function fromASN1(Sequence $seq)
61
+	{
62
+		$base = GeneralName::fromASN1($seq->at(0)->asTagged());
63
+		$min = 0;
64
+		$max = null;
65
+		if ($seq->hasTagged(0)) {
66
+			$min = $seq->getTagged(0)
67
+				->asImplicit(Element::TYPE_INTEGER)
68
+				->asInteger()
69
+				->number();
70
+		}
71
+		if ($seq->hasTagged(1)) {
72
+			$max = $seq->getTagged(1)
73
+				->asImplicit(Element::TYPE_INTEGER)
74
+				->asInteger()
75
+				->number();
76
+		}
77
+		return new self($base, $min, $max);
78
+	}
79 79
     
80
-    /**
81
-     * Get constraint.
82
-     *
83
-     * @return GeneralName
84
-     */
85
-    public function base()
86
-    {
87
-        return $this->_base;
88
-    }
80
+	/**
81
+	 * Get constraint.
82
+	 *
83
+	 * @return GeneralName
84
+	 */
85
+	public function base()
86
+	{
87
+		return $this->_base;
88
+	}
89 89
     
90
-    /**
91
-     * Generate ASN.1 structure.
92
-     *
93
-     * @return Sequence
94
-     */
95
-    public function toASN1()
96
-    {
97
-        $elements = array($this->_base->toASN1());
98
-        if (isset($this->_min) && $this->_min != 0) {
99
-            $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min));
100
-        }
101
-        if (isset($this->_max)) {
102
-            $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max));
103
-        }
104
-        return new Sequence(...$elements);
105
-    }
90
+	/**
91
+	 * Generate ASN.1 structure.
92
+	 *
93
+	 * @return Sequence
94
+	 */
95
+	public function toASN1()
96
+	{
97
+		$elements = array($this->_base->toASN1());
98
+		if (isset($this->_min) && $this->_min != 0) {
99
+			$elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min));
100
+		}
101
+		if (isset($this->_max)) {
102
+			$elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max));
103
+		}
104
+		return new Sequence(...$elements);
105
+	}
106 106
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/CertificatePolicy/UserNoticeQualifier.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -14,114 +14,114 @@
 block discarded – undo
14 14
  */
15 15
 class UserNoticeQualifier extends PolicyQualifierInfo
16 16
 {
17
-    /**
18
-     * Explicit notice text.
19
-     *
20
-     * @var DisplayText $_text
21
-     */
22
-    protected $_text;
17
+	/**
18
+	 * Explicit notice text.
19
+	 *
20
+	 * @var DisplayText $_text
21
+	 */
22
+	protected $_text;
23 23
     
24
-    /**
25
-     * Notice reference.
26
-     *
27
-     * @var NoticeReference $_ref
28
-     */
29
-    protected $_ref;
24
+	/**
25
+	 * Notice reference.
26
+	 *
27
+	 * @var NoticeReference $_ref
28
+	 */
29
+	protected $_ref;
30 30
     
31
-    /**
32
-     * Constructor.
33
-     *
34
-     * @param DisplayText|null $text
35
-     * @param NoticeReference|null $ref
36
-     */
37
-    public function __construct(DisplayText $text = null, NoticeReference $ref = null)
38
-    {
39
-        $this->_oid = self::OID_UNOTICE;
40
-        $this->_text = $text;
41
-        $this->_ref = $ref;
42
-    }
31
+	/**
32
+	 * Constructor.
33
+	 *
34
+	 * @param DisplayText|null $text
35
+	 * @param NoticeReference|null $ref
36
+	 */
37
+	public function __construct(DisplayText $text = null, NoticeReference $ref = null)
38
+	{
39
+		$this->_oid = self::OID_UNOTICE;
40
+		$this->_text = $text;
41
+		$this->_ref = $ref;
42
+	}
43 43
     
44
-    /**
45
-     *
46
-     * @param UnspecifiedType $el
47
-     * @return self
48
-     */
49
-    public static function fromQualifierASN1(UnspecifiedType $el)
50
-    {
51
-        $seq = $el->asSequence();
52
-        $ref = null;
53
-        $text = null;
54
-        $idx = 0;
55
-        if ($seq->has($idx, Element::TYPE_SEQUENCE)) {
56
-            $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence());
57
-        }
58
-        if ($seq->has($idx, Element::TYPE_STRING)) {
59
-            $text = DisplayText::fromASN1($seq->at($idx)->asString());
60
-        }
61
-        return new self($text, $ref);
62
-    }
44
+	/**
45
+	 *
46
+	 * @param UnspecifiedType $el
47
+	 * @return self
48
+	 */
49
+	public static function fromQualifierASN1(UnspecifiedType $el)
50
+	{
51
+		$seq = $el->asSequence();
52
+		$ref = null;
53
+		$text = null;
54
+		$idx = 0;
55
+		if ($seq->has($idx, Element::TYPE_SEQUENCE)) {
56
+			$ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence());
57
+		}
58
+		if ($seq->has($idx, Element::TYPE_STRING)) {
59
+			$text = DisplayText::fromASN1($seq->at($idx)->asString());
60
+		}
61
+		return new self($text, $ref);
62
+	}
63 63
     
64
-    /**
65
-     * Whether explicit text is present.
66
-     *
67
-     * @return bool
68
-     */
69
-    public function hasExplicitText()
70
-    {
71
-        return isset($this->_text);
72
-    }
64
+	/**
65
+	 * Whether explicit text is present.
66
+	 *
67
+	 * @return bool
68
+	 */
69
+	public function hasExplicitText()
70
+	{
71
+		return isset($this->_text);
72
+	}
73 73
     
74
-    /**
75
-     * Get explicit text.
76
-     *
77
-     * @return DisplayText
78
-     */
79
-    public function explicitText()
80
-    {
81
-        if (!$this->hasExplicitText()) {
82
-            throw new \LogicException("explicitText not set.");
83
-        }
84
-        return $this->_text;
85
-    }
74
+	/**
75
+	 * Get explicit text.
76
+	 *
77
+	 * @return DisplayText
78
+	 */
79
+	public function explicitText()
80
+	{
81
+		if (!$this->hasExplicitText()) {
82
+			throw new \LogicException("explicitText not set.");
83
+		}
84
+		return $this->_text;
85
+	}
86 86
     
87
-    /**
88
-     * Whether notice reference is present.
89
-     *
90
-     * @return bool
91
-     */
92
-    public function hasNoticeRef()
93
-    {
94
-        return isset($this->_ref);
95
-    }
87
+	/**
88
+	 * Whether notice reference is present.
89
+	 *
90
+	 * @return bool
91
+	 */
92
+	public function hasNoticeRef()
93
+	{
94
+		return isset($this->_ref);
95
+	}
96 96
     
97
-    /**
98
-     * Get notice reference.
99
-     *
100
-     * @throws \RuntimeException
101
-     * @return NoticeReference
102
-     */
103
-    public function noticeRef()
104
-    {
105
-        if (!$this->hasNoticeRef()) {
106
-            throw new \LogicException("noticeRef not set.");
107
-        }
108
-        return $this->_ref;
109
-    }
97
+	/**
98
+	 * Get notice reference.
99
+	 *
100
+	 * @throws \RuntimeException
101
+	 * @return NoticeReference
102
+	 */
103
+	public function noticeRef()
104
+	{
105
+		if (!$this->hasNoticeRef()) {
106
+			throw new \LogicException("noticeRef not set.");
107
+		}
108
+		return $this->_ref;
109
+	}
110 110
     
111
-    /**
112
-     *
113
-     * {@inheritdoc}
114
-     * @return Sequence
115
-     */
116
-    protected function _qualifierASN1()
117
-    {
118
-        $elements = array();
119
-        if (isset($this->_ref)) {
120
-            $elements[] = $this->_ref->toASN1();
121
-        }
122
-        if (isset($this->_text)) {
123
-            $elements[] = $this->_text->toASN1();
124
-        }
125
-        return new Sequence(...$elements);
126
-    }
111
+	/**
112
+	 *
113
+	 * {@inheritdoc}
114
+	 * @return Sequence
115
+	 */
116
+	protected function _qualifierASN1()
117
+	{
118
+		$elements = array();
119
+		if (isset($this->_ref)) {
120
+			$elements[] = $this->_ref->toASN1();
121
+		}
122
+		if (isset($this->_text)) {
123
+			$elements[] = $this->_text->toASN1();
124
+		}
125
+		return new Sequence(...$elements);
126
+	}
127 127
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/CertificatePolicy/DisplayText.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -17,93 +17,93 @@
 block discarded – undo
17 17
  */
18 18
 class DisplayText
19 19
 {
20
-    /**
21
-     * Text.
22
-     *
23
-     * @var string $_text
24
-     */
25
-    protected $_text;
20
+	/**
21
+	 * Text.
22
+	 *
23
+	 * @var string $_text
24
+	 */
25
+	protected $_text;
26 26
     
27
-    /**
28
-     * Element tag.
29
-     *
30
-     * @var int $_tag
31
-     */
32
-    protected $_tag;
27
+	/**
28
+	 * Element tag.
29
+	 *
30
+	 * @var int $_tag
31
+	 */
32
+	protected $_tag;
33 33
     
34
-    /**
35
-     * Constructor.
36
-     *
37
-     * @param string $text
38
-     * @param int $tag
39
-     */
40
-    public function __construct($text, $tag)
41
-    {
42
-        $this->_text = $text;
43
-        $this->_tag = $tag;
44
-    }
34
+	/**
35
+	 * Constructor.
36
+	 *
37
+	 * @param string $text
38
+	 * @param int $tag
39
+	 */
40
+	public function __construct($text, $tag)
41
+	{
42
+		$this->_text = $text;
43
+		$this->_tag = $tag;
44
+	}
45 45
     
46
-    /**
47
-     * Initialize from ASN.1.
48
-     *
49
-     * @param StringType $el
50
-     * @return self
51
-     */
52
-    public static function fromASN1(StringType $el)
53
-    {
54
-        return new self($el->string(), $el->tag());
55
-    }
46
+	/**
47
+	 * Initialize from ASN.1.
48
+	 *
49
+	 * @param StringType $el
50
+	 * @return self
51
+	 */
52
+	public static function fromASN1(StringType $el)
53
+	{
54
+		return new self($el->string(), $el->tag());
55
+	}
56 56
     
57
-    /**
58
-     * Initialize from a UTF-8 string.
59
-     *
60
-     * @param string $str
61
-     * @return self
62
-     */
63
-    public static function fromString($str)
64
-    {
65
-        return new self($str, Element::TYPE_UTF8_STRING);
66
-    }
57
+	/**
58
+	 * Initialize from a UTF-8 string.
59
+	 *
60
+	 * @param string $str
61
+	 * @return self
62
+	 */
63
+	public static function fromString($str)
64
+	{
65
+		return new self($str, Element::TYPE_UTF8_STRING);
66
+	}
67 67
     
68
-    /**
69
-     * Get the text.
70
-     *
71
-     * @return string
72
-     */
73
-    public function string()
74
-    {
75
-        return $this->_text;
76
-    }
68
+	/**
69
+	 * Get the text.
70
+	 *
71
+	 * @return string
72
+	 */
73
+	public function string()
74
+	{
75
+		return $this->_text;
76
+	}
77 77
     
78
-    /**
79
-     * Generate ASN.1 element.
80
-     *
81
-     * @throws \UnexpectedValueException
82
-     * @return StringType
83
-     */
84
-    public function toASN1()
85
-    {
86
-        switch ($this->_tag) {
87
-            case Element::TYPE_IA5_STRING:
88
-                return new IA5String($this->_text);
89
-            case Element::TYPE_VISIBLE_STRING:
90
-                return new VisibleString($this->_text);
91
-            case Element::TYPE_BMP_STRING:
92
-                return new BMPString($this->_text);
93
-            case Element::TYPE_UTF8_STRING:
94
-                return new UTF8String($this->_text);
95
-            default:
96
-                throw new \UnexpectedValueException(
97
-                    "Type " . Element::tagToName($this->_tag) . " not supported.");
98
-        }
99
-    }
78
+	/**
79
+	 * Generate ASN.1 element.
80
+	 *
81
+	 * @throws \UnexpectedValueException
82
+	 * @return StringType
83
+	 */
84
+	public function toASN1()
85
+	{
86
+		switch ($this->_tag) {
87
+			case Element::TYPE_IA5_STRING:
88
+				return new IA5String($this->_text);
89
+			case Element::TYPE_VISIBLE_STRING:
90
+				return new VisibleString($this->_text);
91
+			case Element::TYPE_BMP_STRING:
92
+				return new BMPString($this->_text);
93
+			case Element::TYPE_UTF8_STRING:
94
+				return new UTF8String($this->_text);
95
+			default:
96
+				throw new \UnexpectedValueException(
97
+					"Type " . Element::tagToName($this->_tag) . " not supported.");
98
+		}
99
+	}
100 100
     
101
-    /**
102
-     *
103
-     * @return string
104
-     */
105
-    public function __toString()
106
-    {
107
-        return $this->string();
108
-    }
101
+	/**
102
+	 *
103
+	 * @return string
104
+	 */
105
+	public function __toString()
106
+	{
107
+		return $this->string();
108
+	}
109 109
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/TargetGroup.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 class TargetGroup extends Target
15 15
 {
16
-    /**
17
-     * Group name.
18
-     *
19
-     * @var GeneralName $_name
20
-     */
21
-    protected $_name;
16
+	/**
17
+	 * Group name.
18
+	 *
19
+	 * @var GeneralName $_name
20
+	 */
21
+	protected $_name;
22 22
     
23
-    /**
24
-     * Constructor.
25
-     *
26
-     * @param GeneralName $name
27
-     */
28
-    public function __construct(GeneralName $name)
29
-    {
30
-        $this->_name = $name;
31
-        $this->_type = self::TYPE_GROUP;
32
-    }
23
+	/**
24
+	 * Constructor.
25
+	 *
26
+	 * @param GeneralName $name
27
+	 */
28
+	public function __construct(GeneralName $name)
29
+	{
30
+		$this->_name = $name;
31
+		$this->_type = self::TYPE_GROUP;
32
+	}
33 33
     
34
-    /**
35
-     *
36
-     * @param TaggedType $el
37
-     * @return self
38
-     */
39
-    public static function fromChosenASN1(TaggedType $el)
40
-    {
41
-        return new self(GeneralName::fromASN1($el));
42
-    }
34
+	/**
35
+	 *
36
+	 * @param TaggedType $el
37
+	 * @return self
38
+	 */
39
+	public static function fromChosenASN1(TaggedType $el)
40
+	{
41
+		return new self(GeneralName::fromASN1($el));
42
+	}
43 43
     
44
-    /**
45
-     *
46
-     * {@inheritdoc}
47
-     */
48
-    public function string()
49
-    {
50
-        return $this->_name->string();
51
-    }
44
+	/**
45
+	 *
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function string()
49
+	{
50
+		return $this->_name->string();
51
+	}
52 52
     
53
-    /**
54
-     * Get group name.
55
-     *
56
-     * @return GeneralName
57
-     */
58
-    public function name()
59
-    {
60
-        return $this->_name;
61
-    }
53
+	/**
54
+	 * Get group name.
55
+	 *
56
+	 * @return GeneralName
57
+	 */
58
+	public function name()
59
+	{
60
+		return $this->_name;
61
+	}
62 62
     
63
-    /**
64
-     *
65
-     * {@inheritdoc}
66
-     * @return ExplicitlyTaggedType
67
-     */
68
-    public function toASN1()
69
-    {
70
-        return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
-    }
63
+	/**
64
+	 *
65
+	 * {@inheritdoc}
66
+	 * @return ExplicitlyTaggedType
67
+	 */
68
+	public function toASN1()
69
+	{
70
+		return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
+	}
72 72
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/TargetName.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 class TargetName extends Target
15 15
 {
16
-    /**
17
-     * Name.
18
-     *
19
-     * @var GeneralName $_name
20
-     */
21
-    protected $_name;
16
+	/**
17
+	 * Name.
18
+	 *
19
+	 * @var GeneralName $_name
20
+	 */
21
+	protected $_name;
22 22
     
23
-    /**
24
-     * Constructor.
25
-     *
26
-     * @param GeneralName $name
27
-     */
28
-    public function __construct(GeneralName $name)
29
-    {
30
-        $this->_name = $name;
31
-        $this->_type = self::TYPE_NAME;
32
-    }
23
+	/**
24
+	 * Constructor.
25
+	 *
26
+	 * @param GeneralName $name
27
+	 */
28
+	public function __construct(GeneralName $name)
29
+	{
30
+		$this->_name = $name;
31
+		$this->_type = self::TYPE_NAME;
32
+	}
33 33
     
34
-    /**
35
-     *
36
-     * @param TaggedType $el
37
-     * @return self
38
-     */
39
-    public static function fromChosenASN1(TaggedType $el)
40
-    {
41
-        return new self(GeneralName::fromASN1($el));
42
-    }
34
+	/**
35
+	 *
36
+	 * @param TaggedType $el
37
+	 * @return self
38
+	 */
39
+	public static function fromChosenASN1(TaggedType $el)
40
+	{
41
+		return new self(GeneralName::fromASN1($el));
42
+	}
43 43
     
44
-    /**
45
-     *
46
-     * {@inheritdoc}
47
-     */
48
-    public function string()
49
-    {
50
-        return $this->_name->string();
51
-    }
44
+	/**
45
+	 *
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function string()
49
+	{
50
+		return $this->_name->string();
51
+	}
52 52
     
53
-    /**
54
-     * Get name.
55
-     *
56
-     * @return GeneralName
57
-     */
58
-    public function name()
59
-    {
60
-        return $this->_name;
61
-    }
53
+	/**
54
+	 * Get name.
55
+	 *
56
+	 * @return GeneralName
57
+	 */
58
+	public function name()
59
+	{
60
+		return $this->_name;
61
+	}
62 62
     
63
-    /**
64
-     *
65
-     * {@inheritdoc}
66
-     * @return ExplicitlyTaggedType
67
-     */
68
-    public function toASN1()
69
-    {
70
-        return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
-    }
63
+	/**
64
+	 *
65
+	 * {@inheritdoc}
66
+	 * @return ExplicitlyTaggedType
67
+	 */
68
+	public function toASN1()
69
+	{
70
+		return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
+	}
72 72
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/Target.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,89 +11,89 @@
 block discarded – undo
11 11
  */
12 12
 abstract class Target
13 13
 {
14
-    const TYPE_NAME = 0;
15
-    const TYPE_GROUP = 1;
16
-    const TYPE_CERT = 2;
14
+	const TYPE_NAME = 0;
15
+	const TYPE_GROUP = 1;
16
+	const TYPE_CERT = 2;
17 17
     
18
-    /**
19
-     * Type tag.
20
-     *
21
-     * @var int $_type
22
-     */
23
-    protected $_type;
18
+	/**
19
+	 * Type tag.
20
+	 *
21
+	 * @var int $_type
22
+	 */
23
+	protected $_type;
24 24
     
25
-    /**
26
-     * Generate ASN.1 element.
27
-     *
28
-     * @return \ASN1\Element
29
-     */
30
-    abstract public function toASN1();
25
+	/**
26
+	 * Generate ASN.1 element.
27
+	 *
28
+	 * @return \ASN1\Element
29
+	 */
30
+	abstract public function toASN1();
31 31
     
32
-    /**
33
-     * Get string value of the target.
34
-     *
35
-     * @return string
36
-     */
37
-    abstract public function string();
32
+	/**
33
+	 * Get string value of the target.
34
+	 *
35
+	 * @return string
36
+	 */
37
+	abstract public function string();
38 38
     
39
-    /**
40
-     * Initialize concrete object from the chosen ASN.1 element.
41
-     *
42
-     * @param TaggedType $el
43
-     * @return self
44
-     */
45
-    public static function fromChosenASN1(TaggedType $el)
46
-    {
47
-        throw new \BadMethodCallException(
48
-            __FUNCTION__ . " must be implemented in the derived class.");
49
-    }
39
+	/**
40
+	 * Initialize concrete object from the chosen ASN.1 element.
41
+	 *
42
+	 * @param TaggedType $el
43
+	 * @return self
44
+	 */
45
+	public static function fromChosenASN1(TaggedType $el)
46
+	{
47
+		throw new \BadMethodCallException(
48
+			__FUNCTION__ . " must be implemented in the derived class.");
49
+	}
50 50
     
51
-    /**
52
-     * Parse from ASN.1.
53
-     *
54
-     * @param TaggedType $el
55
-     * @throws \UnexpectedValueException
56
-     * @return self
57
-     */
58
-    public static function fromASN1(TaggedType $el)
59
-    {
60
-        switch ($el->tag()) {
61
-            case self::TYPE_NAME:
62
-                return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
-            case self::TYPE_GROUP:
64
-                return TargetGroup::fromChosenASN1(
65
-                    $el->asExplicit()->asTagged());
66
-            case self::TYPE_CERT:
67
-                throw new \RuntimeException("targetCert not supported.");
68
-        }
69
-        throw new \UnexpectedValueException(
70
-            "Target type " . $el->tag() . " not supported.");
71
-    }
51
+	/**
52
+	 * Parse from ASN.1.
53
+	 *
54
+	 * @param TaggedType $el
55
+	 * @throws \UnexpectedValueException
56
+	 * @return self
57
+	 */
58
+	public static function fromASN1(TaggedType $el)
59
+	{
60
+		switch ($el->tag()) {
61
+			case self::TYPE_NAME:
62
+				return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
+			case self::TYPE_GROUP:
64
+				return TargetGroup::fromChosenASN1(
65
+					$el->asExplicit()->asTagged());
66
+			case self::TYPE_CERT:
67
+				throw new \RuntimeException("targetCert not supported.");
68
+		}
69
+		throw new \UnexpectedValueException(
70
+			"Target type " . $el->tag() . " not supported.");
71
+	}
72 72
     
73
-    /**
74
-     * Get type tag.
75
-     *
76
-     * @return int
77
-     */
78
-    public function type()
79
-    {
80
-        return $this->_type;
81
-    }
73
+	/**
74
+	 * Get type tag.
75
+	 *
76
+	 * @return int
77
+	 */
78
+	public function type()
79
+	{
80
+		return $this->_type;
81
+	}
82 82
     
83
-    /**
84
-     * Check whether target is equal to another.
85
-     *
86
-     * @param Target $other
87
-     * @return bool
88
-     */
89
-    public function equals(Target $other)
90
-    {
91
-        if ($this->_type != $other->_type) {
92
-            return false;
93
-        }
94
-        if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) {
95
-            return false;
96
-        }
97
-        return true;
98
-    }
83
+	/**
84
+	 * Check whether target is equal to another.
85
+	 *
86
+	 * @param Target $other
87
+	 * @return bool
88
+	 */
89
+	public function equals(Target $other)
90
+	{
91
+		if ($this->_type != $other->_type) {
92
+			return false;
93
+		}
94
+		if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) {
95
+			return false;
96
+		}
97
+		return true;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/Targets.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -12,131 +12,131 @@
 block discarded – undo
12 12
  */
13 13
 class Targets implements \Countable, \IteratorAggregate
14 14
 {
15
-    /**
16
-     * Target elements.
17
-     *
18
-     * @var Target[] $_targets
19
-     */
20
-    protected $_targets;
15
+	/**
16
+	 * Target elements.
17
+	 *
18
+	 * @var Target[] $_targets
19
+	 */
20
+	protected $_targets;
21 21
     
22
-    /**
23
-     * Constructor.
24
-     *
25
-     * @param Target ...$targets
26
-     */
27
-    public function __construct(Target ...$targets)
28
-    {
29
-        $this->_targets = $targets;
30
-    }
22
+	/**
23
+	 * Constructor.
24
+	 *
25
+	 * @param Target ...$targets
26
+	 */
27
+	public function __construct(Target ...$targets)
28
+	{
29
+		$this->_targets = $targets;
30
+	}
31 31
     
32
-    /**
33
-     * Initialize from ASN.1.
34
-     *
35
-     * @param Sequence $seq
36
-     * @return self
37
-     */
38
-    public static function fromASN1(Sequence $seq)
39
-    {
40
-        $targets = array_map(
41
-            function (UnspecifiedType $el) {
42
-                return Target::fromASN1($el->asTagged());
43
-            }, $seq->elements());
44
-        return new self(...$targets);
45
-    }
32
+	/**
33
+	 * Initialize from ASN.1.
34
+	 *
35
+	 * @param Sequence $seq
36
+	 * @return self
37
+	 */
38
+	public static function fromASN1(Sequence $seq)
39
+	{
40
+		$targets = array_map(
41
+			function (UnspecifiedType $el) {
42
+				return Target::fromASN1($el->asTagged());
43
+			}, $seq->elements());
44
+		return new self(...$targets);
45
+	}
46 46
     
47
-    /**
48
-     * Get all targets.
49
-     *
50
-     * @return Target[]
51
-     */
52
-    public function all()
53
-    {
54
-        return $this->_targets;
55
-    }
47
+	/**
48
+	 * Get all targets.
49
+	 *
50
+	 * @return Target[]
51
+	 */
52
+	public function all()
53
+	{
54
+		return $this->_targets;
55
+	}
56 56
     
57
-    /**
58
-     * Get all targets of given type.
59
-     *
60
-     * @param int $type
61
-     * @return Target[]
62
-     */
63
-    protected function _allOfType($type)
64
-    {
65
-        return array_values(
66
-            array_filter($this->_targets,
67
-                function (Target $target) use ($type) {
68
-                    return $target->type() == $type;
69
-                }));
70
-    }
57
+	/**
58
+	 * Get all targets of given type.
59
+	 *
60
+	 * @param int $type
61
+	 * @return Target[]
62
+	 */
63
+	protected function _allOfType($type)
64
+	{
65
+		return array_values(
66
+			array_filter($this->_targets,
67
+				function (Target $target) use ($type) {
68
+					return $target->type() == $type;
69
+				}));
70
+	}
71 71
     
72
-    /**
73
-     * Get all name targets.
74
-     *
75
-     * @return Target[]
76
-     */
77
-    public function nameTargets()
78
-    {
79
-        return $this->_allOfType(Target::TYPE_NAME);
80
-    }
72
+	/**
73
+	 * Get all name targets.
74
+	 *
75
+	 * @return Target[]
76
+	 */
77
+	public function nameTargets()
78
+	{
79
+		return $this->_allOfType(Target::TYPE_NAME);
80
+	}
81 81
     
82
-    /**
83
-     * Get all group targets.
84
-     *
85
-     * @return Target[]
86
-     */
87
-    public function groupTargets()
88
-    {
89
-        return $this->_allOfType(Target::TYPE_GROUP);
90
-    }
82
+	/**
83
+	 * Get all group targets.
84
+	 *
85
+	 * @return Target[]
86
+	 */
87
+	public function groupTargets()
88
+	{
89
+		return $this->_allOfType(Target::TYPE_GROUP);
90
+	}
91 91
     
92
-    /**
93
-     * Check whether given target is present.
94
-     *
95
-     * @param Target $target
96
-     * @return boolean
97
-     */
98
-    public function hasTarget(Target $target)
99
-    {
100
-        foreach ($this->_allOfType($target->type()) as $t) {
101
-            if ($target->equals($t)) {
102
-                return true;
103
-            }
104
-        }
105
-        return false;
106
-    }
92
+	/**
93
+	 * Check whether given target is present.
94
+	 *
95
+	 * @param Target $target
96
+	 * @return boolean
97
+	 */
98
+	public function hasTarget(Target $target)
99
+	{
100
+		foreach ($this->_allOfType($target->type()) as $t) {
101
+			if ($target->equals($t)) {
102
+				return true;
103
+			}
104
+		}
105
+		return false;
106
+	}
107 107
     
108
-    /**
109
-     * Generate ASN.1 structure.
110
-     *
111
-     * @return Sequence
112
-     */
113
-    public function toASN1()
114
-    {
115
-        $elements = array_map(
116
-            function (Target $target) {
117
-                return $target->toASN1();
118
-            }, $this->_targets);
119
-        return new Sequence(...$elements);
120
-    }
108
+	/**
109
+	 * Generate ASN.1 structure.
110
+	 *
111
+	 * @return Sequence
112
+	 */
113
+	public function toASN1()
114
+	{
115
+		$elements = array_map(
116
+			function (Target $target) {
117
+				return $target->toASN1();
118
+			}, $this->_targets);
119
+		return new Sequence(...$elements);
120
+	}
121 121
     
122
-    /**
123
-     *
124
-     * @see \Countable::count()
125
-     * @return int
126
-     */
127
-    public function count()
128
-    {
129
-        return count($this->_targets);
130
-    }
122
+	/**
123
+	 *
124
+	 * @see \Countable::count()
125
+	 * @return int
126
+	 */
127
+	public function count()
128
+	{
129
+		return count($this->_targets);
130
+	}
131 131
     
132
-    /**
133
-     * Get iterator for targets.
134
-     *
135
-     * @see \IteratorAggregate::getIterator()
136
-     * @return \ArrayIterator
137
-     */
138
-    public function getIterator()
139
-    {
140
-        return new \ArrayIterator($this->_targets);
141
-    }
132
+	/**
133
+	 * Get iterator for targets.
134
+	 *
135
+	 * @see \IteratorAggregate::getIterator()
136
+	 * @return \ArrayIterator
137
+	 */
138
+	public function getIterator()
139
+	{
140
+		return new \ArrayIterator($this->_targets);
141
+	}
142 142
 }
Please login to merge, or discard this patch.