Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/CertificationPath/PathValidation/PathValidationResult.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\CertificationPath\PathValidation;
6
7 use function count;
8 use SpomkyLabs\Pki\ASN1\Element;
9 use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType;
10 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKeyInfo;
11 use SpomkyLabs\Pki\X509\Certificate\Certificate;
12 use SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy\PolicyInformation;
13 use SpomkyLabs\Pki\X509\CertificationPath\Policy\PolicyTree;
14
15 /**
16 * Result of the path validation process.
17 *
18 * @see https://tools.ietf.org/html/rfc5280#section-6.1.6
19 */
20 final class PathValidationResult
21 {
22 /**
23 * Certificates in a certification path.
24 *
25 * @var Certificate[]
26 */
27 private readonly array $certificates;
28
29 /**
30 * @param Certificate[] $certificates
31 */
32 private function __construct(
33 array $certificates,
34 private readonly ?PolicyTree $policyTree,
35 private readonly PublicKeyInfo $publicKeyInfo,
36 private readonly AlgorithmIdentifierType $publicKeyAlgo,
37 private readonly ?Element $publicKeyParameters
38 ) {
39 $this->certificates = array_values($certificates);
40 }
41
42 /**
43 * @param Certificate[] $certificates Certificates in a certification path
44 * @param null|PolicyTree $policyTree Valid policy tree
45 * @param PublicKeyInfo $publicKeyInfo Public key of the end-entity certificate
46 * @param AlgorithmIdentifierType $publicKeyAlgo Public key algorithm of the end-entity certificate
47 * @param null|Element $publicKeyParameters Algorithm parameters
48 */
49 public static function create(
50 array $certificates,
51 ?PolicyTree $policyTree,
52 PublicKeyInfo $publicKeyInfo,
53 AlgorithmIdentifierType $publicKeyAlgo,
54 ?Element $publicKeyParameters = null
55 ): self {
56 return new self($certificates, $policyTree, $publicKeyInfo, $publicKeyAlgo, $publicKeyParameters);
57 }
58
59 public function getPolicyTree(): ?PolicyTree
60 {
61 return $this->policyTree;
62 }
63
64 public function getPublicKeyInfo(): PublicKeyInfo
65 {
66 return $this->publicKeyInfo;
67 }
68
69 public function getPublicKeyAlgo(): AlgorithmIdentifierType
70 {
71 return $this->publicKeyAlgo;
72 }
73
74 public function getPublicKeyParameters(): ?Element
75 {
76 return $this->publicKeyParameters;
77 }
78
79 /**
80 * Get end-entity certificate.
81 */
82 public function certificate(): Certificate
83 {
84 return $this->certificates[count($this->certificates) - 1];
85 }
86
87 /**
88 * Get certificate policies of the end-entity certificate.
89 *
90 * @return PolicyInformation[]
91 */
92 public function policies(): array
93 {
94 if ($this->policyTree === null) {
95 return [];
96 }
97 return $this->policyTree->policiesAtDepth(count($this->certificates));
98 }
99 }