<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X509\AttributeCertificate; use SpomkyLabs\Pki\ASN1\Element; use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; use SpomkyLabs\Pki\X501\ASN1\Name; use SpomkyLabs\Pki\X509\Certificate\Certificate; use SpomkyLabs\Pki\X509\GeneralName\DirectoryName; use SpomkyLabs\Pki\X509\GeneralName\GeneralNames; use UnexpectedValueException; abstract class AttCertIssuer { abstract public function toASN1(): Element; abstract public function identifiesPKC(Certificate $cert): bool; public static function fromName(Name $name): self { return V2Form::create(GeneralNames::create(DirectoryName::create($name))); } public static function fromPKC(Certificate $cert): self { return self::fromName($cert->tbsCertificate()->subject()); } public static function fromASN1(UnspecifiedType $el): self { if (! $el->isTagged()) { throw new UnexpectedValueException('v1Form issuer not supported.'); } $tagged = $el->asTagged(); return match ($tagged->tag()) { 0 => V2Form::fromV2ASN1($tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()), default => throw new UnexpectedValueException('Unsupported issuer type.'), }; } } 