| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\AttributeCertificate; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Element; |
| 8 |
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 9 |
use SpomkyLabs\Pki\X501\ASN1\Name; |
| 10 |
use SpomkyLabs\Pki\X509\Certificate\Certificate; |
| 11 |
use SpomkyLabs\Pki\X509\GeneralName\DirectoryName; |
| 12 |
use SpomkyLabs\Pki\X509\GeneralName\GeneralNames; |
| 13 |
use UnexpectedValueException; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
abstract class AttCertIssuer |
| 21 |
{ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
abstract public function toASN1(): Element; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
abstract public function identifiesPKC(Certificate $cert): bool; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static function fromName(Name $name): self |
| 41 |
{ |
| 42 |
return V2Form::create(GeneralNames::create(DirectoryName::create($name))); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public static function fromPKC(Certificate $cert): self |
| 49 |
{ |
| 50 |
return self::fromName($cert->tbsCertificate()->subject()); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public static function fromASN1(UnspecifiedType $el): self |
| 59 |
{ |
| 60 |
if (! $el->isTagged()) { |
| 61 |
throw new UnexpectedValueException('v1Form issuer not supported.'); |
| 62 |
} |
| 63 |
$tagged = $el->asTagged(); |
| 64 |
return match ($tagged->tag()) { |
| 65 |
0 => V2Form::fromV2ASN1($tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()), |
| 66 |
default => throw new UnexpectedValueException('Unsupported issuer type.'), |
| 67 |
}; |
| 68 |
} |
| 69 |
} |