Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/GeneralName/DNSName.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\Primitive\IA5String;
8 use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType;
9 use SpomkyLabs\Pki\ASN1\Type\TaggedType;
10 use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
11
12 /**
13 * Implements *dNSName* CHOICE type of *GeneralName*.
14 *
15 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.6
16 */
17 final class DNSName extends GeneralName
18 {
19 /**
20 * @param string $name Domain name
21 */
22 private function __construct(
23 private readonly string $name
24 ) {
25 parent::__construct(self::TAG_DNS_NAME);
26 }
27
28 public static function create(string $name): self
29 {
30 return new self($name);
31 }
32
33 /**
34 * @return self
35 */
36 public static function fromChosenASN1(UnspecifiedType $el): GeneralName
37 {
38 return self::create($el->asIA5String()->string());
39 }
40
41 public function string(): string
42 {
43 return $this->name;
44 }
45
46 /**
47 * Get DNS name.
48 */
49 public function name(): string
50 {
51 return $this->name;
52 }
53
54 protected function choiceASN1(): TaggedType
55 {
56 return ImplicitlyTaggedType::create($this->tag, IA5String::create($this->name));
57 }
58 }