<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy; use SpomkyLabs\Pki\ASN1\Element; use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier; use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; use UnexpectedValueException; abstract class PolicyQualifierInfo { public const OID_CPS = '1.3.6.1.5.5.7.2.1'; public const OID_UNOTICE = '1.3.6.1.5.5.7.2.2'; protected function __construct( protected string $oid ) { } abstract public static function fromQualifierASN1(UnspecifiedType $el): self; public static function fromASN1(Sequence $seq): self { $oid = $seq->at(0) ->asObjectIdentifier() ->oid(); return match ($oid) { self::OID_CPS => CPSQualifier::fromQualifierASN1($seq->at(1)), self::OID_UNOTICE => UserNoticeQualifier::fromQualifierASN1($seq->at(1)), default => throw new UnexpectedValueException("Qualifier {$oid} not supported."), }; } public function oid(): string { return $this->oid; } public function toASN1(): Sequence { return Sequence::create(ObjectIdentifier::create($this->oid), $this->qualifierASN1()); } abstract protected function qualifierASN1(): Element; } 