| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension\DistributionPoint; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Element; |
| 8 |
use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType; |
| 9 |
use SpomkyLabs\Pki\ASN1\Type\TaggedType; |
| 10 |
use SpomkyLabs\Pki\X501\ASN1\RDN; |
| 11 |
use SpomkyLabs\Pki\X509\GeneralName\GeneralNames; |
| 12 |
use UnexpectedValueException; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
abstract class DistributionPointName |
| 20 |
{ |
| 21 |
public const TAG_FULL_NAME = 0; |
| 22 |
|
| 23 |
public const TAG_RDN = 1; |
| 24 |
|
| 25 |
protected function __construct( |
| 26 |
protected int $tag |
| 27 |
) { |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public static function fromTaggedType(TaggedType $el): self |
| 34 |
{ |
| 35 |
return match ($el->tag()) { |
| 36 |
self::TAG_FULL_NAME => FullName::create(GeneralNames::fromASN1( |
| 37 |
$el->asImplicit(Element::TYPE_SEQUENCE)->asSequence() |
| 38 |
)), |
| 39 |
self::TAG_RDN => RelativeName::create(RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())), |
| 40 |
default => throw new UnexpectedValueException( |
| 41 |
'DistributionPointName tag ' . $el->tag() . ' not supported.' |
| 42 |
), |
| 43 |
}; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function tag(): int |
| 50 |
{ |
| 51 |
return $this->tag; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public function toASN1(): ImplicitlyTaggedType |
| 58 |
{ |
| 59 |
return ImplicitlyTaggedType::create($this->tag, $this->_valueASN1()); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
abstract protected function _valueASN1(): Element; |
| 66 |
} |