1 | <?php |
||
25 | class CertificationPath implements \Countable, \IteratorAggregate |
||
26 | { |
||
27 | /** |
||
28 | * Certification path. |
||
29 | * |
||
30 | * @var Certificate[] $_certificates |
||
31 | */ |
||
32 | protected $_certificates; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | * |
||
37 | * @param Certificate ...$certificates Certificates from the trust anchor |
||
38 | * to the target end-entity certificate |
||
39 | */ |
||
40 | 30 | 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) { |
|
53 | |||
54 | /** |
||
55 | * Build certification path to given target. |
||
56 | * |
||
57 | * @param Certificate $target Target end-entity certificate |
||
58 | * @param CertificateBundle $trust_anchors List of trust anchors |
||
59 | * @param CertificateBundle|null $intermediate Optional intermediate |
||
60 | * certificates |
||
61 | * @return self |
||
62 | */ |
||
63 | 2 | public static function toTarget(Certificate $target, |
|
69 | |||
70 | /** |
||
71 | * Build certification path from given trust anchor to target certificate, |
||
72 | * using intermediate certificates from given bundle. |
||
73 | * |
||
74 | * @param Certificate $trust_anchor Trust anchor certificate |
||
75 | * @param Certificate $target Target end-entity certificate |
||
76 | * @param CertificateBundle|null $intermediate Optional intermediate |
||
77 | * certificates |
||
78 | * @return self |
||
79 | */ |
||
80 | 2 | public static function fromTrustAnchorToTarget(Certificate $trust_anchor, |
|
85 | |||
86 | /** |
||
87 | * Get certificates. |
||
88 | * |
||
89 | * @return Certificate[] |
||
90 | */ |
||
91 | 5 | public function certificates() { |
|
94 | |||
95 | /** |
||
96 | * Get the trust anchor certificate from the path. |
||
97 | * |
||
98 | * @throws \LogicException If path is empty |
||
99 | * @return Certificate |
||
100 | */ |
||
101 | 2 | public function trustAnchorCertificate() { |
|
107 | |||
108 | /** |
||
109 | * Get the end-entity certificate from the path. |
||
110 | * |
||
111 | * @throws \LogicException If path is empty |
||
112 | * @return Certificate |
||
113 | */ |
||
114 | 2 | public function endEntityCertificate() { |
|
120 | |||
121 | /** |
||
122 | * Get certification path as a certificate chain. |
||
123 | * |
||
124 | * @return CertificateChain |
||
125 | */ |
||
126 | 1 | public function certificateChain() { |
|
130 | |||
131 | /** |
||
132 | * Check whether certification path starts with one ore more given |
||
133 | * certificates in parameter order. |
||
134 | * |
||
135 | * @param Certificate ...$certs Certificates |
||
136 | * @return true |
||
137 | */ |
||
138 | 5 | public function startsWith(Certificate ...$certs) { |
|
150 | |||
151 | /** |
||
152 | * Validate certification path. |
||
153 | * |
||
154 | * @param Crypto $crypto |
||
155 | * @param PathValidationConfig $config |
||
156 | * @throws PathValidationException |
||
157 | * @return PathValidationResult |
||
158 | */ |
||
159 | 35 | public function validate(Crypto $crypto, PathValidationConfig $config) { |
|
163 | |||
164 | /** |
||
165 | * |
||
166 | * @see Countable::count() |
||
167 | * @return int |
||
168 | */ |
||
169 | 18 | public function count() { |
|
172 | |||
173 | /** |
||
174 | * Get iterator for certificates. |
||
175 | * |
||
176 | * @see IteratorAggregate::getIterator() |
||
177 | * @return \ArrayIterator |
||
178 | */ |
||
179 | 1 | public function getIterator() { |
|
182 | } |
||
183 |