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
examples/issue-cert.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,27 +25,27 @@
 block discarded – undo
25 25
 $csr = CertificationRequest::fromPEM(PEM::fromFile($argv[2]));
26 26
 // verify CSR
27 27
 if (!$csr->verify()) {
28
-    echo "Failed to verify certification request signature.\n";
29
-    exit(1);
28
+	echo "Failed to verify certification request signature.\n";
29
+	exit(1);
30 30
 }
31 31
 // load CA's private key from PEM
32 32
 $private_key_info = PrivateKeyInfo::fromPEM(
33
-    PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem"));
33
+	PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem"));
34 34
 // initialize certificate from CSR and issuer's certificate
35 35
 $tbs_cert = TBSCertificate::fromCSR($csr)->withIssuerCertificate($issuer_cert);
36 36
 // set random serial number
37 37
 $tbs_cert = $tbs_cert->withRandomSerialNumber();
38 38
 // set validity period
39 39
 $tbs_cert = $tbs_cert->withValidity(
40
-    Validity::fromStrings("now", "now + 3 months"));
40
+	Validity::fromStrings("now", "now + 3 months"));
41 41
 // add extensions
42 42
 $tbs_cert = $tbs_cert->withAdditionalExtensions(
43
-    new KeyUsageExtension(true,
44
-        KeyUsageExtension::DIGITAL_SIGNATURE |
45
-             KeyUsageExtension::KEY_ENCIPHERMENT),
46
-    new BasicConstraintsExtension(true, false));
43
+	new KeyUsageExtension(true,
44
+		KeyUsageExtension::DIGITAL_SIGNATURE |
45
+			 KeyUsageExtension::KEY_ENCIPHERMENT),
46
+	new BasicConstraintsExtension(true, false));
47 47
 // sign certificate with issuer's private key
48 48
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
49
-    $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier());
49
+	$private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier());
50 50
 $cert = $tbs_cert->sign($algo, $private_key_info);
51 51
 echo $cert;
Please login to merge, or discard this patch.
examples/create-csr.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 // load EC private key from PEM
18 18
 $private_key_info = PrivateKeyInfo::fromPEM(
19
-    PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem"));
19
+	PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem"));
20 20
 // extract public key from private key
21 21
 $public_key_info = $private_key_info->publicKeyInfo();
22 22
 // DN of the subject
@@ -25,6 +25,6 @@  discard block
 block discarded – undo
25 25
 $cri = new CertificationRequestInfo($subject, $public_key_info);
26 26
 // sign certificate request with private key
27 27
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
28
-    $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
28
+	$private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
29 29
 $csr = $cri->sign($algo, $private_key_info);
30 30
 echo $csr;
Please login to merge, or discard this patch.
examples/path-validate.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,19 +28,19 @@
 block discarded – undo
28 28
 // build certification path from CA to end-entity certificate
29 29
 $path = CertificationPath::fromTrustAnchorToTarget($ca, $cert);
30 30
 foreach ($path->certificates() as $idx => $cert) {
31
-    printf("#%d: %s\n", $idx,
32
-        $cert->tbsCertificate()
33
-            ->subject()
34
-            ->toString());
31
+	printf("#%d: %s\n", $idx,
32
+		$cert->tbsCertificate()
33
+			->subject()
34
+			->toString());
35 35
 }
36 36
 // validate certification path with default configuration
37 37
 $config = PathValidationConfig::defaultConfig();
38 38
 $result = $path->validate($config);
39 39
 printf("Certificate '%s' is valid.\n",
40
-    $result->certificate()
41
-        ->tbsCertificate()
42
-        ->subject()
43
-        ->toString());
40
+	$result->certificate()
41
+		->tbsCertificate()
42
+		->subject()
43
+		->toString());
44 44
 // remove temporary files
45 45
 unlink($ca_file);
46 46
 unlink($csr_file);
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathValidation/PathValidationConfig.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -12,274 +12,274 @@
 block discarded – undo
12 12
  */
13 13
 class PathValidationConfig
