Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/GeneralName/OtherName.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\Element;
8 use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
9 use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier;
10 use SpomkyLabs\Pki\ASN1\Type\Tagged\ExplicitlyTaggedType;
11 use SpomkyLabs\Pki\ASN1\Type\Tagged\ImplicitlyTaggedType;
12 use SpomkyLabs\Pki\ASN1\Type\TaggedType;
13 use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
14
15 /**
16 * Implements *otherName* CHOICE type of *GeneralName*.
17 *
18 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.6
19 */
20 final class OtherName extends GeneralName
21 {
22 /**
23 * @param string $type OID
24 */
25 private function __construct(
26 private readonly string $type,
27 private readonly Element $element
28 ) {
29 parent::__construct(self::TAG_OTHER_NAME);
30 }
31
32 public static function create(string $type, Element $element): self
33 {
34 return new self($type, $element);
35 }
36
37 /**
38 * @return self
39 */
40 public static function fromChosenASN1(UnspecifiedType $el): GeneralName
41 {
42 $seq = $el->asSequence();
43 $type_id = $seq->at(0)
44 ->asObjectIdentifier()
45 ->oid();
46 $value = $seq->getTagged(0)
47 ->asExplicit()
48 ->asElement();
49 return self::create($type_id, $value);
50 }
51
52 public function string(): string
53 {
54 return $this->type . '/#' . bin2hex($this->element->toDER());
55 }
56
57 /**
58 * Get type OID.
59 */
60 public function type(): string
61 {
62 return $this->type;
63 }
64
65 /**
66 * Get value element.
67 */
68 public function value(): Element
69 {
70 return $this->element;
71 }
72
73 protected function choiceASN1(): TaggedType
74 {
75 return ImplicitlyTaggedType::create(
76 $this->tag,
77 Sequence::create(ObjectIdentifier::create($this->type), ExplicitlyTaggedType::create(0, $this->element))
78 );
79 }
80 }