1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace ASN1\Type\Constructed; |
6
|
|
|
|
7
|
|
|
use ASN1\Component\Identifier; |
8
|
|
|
use ASN1\Element; |
9
|
|
|
use ASN1\Feature\ElementBase; |
10
|
|
|
use ASN1\Type\PrimitiveString; |
11
|
|
|
use ASN1\Type\Structure; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Implements constructed type of simple strings. |
15
|
|
|
*/ |
16
|
|
|
class ConstructedString extends Structure |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Constructor. |
20
|
|
|
* |
21
|
|
|
* @param Element ...$elements Any number of elements |
22
|
|
|
*/ |
23
|
|
|
protected function __construct(Element ...$elements) |
24
|
|
|
{ |
25
|
|
|
parent::__construct(...$elements); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create constructed string. |
30
|
|
|
* |
31
|
|
|
* @param int $tag Type tag |
32
|
|
|
* @param PrimitiveString ...$elements Any number of elements |
33
|
|
|
*/ |
34
|
|
|
public static function create(int $tag, PrimitiveString ...$elements) |
35
|
|
|
{ |
36
|
|
|
$el = new self(...$elements); |
37
|
|
|
$el->_typeTag = $tag; |
38
|
|
|
return $el; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get a list of strings in this structure. |
43
|
|
|
* |
44
|
|
|
* @return string[] |
45
|
|
|
*/ |
46
|
|
|
public function strings(): array |
47
|
|
|
{ |
48
|
|
|
return array_map(function (PrimitiveString $el) { |
49
|
|
|
return $el->string(); |
50
|
|
|
}, $this->_elements); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the contained strings concatenated together. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function concatenated(): string |
59
|
|
|
{ |
60
|
|
|
return implode('', $this->strings()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
* |
66
|
|
|
* @return self |
67
|
|
|
*/ |
68
|
|
|
protected static function _decodeFromDER( |
69
|
|
|
Identifier $identifier, |
70
|
|
|
string $data, |
71
|
|
|
int &$offset |
72
|
|
|
): ElementBase { |
73
|
|
|
/** @var ConstructedString $type */ |
74
|
|
|
$type = forward_static_call_array( |
75
|
|
|
[parent::class, __FUNCTION__], |
76
|
|
|
[$identifier, $data, &$offset] |
77
|
|
|
); |
78
|
|
|
$type->_typeTag = $identifier->intTag(); |
79
|
|
|
return $type; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|