14 14
 {
15
-    /**
16
-     * Maximum allowed certification path length.
17
-     *
18
-     * @var int $_maxLength
19
-     */
20
-    protected $_maxLength;
15
+	/**
16
+	 * Maximum allowed certification path length.
17
+	 *
18
+	 * @var int $_maxLength
19
+	 */
20
+	protected $_maxLength;
21 21
     
22
-    /**
23
-     * Reference time.
24
-     *
25
-     * @var \DateTimeImmutable $_dateTime
26
-     */
27
-    protected $_dateTime;
22
+	/**
23
+	 * Reference time.
24
+	 *
25
+	 * @var \DateTimeImmutable $_dateTime
26
+	 */
27
+	protected $_dateTime;
28 28
     
29
-    /**
30
-     * List of acceptable policy identifiers.
31
-     *
32
-     * @var string[] $_policySet
33
-     */
34
-    protected $_policySet;
29
+	/**
30
+	 * List of acceptable policy identifiers.
31
+	 *
32
+	 * @var string[] $_policySet
33
+	 */
34
+	protected $_policySet;
35 35
     
36
-    /**
37
-     * Trust anchor certificate.
38
-     *
39
-     * If not set, path validation uses the first certificate of the path.
40
-     *
41
-     * @var Certificate|null $_trustAnchor
42
-     */
43
-    protected $_trustAnchor;
36
+	/**
37
+	 * Trust anchor certificate.
38
+	 *
39
+	 * If not set, path validation uses the first certificate of the path.
40
+	 *
41
+	 * @var Certificate|null $_trustAnchor
42
+	 */
43
+	protected $_trustAnchor;
44 44
     
45
-    /**
46
-     * Whether policy mapping in inhibited.
47
-     *
48
-     * Setting this to true disallows policy mapping.
49
-     *
50
-     * @var bool $_policyMappingInhibit
51
-     */
52
-    protected $_policyMappingInhibit;
45
+	/**
46
+	 * Whether policy mapping in inhibited.
47
+	 *
48
+	 * Setting this to true disallows policy mapping.
49
+	 *
50
+	 * @var bool $_policyMappingInhibit
51
+	 */
52
+	protected $_policyMappingInhibit;
53 53
     
54
-    /**
55
-     * Whether the path must be valid for at least one policy in the
56
-     * initial policy set.
57
-     *
58
-     * @var bool $_explicitPolicy
59
-     */
60
-    protected $_explicitPolicy;
54
+	/**
55
+	 * Whether the path must be valid for at least one policy in the
56
+	 * initial policy set.
57
+	 *
58
+	 * @var bool $_explicitPolicy
59
+	 */
60
+	protected $_explicitPolicy;
61 61
     
62
-    /**
63
-     * Whether anyPolicy OID processing should be inhibited.
64
-     *
65
-     * Setting this to true disallows the usage of anyPolicy.
66
-     *
67
-     * @var bool $_anyPolicyInhibit
68
-     */
69
-    protected $_anyPolicyInhibit;
62
+	/**
63
+	 * Whether anyPolicy OID processing should be inhibited.
64
+	 *
65
+	 * Setting this to true disallows the usage of anyPolicy.
66
+	 *
67
+	 * @var bool $_anyPolicyInhibit
68
+	 */
69
+	protected $_anyPolicyInhibit;
70 70
     
71
-    /**
72
-     *
73
-     * @todo Implement
74
-     * @var mixed $_permittedSubtrees
75
-     */
76
-    protected $_permittedSubtrees;
71
+	/**
72
+	 *
73
+	 * @todo Implement
74
+	 * @var mixed $_permittedSubtrees
75
+	 */
76
+	protected $_permittedSubtrees;
77 77
     
78
-    /**
79
-     *
80
-     * @todo Implement
81
-     * @var mixed $_excludedSubtrees
82
-     */
83
-    protected $_excludedSubtrees;
78
+	/**
79
+	 *
80
+	 * @todo Implement
81
+	 * @var mixed $_excludedSubtrees
82
+	 */
83
+	protected $_excludedSubtrees;
84 84
     
85
-    /**
86
-     * Constructor.
87
-     *
88
-     * @param \DateTimeImmutable $dt Reference date and time
89
-     * @param int $max_length Maximum certification path length
90
-     */
91
-    public function __construct(\DateTimeImmutable $dt, $max_length)
92
-    {
93
-        $this->_dateTime = $dt;
94
-        $this->_maxLength = (int) $max_length;
95
-        $this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY);
96
-        $this->_policyMappingInhibit = false;
97
-        $this->_explicitPolicy = false;
98
-        $this->_anyPolicyInhibit = false;
99
-    }
85
+	/**
86
+	 * Constructor.
87
+	 *
88
+	 * @param \DateTimeImmutable $dt Reference date and time
89
+	 * @param int $max_length Maximum certification path length
90
+	 */
91
+	public function __construct(\DateTimeImmutable $dt, $max_length)
92
+	{
93
+		$this->_dateTime = $dt;
94
+		$this->_maxLength = (int) $max_length;
95
+		$this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY);
96
+		$this->_policyMappingInhibit = false;
97
+		$this->_explicitPolicy = false;
98
+		$this->_anyPolicyInhibit = false;
99
+	}
100 100
     
101
-    /**
102
-     * Get default configuration.
103
-     *
104
-     * @return self
105
-     */
106
-    public static function defaultConfig()
107
-    {
108
-        return new self(new \DateTimeImmutable(), 3);
109
-    }
101
+	/**
102
+	 * Get default configuration.
103
+	 *
104
+	 * @return self
105
+	 */
106
+	public static function defaultConfig()
107
+	{
108
+		return new self(new \DateTimeImmutable(), 3);
109
+	}
110 110
     
111
-    /**
112
-     * Get self with maximum path length.
113
-     *
114
-     * @param int $length
115
-     * @return self
116
-     */
117
-    public function withMaxLength($length)
118
-    {
119
-        $obj = clone $this;
120
-        $obj->_maxLength = $length;
121
-        return $obj;
122
-    }
111
+	/**
112
+	 * Get self with maximum path length.
113
+	 *
114
+	 * @param int $length
115
+	 * @return self
116
+	 */
117
+	public function withMaxLength($length)
118
+	{
119
+		$obj = clone $this;
120
+		$obj->_maxLength = $length;
121
+		return $obj;
122
+	}
123 123
     
124
-    /**
125
-     * Get self with reference date and time.
126
-     *
127
-     * @param \DateTimeImmutable $dt
128
-     * @return self
129
-     */
130
-    public function withDateTime(\DateTimeImmutable $dt)
131
-    {
132
-        $obj = clone $this;
133
-        $obj->_dateTime = $dt;
134
-        return $obj;
135
-    }
124
+	/**
125
+	 * Get self with reference date and time.
126
+	 *
127
+	 * @param \DateTimeImmutable $dt
128
+	 * @return self
129
+	 */
130
+	public function withDateTime(\DateTimeImmutable $dt)
131
+	{
132
+		$obj = clone $this;
133
+		$obj->_dateTime = $dt;
134
+		return $obj;
135
+	}
136 136
     
137
-    /**
138
-     * Get self with trust anchor certificate.
139
-     *
140
-     * @param Certificate $ca
141
-     * @return self
142
-     */
143
-    public function withTrustAnchor(Certificate $ca)
144
-    {
145
-        $obj = clone $this;
146
-        $obj->_trustAnchor = $ca;
147
-        return $obj;
148
-    }
137
+	/**
138
+	 * Get self with trust anchor certificate.
139
+	 *
140
+	 * @param Certificate $ca
141
+	 * @return self
142
+	 */
143
+	public function withTrustAnchor(Certificate $ca)
144
+	{
145
+		$obj = clone $this;
146
+		$obj->_trustAnchor = $ca;
147
+		return $obj;
148
+	}
149 149
     
150
-    /**
151
-     * Get self with initial-policy-mapping-inhibit set.
152
-     *
153
-     * @param bool $flag
154
-     * @return self
155
-     */
156
-    public function withPolicyMappingInhibit($flag)
157
-    {
158
-        $obj = clone $this;
159
-        $obj->_policyMappingInhibit = (bool) $flag;
160
-        return $obj;
161
-    }
150
+	/**
151
+	 * Get self with initial-policy-mapping-inhibit set.
152
+	 *
153
+	 * @param bool $flag
154
+	 * @return self
155
+	 */
156
+	public function withPolicyMappingInhibit($flag)
157
+	{
158
+		$obj = clone $this;
159
+		$obj->_policyMappingInhibit = (bool) $flag;
160
+		return $obj;
161
+	}
162 162
     
