<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X509\CertificationPath\PathValidation; use DateTimeImmutable; use LogicException; use SpomkyLabs\Pki\X509\Certificate\Certificate; use SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy\PolicyInformation; final class PathValidationConfig { private array $policySet; private ?Certificate $trustAnchor = null; private bool $policyMappingInhibit; private bool $explicitPolicy; private bool $anyPolicyInhibit; private function __construct( private DateTimeImmutable $dateTime, private int $maxLength ) { $this->policySet = [PolicyInformation::OID_ANY_POLICY]; $this->policyMappingInhibit = false; $this->explicitPolicy = false; $this->anyPolicyInhibit = false; } public static function create(DateTimeImmutable $dateTime, int $maxLength): self { return new self($dateTime, $maxLength); } public static function defaultConfig(): self { return self::create(new DateTimeImmutable(), 3); } public function withMaxLength(int $length): self { $obj = clone $this; $obj->maxLength = $length; return $obj; } public function withDateTime(DateTimeImmutable $dt): self { $obj = clone $this; $obj->dateTime = $dt; return $obj; } public function withTrustAnchor(Certificate $ca): self { $obj = clone $this; $obj->trustAnchor = $ca; return $obj; } public function withPolicyMappingInhibit(bool $flag): self { $obj = clone $this; $obj->policyMappingInhibit = $flag; return $obj; } public function withExplicitPolicy(bool $flag): self { $obj = clone $this; $obj->explicitPolicy = $flag; return $obj; } public function withAnyPolicyInhibit(bool $flag): self { $obj = clone $this; $obj->anyPolicyInhibit = $flag; return $obj; } public function withPolicySet(string ...$policies): self { $obj = clone $this; $obj->policySet = $policies; return $obj; } public function maxLength(): int { return $this->maxLength; } public function dateTime(): DateTimeImmutable { return $this->dateTime; } public function policySet(): array { return $this->policySet; } public function hasTrustAnchor(): bool { return isset($this->trustAnchor); } public function trustAnchor(): Certificate { if (! $this->hasTrustAnchor()) { throw new LogicException('No trust anchor.'); } return $this->trustAnchor; } public function policyMappingInhibit(): bool { return $this->policyMappingInhibit; } public function explicitPolicy(): bool { return $this->explicitPolicy; } public function anyPolicyInhibit(): bool { return $this->anyPolicyInhibit; } } 