Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/AttributeCertificate/Validation/ACValidationConfig.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\AttributeCertificate\Validation;
6
7 use DateTimeImmutable;
8 use Psr\Clock\ClockInterface;
9 use SpomkyLabs\Pki\X509\Certificate\Extension\Target\Target;
10 use SpomkyLabs\Pki\X509\CertificationPath\CertificationPath;
11
12 /**
13 * Provides configuration context for the attribute certificate validation.
14 */
15 final class ACValidationConfig
16 {
17 /**
18 * Evaluation reference time.
19 */
20 private DateTimeImmutable $evalTime;
21
22 /**
23 * Permitted targets.
24 *
25 * @var Target[]
26 */
27 private array $targets;
28
29 /**
30 * @param CertificationPath $holderPath Certification path of the AC holder
31 * @param CertificationPath $issuerPath Certification path of the AC issuer
32 */
33 private function __construct(
34 private readonly CertificationPath $holderPath,
35 private readonly CertificationPath $issuerPath,
36 ?ClockInterface $clock = null,
37 ) {
38 $this->evalTime = $clock !== null ? $clock->now() : new DateTimeImmutable();
39 $this->targets = [];
40 }
41
42 public static function create(
43 CertificationPath $holderPath,
44 CertificationPath $issuerPath,
45 ?ClockInterface $clock = null,
46 ): self {
47 return new self($holderPath, $issuerPath, $clock);
48 }
49
50 /**
51 * Get certification path of the AC's holder.
52 */
53 public function holderPath(): CertificationPath
54 {
55 return $this->holderPath;
56 }
57
58 /**
59 * Get certification path of the AC's issuer.
60 */
61 public function issuerPath(): CertificationPath
62 {
63 return $this->issuerPath;
64 }
65
66 /**
67 * Get self with given evaluation reference time.
68 */
69 public function withEvaluationTime(DateTimeImmutable $dt): self
70 {
71 $obj = clone $this;
72 $obj->evalTime = $dt;
73 return $obj;
74 }
75
76 /**
77 * Get the evaluation reference time.
78 */
79 public function evaluationTime(): DateTimeImmutable
80 {
81 return $this->evalTime;
82 }
83
84 /**
85 * Get self with permitted targets.
86 */
87 public function withTargets(Target ...$targets): self
88 {
89 $obj = clone $this;
90 $obj->targets = $targets;
91 return $obj;
92 }
93
94 /**
95 * Get array of permitted targets.
96 *
97 * @return Target[]
98 */
99 public function targets(): array
100 {
101 return $this->targets;
102 }
103 }