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.

PathValidationConfig::hasTrustAnchor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\CertificationPath\PathValidation;
6
7
use Sop\X509\Certificate\Certificate;
8
use Sop\X509\Certificate\Extension\CertificatePolicy\PolicyInformation;
9
10
/**
11
 * Configuration for the certification path validation process.
12
 *
13
 * @see https://tools.ietf.org/html/rfc5280#section-6.1.1
14
 */
15
class PathValidationConfig
16
{
17
    /**
18
     * Maximum allowed certification path length.
19
     *
20
     * @var int
21
     */
22
    protected $_maxLength;
23
24
    /**
25
     * Reference time.
26
     *
27
     * @var \DateTimeImmutable
28
     */
29
    protected $_dateTime;
30
31
    /**
32
     * List of acceptable policy identifiers.
33
     *
34
     * @var string[]
35
     */
36
    protected $_policySet;
37
38
    /**
39
     * Trust anchor certificate.
40
     *
41
     * If not set, path validation uses the first certificate of the path.
42
     *
43
     * @var null|Certificate
44
     */
45
    protected $_trustAnchor;
46
47
    /**
48
     * Whether policy mapping in inhibited.
49
     *
50
     * Setting this to true disallows policy mapping.
51
     *
52
     * @var bool
53
     */
54
    protected $_policyMappingInhibit;
55
56
    /**
57
     * Whether the path must be valid for at least one policy in the
58
     * initial policy set.
59
     *
60
     * @var bool
61
     */
62
    protected $_explicitPolicy;
63
64
    /**
65
     * Whether anyPolicy OID processing should be inhibited.
66
     *
67
     * Setting this to true disallows the usage of anyPolicy.
68
     *
69
     * @var bool
70
     */
71
    protected $_anyPolicyInhibit;
72
73
    /**
74
     * @todo Implement
75
     *
76
     * @var mixed
77
     */
78
    protected $_permittedSubtrees;
79
80
    /**
81
     * @todo Implement
82
     *
83
     * @var mixed
84
     */
85
    protected $_excludedSubtrees;
86
87
    /**
88
     * Constructor.
89
     *
90
     * @param \DateTimeImmutable $dt         Reference date and time
91
     * @param int                $max_length Maximum certification path length
92
     */
93 49
    public function __construct(\DateTimeImmutable $dt, int $max_length)
94
    {
95 49
        $this->_dateTime = $dt;
96 49
        $this->_maxLength = $max_length;
97 49
        $this->_policySet = [PolicyInformation::OID_ANY_POLICY];
98 49
        $this->_policyMappingInhibit = false;
99 49
        $this->_explicitPolicy = false;
100 49
        $this->_anyPolicyInhibit = false;
101 49
    }
102
103
    /**
104
     * Get default configuration.
105
     *
106
     * @return self
107
     */
108 24
    public static function defaultConfig(): self
109
    {
110 24
        return new self(new \DateTimeImmutable(), 3);
111
    }
112
113
    /**
114
     * Get self with maximum path length.
115
     *
116
     * @param int $length
117
     *
118
     * @return self
119
     */
120 14
    public function withMaxLength(int $length): self
121
    {
122 14
        $obj = clone $this;
123 14
        $obj->_maxLength = $length;
124 14
        return $obj;
125
    }
126
127
    /**
128
     * Get self with reference date and time.
129
     *
130
     * @param \DateTimeImmutable $dt
131
     *
132
     * @return self
133
     */
134 16
    public function withDateTime(\DateTimeImmutable $dt): self
135
    {
136 16
        $obj = clone $this;
137 16
        $obj->_dateTime = $dt;
138 16
        return $obj;
139
    }
140
141
    /**
142
     * Get self with trust anchor certificate.
143
     *
144
     * @param Certificate $ca
145
     *
146
     * @return self
147
     */
148 2
    public function withTrustAnchor(Certificate $ca): self
149
    {
150 2
        $obj = clone $this;
151 2
        $obj->_trustAnchor = $ca;
152 2
        return $obj;
153
    }
154
155
    /**
156
     * Get self with initial-policy-mapping-inhibit set.
157
     *
158
     * @param bool $flag
159
     *
160
     * @return self
161
     */
162 1
    public function withPolicyMappingInhibit(bool $flag): self
163
    {
164 1
        $obj = clone $this;
165 1
        $obj->_policyMappingInhibit = $flag;
166 1
        return $obj;
167
    }
168
169
    /**
170
     * Get self with initial-explicit-policy set.
171
     *
172
     * @param bool $flag
173
     *
174
     * @return self
175
     */
176 7
    public function withExplicitPolicy(bool $flag): self
177
    {
178 7
        $obj = clone $this;
179 7
        $obj->_explicitPolicy = $flag;
180 7
        return $obj;
181
    }
182
183
    /**
184
     * Get self with initial-any-policy-inhibit set.
185
     *
186
     * @param bool $flag
187
     *
188
     * @return self
189
     */
190 1
    public function withAnyPolicyInhibit(bool $flag): self
191
    {
192 1
        $obj = clone $this;
193 1
        $obj->_anyPolicyInhibit = $flag;
194 1
        return $obj;
195
    }
196
197
    /**
198
     * Get self with user-initial-policy-set set to policy OIDs.
199
     *
200
     * @param string ...$policies List of policy OIDs
201
     *
202
     * @return self
203
     */
204 6
    public function withPolicySet(string ...$policies): self
205
    {
206 6
        $obj = clone $this;
207 6
        $obj->_policySet = $policies;
208 6
        return $obj;
209
    }
210
211
    /**
212
     * Get maximum certification path length.
213
     *
214
     * @return int
215
     */
216 48
    public function maxLength(): int
217
    {
218 48
        return $this->_maxLength;
219
    }
220
221
    /**
222
     * Get reference date and time.
223
     *
224
     * @return \DateTimeImmutable
225
     */
226 45
    public function dateTime(): \DateTimeImmutable
227
    {
228 45
        return $this->_dateTime;
229
    }
230
231
    /**
232
     * Get user-initial-policy-set.
233
     *
234
     * @return string[] Array of OID's
235
     */
236 10
    public function policySet(): array
237
    {
238 10
        return $this->_policySet;
239
    }
240
241
    /**
242
     * Check whether trust anchor certificate is set.
243
     *
244
     * @return bool
245
     */
246 47
    public function hasTrustAnchor(): bool
247
    {
248 47
        return isset($this->_trustAnchor);
249
    }
250
251
    /**
252
     * Get trust anchor certificate.
253
     *
254
     * @throws \LogicException If not set
255
     *
256
     * @return Certificate
257
     */
258 3
    public function trustAnchor(): Certificate
259
    {
260 3
        if (!$this->hasTrustAnchor()) {
261 1
            throw new \LogicException('No trust anchor.');
262
        }
263 2
        return $this->_trustAnchor;
264
    }
265
266
    /**
267
     * Get initial-policy-mapping-inhibit.
268
     *
269
     * @return bool
270
     */
271 48
    public function policyMappingInhibit(): bool
272
    {
273 48
        return $this->_policyMappingInhibit;
274
    }
275
276
    /**
277
     * Get initial-explicit-policy.
278
     *
279
     * @return bool
280
     */
281 48
    public function explicitPolicy(): bool
282
    {
283 48
        return $this->_explicitPolicy;
284
    }
285
286
    /**
287
     * Get initial-any-policy-inhibit.
288
     *
289
     * @return bool
290
     */
291 48
    public function anyPolicyInhibit(): bool
292
    {
293 48
        return $this->_anyPolicyInhibit;
294
    }
295
}
296