163
-    /**
164
-     * Get self with initial-explicit-policy set.
165
-     *
166
-     * @param bool $flag
167
-     * @return self
168
-     */
169
-    public function withExplicitPolicy($flag)
170
-    {
171
-        $obj = clone $this;
172
-        $obj->_explicitPolicy = (bool) $flag;
173
-        return $obj;
174
-    }
163
+	/**
164
+	 * Get self with initial-explicit-policy set.
165
+	 *
166
+	 * @param bool $flag
167
+	 * @return self
168
+	 */
169
+	public function withExplicitPolicy($flag)
170
+	{
171
+		$obj = clone $this;
172
+		$obj->_explicitPolicy = (bool) $flag;
173
+		return $obj;
174
+	}
175 175
     
176
-    /**
177
-     * Get self with initial-any-policy-inhibit set.
178
-     *
179
-     * @param bool $flag
180
-     * @return self
181
-     */
182
-    public function withAnyPolicyInhibit($flag)
183
-    {
184
-        $obj = clone $this;
185
-        $obj->_anyPolicyInhibit = (bool) $flag;
186
-        return $obj;
187
-    }
176
+	/**
177
+	 * Get self with initial-any-policy-inhibit set.
178
+	 *
179
+	 * @param bool $flag
180
+	 * @return self
181
+	 */
182
+	public function withAnyPolicyInhibit($flag)
183
+	{
184
+		$obj = clone $this;
185
+		$obj->_anyPolicyInhibit = (bool) $flag;
186
+		return $obj;
187
+	}
188 188
     
189
-    /**
190
-     * Get self with user-initial-policy-set set to policy OIDs.
191
-     *
192
-     * @param string ...$policies List of policy OIDs
193
-     * @return self
194
-     */
195
-    public function withPolicySet(...$policies)
196
-    {
197
-        $obj = clone $this;
198
-        $obj->_policySet = $policies;
199
-        return $obj;
200
-    }
189
+	/**
190
+	 * Get self with user-initial-policy-set set to policy OIDs.
191
+	 *
192
+	 * @param string ...$policies List of policy OIDs
193
+	 * @return self
194
+	 */
195
+	public function withPolicySet(...$policies)
196
+	{
197
+		$obj = clone $this;
198
+		$obj->_policySet = $policies;
199
+		return $obj;
200
+	}
201 201
     
202
-    /**
203
-     * Get maximum certification path length.
204
-     *
205
-     * @return int
206
-     */
207
-    public function maxLength()
208
-    {
209
-        return $this->_maxLength;
210
-    }
202
+	/**
203
+	 * Get maximum certification path length.
204
+	 *
205
+	 * @return int
206
+	 */
207
+	public function maxLength()
208
+	{
209
+		return $this->_maxLength;
210
+	}
211 211
     
212
-    /**
213
-     * Get reference date and time.
214
-     *
215
-     * @return \DateTimeImmutable
216
-     */
217
-    public function dateTime()
218
-    {
219
-        return $this->_dateTime;
220
-    }
212
+	/**
213
+	 * Get reference date and time.
214
+	 *
215
+	 * @return \DateTimeImmutable
216
+	 */
217
+	public function dateTime()
218
+	{
219
+		return $this->_dateTime;
220
+	}
221 221
     
222
-    /**
223
-     * Get user-initial-policy-set.
224
-     *
225
-     * @return string[] Array of OID's
226
-     */
227
-    public function policySet()
228
-    {
229
-        return $this->_policySet;
230
-    }
222
+	/**
223
+	 * Get user-initial-policy-set.
224
+	 *
225
+	 * @return string[] Array of OID's
226
+	 */
227
+	public function policySet()
228
+	{
229
+		return $this->_policySet;
230
+	}
231 231
     
232
-    /**
233
-     * Check whether trust anchor certificate is set.
234
-     *
235
-     * @return bool
236
-     */
237
-    public function hasTrustAnchor()
238
-    {
239
-        return isset($this->_trustAnchor);
240
-    }
232
+	/**
233
+	 * Check whether trust anchor certificate is set.
234
+	 *
235
+	 * @return bool
236
+	 */
237
+	public function hasTrustAnchor()
238
+	{
239
+		return isset($this->_trustAnchor);
240
+	}
241 241
     
242
-    /**
243
-     * Get trust anchor certificate.
244
-     *
245
-     * @throws \LogicException
246
-     * @return Certificate
247
-     */
248
-    public function trustAnchor()
249
-    {
250
-        if (!$this->hasTrustAnchor()) {
251
-            throw new \LogicException("No trust anchor.");
252
-        }
253
-        return $this->_trustAnchor;
254
-    }
242
+	/**
243
+	 * Get trust anchor certificate.
244
+	 *
245
+	 * @throws \LogicException
246
+	 * @return Certificate
247
+	 */
248
+	public function trustAnchor()
249
+	{
250
+		if (!$this->hasTrustAnchor()) {
251
+			throw new \LogicException("No trust anchor.");
252
+		}
253
+		return $this->_trustAnchor;
254
+	}
255 255
     
256
-    /**
257
-     * Get initial-policy-mapping-inhibit.
258
-     *
259
-     * @return bool
260
-     */
261
-    public function policyMappingInhibit()
262
-    {
263
-        return $this->_policyMappingInhibit;
264
-    }
256
+	/**
257
+	 * Get initial-policy-mapping-inhibit.
258
+	 *
259
+	 * @return bool
260
+	 */
261
+	public function policyMappingInhibit()
262
+	{
263
+		return $this->_policyMappingInhibit;
264
+	}
265 265
     
266
-    /**
267
-     * Get initial-explicit-policy.
268
-     *
269
-     * @return bool
270
-     */
271
-    public function explicitPolicy()
272
-    {
273
-        return $this->_explicitPolicy;
274
-    }
266
+	/**
267
+	 * Get initial-explicit-policy.
268
+	 *
269
+	 * @return bool
270
+	 */
271
+	public function explicitPolicy()
272
+	{
273
+		return $this->_explicitPolicy;
274
+	}
275 275
     
276
-    /**
277
-     * Get initial-any-policy-inhibit.
278
-     *
279
-     * @return bool
280
-     */
281
-    public function anyPolicyInhibit()
282
-    {
283
-        return $this->_anyPolicyInhibit;
284
-    }
276
+	/**
277
+	 * Get initial-any-policy-inhibit.
278
+	 *
279
+	 * @return bool
280
+	 */
281
+	public function anyPolicyInhibit()
282
+	{
283
+		return $this->_anyPolicyInhibit;
284
+	}
285 285
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\CertificationPath\PathValidation;
6 6
 
Please login to merge, or discard this patch.
lib/X509/Exception/X509ValidationException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\Exception;
6 6
 
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/Attributes.php 2 patches
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -26,200 +26,200 @@
 block discarded – undo
