<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X509\CertificationPath\PathValidation; use SpomkyLabs\Pki\ASN1\Element; use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType; use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKeyInfo; use SpomkyLabs\Pki\X509\Certificate\Certificate; use SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy\PolicyInformation; use SpomkyLabs\Pki\X509\CertificationPath\Policy\PolicyTree; use function count; final class PathValidationResult { private readonly array $certificates; private function __construct( array $certificates, private readonly ?PolicyTree $policyTree, private readonly PublicKeyInfo $publicKeyInfo, private readonly AlgorithmIdentifierType $publicKeyAlgo, private readonly ?Element $publicKeyParameters ) { $this->certificates = array_values($certificates); } public static function create( array $certificates, ?PolicyTree $policyTree, PublicKeyInfo $publicKeyInfo, AlgorithmIdentifierType $publicKeyAlgo, ?Element $publicKeyParameters = null ): self { return new self($certificates, $policyTree, $publicKeyInfo, $publicKeyAlgo, $publicKeyParameters); } public function getPolicyTree(): ?PolicyTree { return $this->policyTree; } public function getPublicKeyInfo(): PublicKeyInfo { return $this->publicKeyInfo; } public function getPublicKeyAlgo(): AlgorithmIdentifierType { return $this->publicKeyAlgo; } public function getPublicKeyParameters(): ?Element { return $this->publicKeyParameters; } public function certificate(): Certificate { return $this->certificates[count($this->certificates) - 1]; } public function policies(): array { if ($this->policyTree === null) { return []; } return $this->policyTree->policiesAtDepth(count($this->certificates)); } } 