Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\Certificate\Extension\Target;
6
7 use SpomkyLabs\Pki\ASN1\Element;
8 use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType;
9 use SpomkyLabs\Pki\ASN1\Type\TaggedType;
10 use SpomkyLabs\Pki\X509\GeneralName\GeneralName;
11
12 /**
13 * Implements 'targetName' CHOICE of the *Target* ASN.1 type.
14 *
15 * @see https://tools.ietf.org/html/rfc5755#section-4.3.2
16 */
17 final class TargetName extends Target
18 {
19 private function __construct(
20 private readonly GeneralName $name
21 ) {
22 parent::__construct(self::TYPE_NAME);
23 }
24
25 public static function create(GeneralName $name): self
26 {
27 return new self($name);
28 }
29
30 /**
31 * @return self
32 */
33 public static function fromChosenASN1(TaggedType $el): Target
34 {
35 return self::create(GeneralName::fromASN1($el));
36 }
37
38 public function string(): string
39 {
40 return $this->name->string();
41 }
42
43 public function name(): GeneralName
44 {
45 return $this->name;
46 }
47
48 public function toASN1(): Element
49 {
50 return ExplicitlyTaggedType::create($this->type, $this->name->toASN1());
51 }
52 }