1 | <?php |
||
24 | class CertificationPath implements \Countable, \IteratorAggregate |
||
25 | { |
||
26 | /** |
||
27 | * Certification path. |
||
28 | * |
||
29 | * @var Certificate[] $_certificates |
||
30 | */ |
||
31 | protected $_certificates; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param Certificate ...$certificates Certificates from the trust anchor |
||
37 | * to the target end-entity certificate |
||
38 | */ |
||
39 | 38 | public function __construct(Certificate ...$certificates) |
|
43 | |||
44 | /** |
||
45 | * Initialize from a certificate chain. |
||
46 | * |
||
47 | * @param CertificateChain $chain |
||
48 | * @return self |
||
49 | */ |
||
50 | 2 | public static function fromCertificateChain(CertificateChain $chain): self |
|
54 | |||
55 | /** |
||
56 | * Build certification path to given target. |
||
57 | * |
||
58 | * @param Certificate $target Target end-entity certificate |
||
59 | * @param CertificateBundle $trust_anchors List of trust anchors |
||
60 | * @param CertificateBundle|null $intermediate Optional intermediate |
||
61 | * certificates |
||
62 | * @return self |
||
63 | */ |
||
64 | 2 | public static function toTarget(Certificate $target, |
|
70 | |||
71 | /** |
||
72 | * Build certification path from given trust anchor to target certificate, |
||
73 | * using intermediate certificates from given bundle. |
||
74 | * |
||
75 | * @param Certificate $trust_anchor Trust anchor certificate |
||
76 | * @param Certificate $target Target end-entity certificate |
||
77 | * @param CertificateBundle|null $intermediate Optional intermediate |
||
78 | * certificates |
||
79 | * @return self |
||
80 | */ |
||
81 | 2 | public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
87 | |||
88 | /** |
||
89 | * Get certificates. |
||
90 | * |
||
91 | * @return Certificate[] |
||
92 | */ |
||
93 | 5 | public function certificates(): array |
|
97 | |||
98 | /** |
||
99 | * Get the trust anchor certificate from the path. |
||
100 | * |
||
101 | * @throws \LogicException If path is empty |
||
102 | * @return Certificate |
||
103 | */ |
||
104 | 2 | public function trustAnchorCertificate(): Certificate |
|
111 | |||
112 | /** |
||
113 | * Get the end-entity certificate from the path. |
||
114 | * |
||
115 | * @throws \LogicException If path is empty |
||
116 | * @return Certificate |
||
117 | */ |
||
118 | 2 | public function endEntityCertificate(): Certificate |
|
125 | |||
126 | /** |
||
127 | * Get certification path as a certificate chain. |
||
128 | * |
||
129 | * @return CertificateChain |
||
130 | */ |
||
131 | 1 | public function certificateChain(): CertificateChain |
|
136 | |||
137 | /** |
||
138 | * Check whether certification path starts with one ore more given |
||
139 | * certificates in parameter order. |
||
140 | * |
||
141 | * @param Certificate ...$certs Certificates |
||
142 | * @return true |
||
143 | */ |
||
144 | 5 | public function startsWith(Certificate ...$certs): bool |
|
157 | |||
158 | /** |
||
159 | * Validate certification path. |
||
160 | * |
||
161 | * @param PathValidationConfig $config |
||
162 | * @param Crypto|null $crypto Crypto engine, use default if not set |
||
163 | * @throws Exception\PathValidationException |
||
164 | * @return PathValidation\PathValidationResult |
||
165 | */ |
||
166 | 43 | public function validate(PathValidationConfig $config, Crypto $crypto = null): PathValidation\PathValidationResult |
|
172 | |||
173 | /** |
||
174 | * |
||
175 | * @see \Countable::count() |
||
176 | * @return int |
||
177 | */ |
||
178 | 18 | public function count(): int |
|
182 | |||
183 | /** |
||
184 | * Get iterator for certificates. |
||
185 | * |
||
186 | * @see \IteratorAggregate::getIterator() |
||
187 | * @return \ArrayIterator |
||
188 | */ |
||
189 | 1 | public function getIterator(): \ArrayIterator |
|
193 | } |
||
194 |