Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/GeneralName/DirectoryName.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\GeneralName;
6
7 use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType;
8 use SpomkyLabs\Pki\ASN1\Type\TaggedType;
9 use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
10 use SpomkyLabs\Pki\X501\ASN1\Name;
11
12 /**
13 * Implements *directoryName* CHOICE type of *GeneralName*.
14 *
15 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.6
16 */
17 final class DirectoryName extends GeneralName
18 {
19 private function __construct(
20 private readonly Name $directoryName
21 ) {
22 parent::__construct(self::TAG_DIRECTORY_NAME);
23 }
24
25 public static function create(Name $directoryName): self
26 {
27 return new self($directoryName);
28 }
29
30 /**
31 * @return self
32 */
33 public static function fromChosenASN1(UnspecifiedType $el): GeneralName
34 {
35 return self::create(Name::fromASN1($el->asSequence()));
36 }
37
38 /**
39 * Initialize from distinguished name string.
40 */
41 public static function fromDNString(string $str): self
42 {
43 return self::create(Name::fromString($str));
44 }
45
46 public function string(): string
47 {
48 return $this->directoryName->toString();
49 }
50
51 /**
52 * Get directory name.
53 */
54 public function dn(): Name
55 {
56 return $this->directoryName;
57 }
58
59 protected function choiceASN1(): TaggedType
60 {
61 // Name type is itself a CHOICE, so explicit tagging must be
62 // employed to avoid ambiguities
63 return ExplicitlyTaggedType::create($this->tag, $this->directoryName->toASN1());
64 }
65 }