|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Sop\X509\GeneralName; |
|
6
|
|
|
|
|
7
|
|
|
use Sop\ASN1\Element; |
|
8
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
|
9
|
|
|
use Sop\ASN1\Type\Primitive\ObjectIdentifier; |
|
10
|
|
|
use Sop\ASN1\Type\Tagged\ExplicitlyTaggedType; |
|
11
|
|
|
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType; |
|
12
|
|
|
use Sop\ASN1\Type\TaggedType; |
|
13
|
|
|
use Sop\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
|
|
|
class OtherName extends GeneralName |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Type OID. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $_type; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Value. |
|
31
|
|
|
* |
|
32
|
|
|
* @var Element |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $_element; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $type_id OID |
|
40
|
|
|
* @param Element $el |
|
41
|
|
|
*/ |
|
42
|
10 |
|
public function __construct(string $type_id, Element $el) |
|
43
|
|
|
{ |
|
44
|
10 |
|
$this->_tag = self::TAG_OTHER_NAME; |
|
45
|
10 |
|
$this->_type = $type_id; |
|
46
|
10 |
|
$this->_element = $el; |
|
47
|
10 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
* |
|
52
|
|
|
* @return self |
|
53
|
|
|
*/ |
|
54
|
9 |
|
public static function fromChosenASN1(UnspecifiedType $el): GeneralName |
|
55
|
|
|
{ |
|
56
|
9 |
|
$seq = $el->asSequence(); |
|
57
|
9 |
|
$type_id = $seq->at(0)->asObjectIdentifier()->oid(); |
|
58
|
9 |
|
$value = $seq->getTagged(0)->asExplicit()->asElement(); |
|
59
|
9 |
|
return new self($type_id, $value); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function string(): string |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->_type . '/#' . bin2hex($this->_element->toDER()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get type OID. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function type(): string |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->_type; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get value element. |
|
82
|
|
|
* |
|
83
|
|
|
* @return Element |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function value(): Element |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->_element; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
15 |
|
protected function _choiceASN1(): TaggedType |
|
94
|
|
|
{ |
|
95
|
15 |
|
return new ImplicitlyTaggedType($this->_tag, |
|
96
|
15 |
|
new Sequence(new ObjectIdentifier($this->_type), |
|
97
|
15 |
|
new ExplicitlyTaggedType(0, $this->_element))); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|