26 26
  */
27 27
 class Attributes implements \Countable, \IteratorAggregate
28 28
 {
29
-    use AttributeContainer;
30
-    
31
-    /**
32
-     * Mapping from OID to attribute value class name.
33
-     *
34
-     * @internal
35
-     *
36
-     * @var array
37
-     */
38
-    const MAP_OID_TO_CLASS = array(
39
-        /* @formatter:off */
40
-        AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
41
-        AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
42
-        ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
43
-        GroupAttributeValue::OID => GroupAttributeValue::class,
44
-        AttributeType::OID_ROLE => RoleAttributeValue::class
45
-        /* @formatter:on */
46
-    );
47
-    
48
-    /**
49
-     * Constructor.
50
-     *
51
-     * @param Attribute[] $attribs
52
-     */
53
-    public function __construct(Attribute ...$attribs)
54
-    {
55
-        $this->_attributes = $attribs;
56
-    }
57
-    
58
-    /**
59
-     * Initialize from attribute values.
60
-     *
61
-     * @param AttributeValue[] $values
62
-     * @return self
63
-     */
64
-    public static function fromAttributeValues(AttributeValue ...$values)
65
-    {
66
-        $attribs = array_map(
67
-            function (AttributeValue $value) {
68
-                return $value->toAttribute();
69
-            }, $values);
70
-        return new self(...$attribs);
71
-    }
72
-    
73
-    /**
74
-     * Initialize from ASN.1.
75
-     *
76
-     * @param Sequence $seq
77
-     * @return self
78
-     */
79
-    public static function fromASN1(Sequence $seq)
80
-    {
81
-        $attribs = array_map(
82
-            function (UnspecifiedType $el) {
83
-                return Attribute::fromASN1($el->asSequence());
84
-            }, $seq->elements());
85
-        // cast attributes
86
-        $attribs = array_map(
87
-            function (Attribute $attr) {
88
-                $oid = $attr->oid();
89
-                if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
90
-                    $cls = self::MAP_OID_TO_CLASS[$oid];
91
-                    $attr = $attr->castValues($cls);
92
-                }
93
-                return $attr;
94
-            }, $attribs);
95
-        return new self(...$attribs);
96
-    }
97
-    
98
-    /**
99
-     * Check whether 'Access Identity' attribute is present.
100
-     *
101
-     * @return bool
102
-     */
103
-    public function hasAccessIdentity(): bool
104
-    {
105
-        return $this->has(AccessIdentityAttributeValue::OID);
106
-    }
107
-    
108
-    /**
109
-     * Get the first 'Access Identity' attribute value.
110
-     *
111
-     * @return AccessIdentityAttributeValue
112
-     */
113
-    public function accessIdentity(): AccessIdentityAttributeValue
114
-    {
115
-        return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
116
-    }
117
-    
118
-    /**
119
-     * Check whether 'Service Authentication Information' attribute is present.
120
-     *
121
-     * @return bool
122
-     */
123
-    public function hasAuthenticationInformation(): bool
124
-    {
125
-        return $this->has(AuthenticationInfoAttributeValue::OID);
126
-    }
127
-    
128
-    /**
129
-     * Get the first 'Service Authentication Information' attribute value.
130
-     *
131
-     * @return AuthenticationInfoAttributeValue
132
-     */
133
-    public function authenticationInformation(): AuthenticationInfoAttributeValue
134
-    {
135
-        return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
136
-    }
137
-    
138
-    /**
139
-     * Check whether 'Charging Identity' attribute is present.
140
-     *
141
-     * @return bool
142
-     */
143
-    public function hasChargingIdentity(): bool
144
-    {
145
-        return $this->has(ChargingIdentityAttributeValue::OID);
146
-    }
147
-    
148
-    /**
149
-     * Get the first 'Charging Identity' attribute value.
150
-     *
151
-     * @return ChargingIdentityAttributeValue
152
-     */
153
-    public function chargingIdentity(): ChargingIdentityAttributeValue
154
-    {
155
-        return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
156
-    }
157
-    
158
-    /**
159
-     * Check whether 'Group' attribute is present.
160
-     *
161
-     * @return bool
162
-     */
163
-    public function hasGroup(): bool
164
-    {
165
-        return $this->has(GroupAttributeValue::OID);
166
-    }
167
-    
168
-    /**
169
-     * Get the first 'Group' attribute value.
170
-     *
171
-     * @return GroupAttributeValue
172
-     */
173
-    public function group(): GroupAttributeValue
174
-    {
175
-        return $this->firstOf(GroupAttributeValue::OID)->first();
176
-    }
177
-    
178
-    /**
179
-     * Check whether 'Role' attribute is present.
180
-     *
181
-     * @return bool
182
-     */
183
-    public function hasRole(): bool
184
-    {
185
-        return $this->has(AttributeType::OID_ROLE);
186
-    }
187
-    
188
-    /**
189
-     * Get the first 'Role' attribute value.
190
-     *
191
-     * @return RoleAttributeValue
192
-     */
193
-    public function role(): RoleAttributeValue
194
-    {
195
-        return $this->firstOf(AttributeType::OID_ROLE)->first();
196
-    }
197
-    
198
-    /**
199
-     * Get all 'Role' attribute values.
200
-     *
201
-     * @return RoleAttributeValue[]
202
-     */
203
-    public function roles(): array
204
-    {
205
-        return array_merge(array(),
206
-            ...array_map(
207
-                function (Attribute $attr) {
208
-                    return $attr->values();
209
-                }, $this->allOf(AttributeType::OID_ROLE)));
210
-    }
211
-    
212
-    /**
213
-     * Generate ASN.1 structure.
214
-     *
215
-     * @return Sequence
216
-     */
217
-    public function toASN1(): Sequence
218
-    {
219
-        $elements = array_map(
220
-            function (Attribute $attr) {
221
-                return $attr->toASN1();
222
-            }, array_values($this->_attributes));
223
-        return new Sequence(...$elements);
224
-    }
29
+	use AttributeContainer;
30
+    
31
+	/**
32
+	 * Mapping from OID to attribute value class name.
33
+	 *
34
+	 * @internal
35
+	 *
36
+	 * @var array
37
+	 */
38
+	const MAP_OID_TO_CLASS = array(
39
+		/* @formatter:off */
40
+		AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
41
+		AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
42
+		ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
43
+		GroupAttributeValue::OID => GroupAttributeValue::class,
44
+		AttributeType::OID_ROLE => RoleAttributeValue::class
45
+		/* @formatter:on */
46
+	);
47
+    
48
+	/**
49
+	 * Constructor.
50
+	 *
51
+	 * @param Attribute[] $attribs
52
+	 */
53
+	public function __construct(Attribute ...$attribs)
54
+	{
55
+		$this->_attributes = $attribs;
56
+	}
57
+    
58
+	/**
59
+	 * Initialize from attribute values.
60
+	 *
61
+	 * @param AttributeValue[] $values
62
+	 * @return self
63
+	 */
64
+	public static function fromAttributeValues(AttributeValue ...$values)
65
+	{
66
+		$attribs = array_map(
67
+			function (AttributeValue $value) {
68
+				return $value->toAttribute();
69
+			}, $values);
70
+		return new self(...$attribs);
71
+	}
72
+    
73
+	/**
74
+	 * Initialize from ASN.1.
75
+	 *
76
+	 * @param Sequence $seq
77
+	 * @return self
78
+	 */
79
+	public static function fromASN1(Sequence $seq)
80
+	{
81
+		$attribs = array_map(
82
+			function (UnspecifiedType $el) {
83
+				return Attribute::fromASN1($el->asSequence());
84
+			}, $seq->elements());
85
+		// cast attributes
86
+		$attribs = array_map(
87
+			function (Attribute $attr) {
88
+				$oid = $attr->oid();
89
+				if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
90
+					$cls = self::MAP_OID_TO_CLASS[$oid];
91
+					$attr = $attr->castValues($cls);
92
+				}
93
+				return $attr;
94
+			}, $attribs);
95
+		return new self(...$attribs);
96
+	}
97
+    
98
+	/**
99
+	 * Check whether 'Access Identity' attribute is present.
100
+	 *
101
+	 * @return bool
102
+	 */
103
+	public function hasAccessIdentity(): bool
104
+	{
105
+		return $this->has(AccessIdentityAttributeValue::OID);
106
+	}
107
+    
108
+	/**
109
+	 * Get the first 'Access Identity' attribute value.
110
+	 *
111
+	 * @return AccessIdentityAttributeValue
112
+	 */
113
+	public function accessIdentity(): AccessIdentityAttributeValue
114
+	{
115
+		return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
116
+	}
117
+    
118
+	/**
119
+	 * Check whether 'Service Authentication Information' attribute is present.
120
+	 *
121
+	 * @return bool
122
+	 */
123
+	public function hasAuthenticationInformation(): bool
124
+	{
125
+		return $this->has(AuthenticationInfoAttributeValue::OID);
126
+	}
127
+    
128
+	/**
129
+	 * Get the first 'Service Authentication Information' attribute value.
130
+	 *
131
+	 * @return AuthenticationInfoAttributeValue
132
+	 */
133
+	public function authenticationInformation(): AuthenticationInfoAttributeValue
134
+	{
135
+		return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
136
+	}
137
+    
138
+	/**
139
+	 * Check whether 'Charging Identity' attribute is present.
140
+	 *
141
+	 * @return bool
142
+	 */
143
+	public function hasChargingIdentity(): bool
144
+	{
145
+		return $this->has(ChargingIdentityAttributeValue::OID);
146
+	}
147
+    
148
+	/**
149
+	 * Get the first 'Charging Identity' attribute value.
150
+	 *
151
+	 * @return ChargingIdentityAttributeValue
152
+	 */
153
+	public function chargingIdentity(): ChargingIdentityAttributeValue
154
+	{
155
+		return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
156
+	}
157
+    
158
+	/**
159
+	 * Check whether 'Group' attribute is present.
160
+	 *
161
+	 * @return bool
162
+	 */
163
+	public function hasGroup(): bool
164
+	{
165
+		return $this->has(GroupAttributeValue::OID);
166
+	}
167
+    
168
+	/**
169
+	 * Get the first 'Group' attribute value.
170
+	 *
171
+	 * @return GroupAttributeValue
172
+	 */
173
+	public function group(): GroupAttributeValue
174
+	{
175
+		return $this->firstOf(GroupAttributeValue::OID)->first();
176
+	}
177
+    
178
+	/**
179
+	 * Check whether 'Role' attribute is present.
180
+	 *
181
+	 * @return bool
182
+	 */
183
+	public function hasRole(): bool
184
+	{
185
+		return $this->has(AttributeType::OID_ROLE);
186
+	}
187
+    
188
+	/**
189
+	 * Get the first 'Role' attribute value.
190
+	 *
191
+	 * @return RoleAttributeValue
192
+	 */
193
+	public function role(): RoleAttributeValue
194
+	{
195
+		return $this->firstOf(AttributeType::OID_ROLE)->first();
196
+	}
197
+    
198
+	/**
199
+	 * Get all 'Role' attribute values.
200
+	 *
201
+	 * @return RoleAttributeValue[]
202
+	 */
203
+	public function roles(): array
204
+	{
205
+		return array_merge(array(),
206
+			...array_map(
207
+				function (Attribute $attr) {
208
+					return $attr->values();
209
+				}, $this->allOf(AttributeType::OID_ROLE)));
210
+	}
211
+    
212
+	/**
213
+	 * Generate ASN.1 structure.
214
+	 *
215
+	 * @return Sequence
216
+	 */
217
+	public function toASN1(): Sequence
218
+	{
219
+		$elements = array_map(
220
+			function (Attribute $attr) {
221
+				return $attr->toASN1();
222
+			}, array_values($this->_attributes));
223
+		return new Sequence(...$elements);
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\AttributeCertificate;
6 6
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public static function fromAttributeValues(AttributeValue ...$values)
65 65
     {
66 66
         $attribs = array_map(
67
-            function (AttributeValue $value) {
67
+            function(AttributeValue $value) {
68 68
                 return $value->toAttribute();
69 69
             }, $values);
70 70
         return new self(...$attribs);
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
     public static function fromASN1(Sequence $seq)
80 80
     {
81 81
         $attribs = array_map(
82
-            function (UnspecifiedType $el) {
82
+            function(UnspecifiedType $el) {
83 83
                 return Attribute::fromASN1($el->asSequence());
84 84
             }, $seq->elements());
85 85
         // cast attributes
86 86
         $attribs = array_map(
87
-            function (Attribute $attr) {
87
+            function(Attribute $attr) {
88 88
                 $oid = $attr->oid();
89 89
                 if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
90 90
                     $cls = self::MAP_OID_TO_CLASS[$oid];
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         return array_merge(array(),
206 206
             ...array_map(
207
-                function (Attribute $attr) {
207
+                function(Attribute $attr) {
208 208
                     return $attr->values();
209 209
                 }, $this->allOf(AttributeType::OID_ROLE)));
210 210
     }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     public function toASN1(): Sequence
218 218
     {
219 219
         $elements = array_map(
220
-            function (Attribute $attr) {
220
+            function(Attribute $attr) {
221 221
                 return $attr->toASN1();
222 222
             }, array_values($this->_attributes));
223 223
         return new Sequence(...$elements);
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/ObjectDigestInfo.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -20,92 +20,92 @@
 block discarded – undo
20 20
  */
21 21
 class ObjectDigestInfo
22 22
 {
23
-    const TYPE_PUBLIC_KEY = 0;
24
-    const TYPE_PUBLIC_KEY_CERT = 1;
25
-    const TYPE_OTHER_OBJECT_TYPES = 2;
23
+	const TYPE_PUBLIC_KEY = 0;
24
+	const TYPE_PUBLIC_KEY_CERT = 1;
25
+	const TYPE_OTHER_OBJECT_TYPES = 2;
26 26
     
27
-    /**
28
-     * Object type.
29
-     *
30
-     * @var int $_digestedObjectType
31
-     */
32
-    protected $_digestedObjectType;
27
+	/**
28
+	 * Object type.
29
+	 *
30
+	 * @var int $_digestedObjectType
31
+	 */
32
+	protected $_digestedObjectType;
33 33
     
34
-    /**
35
-     * OID of other object type.
36
-     *
37
-     * @var string|null $_otherObjectTypeID
38
-     */
39
-    protected $_otherObjectTypeID;
34
+	/**
35
+	 * OID of other object type.
36
+	 *
37
+	 * @var string|null $_otherObjectTypeID
38
+	 */
39
+	protected $_otherObjectTypeID;
40 40
     
41
-    /**
42
-     * Digest algorithm.
43
-     *
44
-     * @var AlgorithmIdentifierType $_digestAlgorithm
45
-     */
46
-    protected $_digestAlgorithm;
41
+	/**
42
+	 * Digest algorithm.
43
+	 *
44
+	 * @var AlgorithmIdentifierType $_digestAlgorithm
45
+	 */
46
+	protected $_digestAlgorithm;
47 47
     
48
-    /**
49
-     * Object digest.
50
-     *
51
-     * @var BitString $_objectDigest
52
-     */
53
-    protected $_objectDigest;
48
+	/**
49
+	 * Object digest.
50
+	 *
51
+	 * @var BitString $_objectDigest
52
+	 */
53
+	protected $_objectDigest;
54 54
     
55
-    /**
56
-     * Constructor.
57
-     *
58
-     * @param int $type
59
-     * @param AlgorithmIdentifierType $algo
60
-     * @param BitString $digest
61
-     */
62
-    public function __construct($type, AlgorithmIdentifierType $algo,
63
-        BitString $digest)
64
-    {
65
-        $this->_digestedObjectType = $type;
66
-        $this->_otherObjectTypeID = null;
67
-        $this->_digestAlgorithm = $algo;
68
-        $this->_objectDigest = $digest;
69
-    }
55
+	/**
56
+	 * Constructor.
57
+	 *
58
+	 * @param int $type
59
+	 * @param AlgorithmIdentifierType $algo
60
+	 * @param BitString $digest
61
+	 */
62
+	public function __construct($type, AlgorithmIdentifierType $algo,
63
+		BitString $digest)
64
+	{
65
+		$this->_digestedObjectType = $type;
66
+		$this->_otherObjectTypeID = null;
67
+		$this->_digestAlgorithm = $algo;
68
+		$this->_objectDigest = $digest;
69
+	}
70 70
     
71
-    /**
72
-     * Initialize from ASN.1.
73
-     *
74
-     * @param Sequence $seq
75
-     * @return self
76
-     */
77
-    public static function fromASN1(Sequence $seq)
78
-    {
79
-        $type = $seq->at(0)
80
-            ->asEnumerated()
81
-            ->number();
82
-        $oid = null;
83
-        $idx = 1;
84
-        if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) {
85
-            $oid = $seq->at($idx++)
86
-                ->asObjectIdentifier()
87
-                ->oid();
88
-        }
89
-        $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
90
-        $digest = $seq->at($idx)->asBitString();
91
-        $obj = new self($type, $algo, $digest);
92
-        $obj->_otherObjectTypeID = $oid;
93
-        return $obj;
94
-    }
71
+	/**
72
+	 * Initialize from ASN.1.
73
+	 *
74
+	 * @param Sequence $seq
75
+	 * @return self
76
+	 */
77
+	public static function fromASN1(Sequence $seq)
78
+	{
79
+		$type = $seq->at(0)
80
+			->asEnumerated()
81
+			->number();
82
+		$oid = null;
83
+		$idx = 1;
84
+		if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) {
85
+			$oid = $seq->at($idx++)
86
+				->asObjectIdentifier()
87
+				->oid();
88
+		}
89
+		$algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
90
+		$digest = $seq->at($idx)->asBitString();
91
+		$obj = new self($type, $algo, $digest);
92
+		$obj->_otherObjectTypeID = $oid;
93
+		return $obj;
94
+	}
95 95
     
96
-    /**
97
-     * Generate ASN.1 structure.
98
-     *
99
-     * @return Sequence
100
-     */
101
-    public function toASN1(): Sequence
102
-    {
103
-        $elements = array(new Enumerated($this->_digestedObjectType));
104
-        if (isset($this->_otherObjectTypeID)) {
105
-            $elements[] = new ObjectIdentifier($this->_otherObjectTypeID);
106
-        }
107
-        $elements[] = $this->_digestAlgorithm->toASN1();
108
-        $elements[] = $this->_objectDigest;
109
-        return new Sequence(...$elements);
110
-    }
96
+	/**
97
+	 * Generate ASN.1 structure.
98
+	 *
99
+	 * @return Sequence
100
+	 */
101
+	public function toASN1(): Sequence
102
+	{
103
+		$elements = array(new Enumerated($this->_digestedObjectType));
104
+		if (isset($this->_otherObjectTypeID)) {
105
+			$elements[] = new ObjectIdentifier($this->_otherObjectTypeID);
106
+		}
107
+		$elements[] = $this->_digestAlgorithm->toASN1();
108
+		$elements[] = $this->_objectDigest;
109
+		return new Sequence(...$elements);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\AttributeCertificate;
6 6
 
Please login to merge, or discard this patch.
X509/AttributeCertificate/Validation/Exception/ACValidationException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\AttributeCertificate\Validation\Exception;
6 6
 
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/Validation/ACValidator.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -21,178 +21,178 @@
 block discarded – undo
21 21
  */
22 22
 class ACValidator
23 23
 {
24
-    /**
25
-     * Attribute certificate.
26
-     *
27
-     * @var AttributeCertificate
28
-     */
29
-    protected $_ac;
24
+	/**
25
+	 * Attribute certificate.
26
+	 *
27
+	 * @var AttributeCertificate
28
+	 */
29
+	protected $_ac;
30 30
     
31
-    /**
32
-     * Validation configuration.
33
-     *
34
-     * @var ACValidationConfig
35
-     */
36
-    protected $_config;
31
+	/**
32
+	 * Validation configuration.
33
+	 *
34
+	 * @var ACValidationConfig
35
+	 */
36
+	protected $_config;
37 37
     
38
-    /**
39
-     * Crypto engine.
40
-     *
41
-     * @var Crypto
42
-     */
43
-    protected $_crypto;
38
+	/**
39
+	 * Crypto engine.
40
+	 *
41
+	 * @var Crypto
42
+	 */
43
+	protected $_crypto;
44 44
     
45
-    /**
46
-     * Constructor.
47
-     *
48
-     * @param AttributeCertificate $ac Attribute certificate to validate
49
-     * @param ACValidationConfig $config Validation configuration
50
-     * @param Crypto|null $crypto Crypto engine, use default if not set
51
-     */
52
-    public function __construct(AttributeCertificate $ac,
53
-        ACValidationConfig $config, Crypto $crypto = null)
54
-    {
55
-        $this->_ac = $ac;
56
-        $this->_config = $config;
57
-        $this->_crypto = $crypto ?: Crypto::getDefault();
58
-    }
45
+	/**
46
+	 * Constructor.
47
+	 *
48
+	 * @param AttributeCertificate $ac Attribute certificate to validate
49
+	 * @param ACValidationConfig $config Validation configuration
50
+	 * @param Crypto|null $crypto Crypto engine, use default if not set
51
+	 */
52
+	public function __construct(AttributeCertificate $ac,
53
+		ACValidationConfig $config, Crypto $crypto = null)
54
+	{
55
+		$this->_ac = $ac;
56
+		$this->_config = $config;
57
+		$this->_crypto = $crypto ?: Crypto::getDefault();
58
+	}
59 59
     
60
-    /**
61
-     * Validate attribute certificate.
62
-     *
63
-     * @throws ACValidationException If validation fails
64
-     * @return AttributeCertificate Validated AC
65
-     */
66
-    public function validate()
67
-    {
68
-        $this->_validateHolder();
69
-        $issuer = $this->_verifyIssuer();
70
-        $this->_validateIssuerProfile($issuer);
71
-        $this->_validateTime();
72
-        $this->_validateTargeting();
73
-        return $this->_ac;
74
-    }
60
+	/**
61
+	 * Validate attribute certificate.
62
+	 *
63
+	 * @throws ACValidationException If validation fails
64
+	 * @return AttributeCertificate Validated AC
65
+	 */
66
+	public function validate()
67
+	{
68
+		$this->_validateHolder();
69
+		$issuer = $this->_verifyIssuer();
70
+		$this->_validateIssuerProfile($issuer);
71
+		$this->_validateTime();
72
+		$this->_validateTargeting();
73
+		return $this->_ac;
74
+	}
75 75
     
76
-    /**
77
-     * Validate AC holder's certification.
78
-     *
79
-     * @throws ACValidationException
80
-     * @return Certificate Certificate of the AC's holder
81
-     */
82
-    private function _validateHolder()
83
-    {
84
-        $path = $this->_config->holderPath();
85
-        $config = PathValidationConfig::defaultConfig()->withMaxLength(
86
-            count($path))->withDateTime($this->_config->evaluationTime());
87
-        try {
88
-            $holder = $path->validate($config, $this->_crypto)->certificate();
89
-        } catch (PathValidationException $e) {
90
-            throw new ACValidationException(
91
-                "Failed to validate holder PKC's certification path.", 0, $e);
92
-        }
93
-        if (!$this->_ac->isHeldBy($holder)) {
94
-            throw new ACValidationException("Name mismatch of AC's holder PKC.");
95
-        }
96
-        return $holder;
97
-    }
76
+	/**
77
+	 * Validate AC holder's certification.
78
+	 *
79
+	 * @throws ACValidationException
80
+	 * @return Certificate Certificate of the AC's holder
81
+	 */
82
+	private function _validateHolder()
83
+	{
84
+		$path = $this->_config->holderPath();
85
+		$config = PathValidationConfig::defaultConfig()->withMaxLength(
86
+			count($path))->withDateTime($this->_config->evaluationTime());
87
+		try {
88
+			$holder = $path->validate($config, $this->_crypto)->certificate();
89
+		} catch (PathValidationException $e) {
90
+			throw new ACValidationException(
91
+				"Failed to validate holder PKC's certification path.", 0, $e);
92
+		}
93
+		if (!$this->_ac->isHeldBy($holder)) {
94
+			throw new ACValidationException("Name mismatch of AC's holder PKC.");
95
+		}
96
+		return $holder;
97
+	}
98 98
     
99
-    /**
100
-     * Verify AC's signature and issuer's certification.
101
-     *
102
-     * @throws ACValidationException
103
-     * @return Certificate Certificate of the AC's issuer
104
-     */
105
-    private function _verifyIssuer()
106
-    {
107
-        $path = $this->_config->issuerPath();
108
-        $config = PathValidationConfig::defaultConfig()->withMaxLength(
109
-            count($path))->withDateTime($this->_config->evaluationTime());
110
-        try {
111
-            $issuer = $path->validate($config, $this->_crypto)->certificate();
112
-        } catch (PathValidationException $e) {
113
-            throw new ACValidationException(
114
-                "Failed to validate issuer PKC's certification path.", 0, $e);
115
-        }
116
-        if (!$this->_ac->isIssuedBy($issuer)) {
117
-            throw new ACValidationException("Name mismatch of AC's issuer PKC.");
118
-        }
119
-        $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo();
120
-        if (!$this->_ac->verify($pubkey_info, $this->_crypto)) {
121
-            throw new ACValidationException("Failed to verify signature.");
122
-        }
123
-        return $issuer;
124
-    }
99
+	/**
100
+	 * Verify AC's signature and issuer's certification.
101
+	 *
102
+	 * @throws ACValidationException
103
+	 * @return Certificate Certificate of the AC's issuer
104
+	 */
105
+	private function _verifyIssuer()
106
+	{
107
+		$path = $this->_config->issuerPath();
108
+		$config = PathValidationConfig::defaultConfig()->withMaxLength(
109
+			count($path))->withDateTime($this->_config->evaluationTime());
110
+		try {
111
+			$issuer = $path->validate($config, $this->_crypto)->certificate();
112
+		} catch (PathValidationException $e) {
113
+			throw new ACValidationException(
114
+				"Failed to validate issuer PKC's certification path.", 0, $e);
115
+		}
116
+		if (!$this->_ac->isIssuedBy($issuer)) {
117
+			throw new ACValidationException("Name mismatch of AC's issuer PKC.");
118
+		}
119
+		$pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo();
120
+		if (!$this->_ac->verify($pubkey_info, $this->_crypto)) {
121
+			throw new ACValidationException("Failed to verify signature.");
122
+		}
123
+		return $issuer;
124
+	}
125 125
     
126
-    /**
127
-     * Validate AC issuer's profile.
128
-     *
129
-     * @link https://tools.ietf.org/html/rfc5755#section-4.5
130
-     * @param Certificate $cert
131
-     * @throws ACValidationException
132
-     */
133
-    private function _validateIssuerProfile(Certificate $cert)
134
-    {
135
-        $exts = $cert->tbsCertificate()->extensions();
136
-        if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) {
137
-            throw new ACValidationException(
138
-                "Issuer PKC's Key Usage extension doesn't permit" .
139
-                     " verification of digital signatures.");
140
-        }
141
-        if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) {
142
-            throw new ACValidationException("Issuer PKC must not be a CA.");
143
-        }
144
-    }
126
+	/**
127
+	 * Validate AC issuer's profile.
128
+	 *
129
+	 * @link https://tools.ietf.org/html/rfc5755#section-4.5
130
+	 * @param Certificate $cert
131
+	 * @throws ACValidationException
132
+	 */
133
+	private function _validateIssuerProfile(Certificate $cert)
134
+	{
135
+		$exts = $cert->tbsCertificate()->extensions();
136
+		if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) {
137
+			throw new ACValidationException(
138
+				"Issuer PKC's Key Usage extension doesn't permit" .
139
+					 " verification of digital signatures.");
140
+		}
141
+		if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) {
142
+			throw new ACValidationException("Issuer PKC must not be a CA.");
143
+		}
144
+	}
145 145
     
146
-    /**
147
-     * Validate AC's validity period.
148
-     *
149
-     * @throws ACValidationException
150
-     */
151
-    private function _validateTime()
152
-    {
153
-        $t = $this->_config->evaluationTime();
154
-        $validity = $this->_ac->acinfo()->validityPeriod();
155
-        if ($validity->notBeforeTime()->diff($t)->invert) {
156
-            throw new ACValidationException("Validity period has not started.");
157
-        }
158
-        if ($t->diff($validity->notAfterTime())->invert) {
159
-            throw new ACValidationException("Attribute certificate has expired.");
160
-        }
161
-    }
146
+	/**
147
+	 * Validate AC's validity period.
148
+	 *
149
+	 * @throws ACValidationException
150
+	 */
151
+	private function _validateTime()
152
+	{
153
+		$t = $this->_config->evaluationTime();
154
+		$validity = $this->_ac->acinfo()->validityPeriod();
155
+		if ($validity->notBeforeTime()->diff($t)->invert) {
156
+			throw new ACValidationException("Validity period has not started.");
157
+		}
158
+		if ($t->diff($validity->notAfterTime())->invert) {
159
+			throw new ACValidationException("Attribute certificate has expired.");
160
+		}
161
+	}
162 162
     
163
-    /**
164
-     * Validate AC's target information.
165
-     *
166
-     * @throws ACValidationException
167
-     */
168
-    private function _validateTargeting()
169
-    {
170
-        $exts = $this->_ac->acinfo()->extensions();
171
-        // if target information extension is not present
172
-        if (!$exts->has(Extension::OID_TARGET_INFORMATION)) {
173
-            return;
174
-        }
175
-        $ext = $exts->get(Extension::OID_TARGET_INFORMATION);
176
-        if ($ext instanceof TargetInformationExtension &&
177
-             !$this->_hasMatchingTarget($ext->targets())) {
178
-            throw new ACValidationException(
179
-                "Attribute certificate doesn't have a matching target.");
180
-        }
181
-    }
163
+	/**
164
+	 * Validate AC's target information.
165
+	 *
166
+	 * @throws ACValidationException
167
+	 */
168
+	private function _validateTargeting()
169
+	{
170
+		$exts = $this->_ac->acinfo()->extensions();
171
+		// if target information extension is not present
172
+		if (!$exts->has(Extension::OID_TARGET_INFORMATION)) {
173
+			return;
174
+		}
175
+		$ext = $exts->get(Extension::OID_TARGET_INFORMATION);
176
+		if ($ext instanceof TargetInformationExtension &&
177
+			 !$this->_hasMatchingTarget($ext->targets())) {
178
+			throw new ACValidationException(
179
+				"Attribute certificate doesn't have a matching target.");
180
+		}
181
+	}
182 182
     
183
-    /**
184
-     * Check whether validation configuration has matching targets.
185
-     *
186
-     * @param Targets $targets Set of eligible targets
187
-     * @return boolean
188
-     */
189
-    private function _hasMatchingTarget(Targets $targets)
190
-    {
191
-        foreach ($this->_config->targets() as $target) {
192
-            if ($targets->hasTarget($target)) {
193
-                return true;
194
-            }
195
-        }
196
-        return false;
197
-    }
183
+	/**
184
+	 * Check whether validation configuration has matching targets.
185
+	 *
186
+	 * @param Targets $targets Set of eligible targets
187
+	 * @return boolean
188
+	 */
189
+	private function _hasMatchingTarget(Targets $targets)
190
+	{
191
+		foreach ($this->_config->targets() as $target) {
192
+			if ($targets->hasTarget($target)) {
193
+				return true;
194
+			}
195
+		}
196
+		return false;
197
+	}
198 198
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace X509\AttributeCertificate\Validation;
6 6
 
Please login to merge, or discard this patch.