Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/Certificate/Extension/DistributionPoint/DistributionPointName.php

raw symbols SCIP
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 * Base class for *DistributionPointName* ASN.1 CHOICE type used by 'CRL Distribution Points' certificate extension.
16 *
17 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.13
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 * Initialize from TaggedType.
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 * Get type tag.
48 */
49 public function tag(): int
50 {
51 return $this->tag;
52 }
53
54 /**
55 * Generate ASN.1 structure.
56 */
57 public function toASN1(): ImplicitlyTaggedType
58 {
59 return ImplicitlyTaggedType::create($this->tag, $this->_valueASN1());
60 }
61
62 /**
63 * Generate ASN.1 element.
64 */
65 abstract protected function _valueASN1(): Element;
66 }