@@ -15,106 +15,106 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ConstructedString extends Structure implements Stringable |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @internal Use create() |
|
| 22 | - * |
|
| 23 | - * @param Element ...$elements Any number of elements |
|
| 24 | - */ |
|
| 25 | - public function __construct(Element ...$elements) |
|
| 26 | - { |
|
| 27 | - parent::__construct(...$elements); |
|
| 28 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @internal Use create() |
|
| 22 | + * |
|
| 23 | + * @param Element ...$elements Any number of elements |
|
| 24 | + */ |
|
| 25 | + public function __construct(Element ...$elements) |
|
| 26 | + { |
|
| 27 | + parent::__construct(...$elements); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Create from a list of string type elements |
|
| 32 | - * |
|
| 33 | - * All strings must have the same type. |
|
| 34 | - * |
|
| 35 | - * @param StringType ...$elements |
|
| 36 | - * @throws \LogicException |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function create(StringType ...$elements): self |
|
| 40 | - { |
|
| 41 | - if (!count($elements)) { |
|
| 42 | - throw new \LogicException( |
|
| 43 | - 'No elements, unable to determine type tag.'); |
|
| 44 | - } |
|
| 45 | - $tag = $elements[0]->tag(); |
|
| 46 | - foreach ($elements as $el) { |
|
| 47 | - if ($el->tag() !== $tag) { |
|
| 48 | - throw new \LogicException( |
|
| 49 | - 'All elements in constructed string must have the same type.'); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - return self::createWithTag($tag, ...$elements); |
|
| 53 | - } |
|
| 30 | + /** |
|
| 31 | + * Create from a list of string type elements |
|
| 32 | + * |
|
| 33 | + * All strings must have the same type. |
|
| 34 | + * |
|
| 35 | + * @param StringType ...$elements |
|
| 36 | + * @throws \LogicException |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function create(StringType ...$elements): self |
|
| 40 | + { |
|
| 41 | + if (!count($elements)) { |
|
| 42 | + throw new \LogicException( |
|
| 43 | + 'No elements, unable to determine type tag.'); |
|
| 44 | + } |
|
| 45 | + $tag = $elements[0]->tag(); |
|
| 46 | + foreach ($elements as $el) { |
|
| 47 | + if ($el->tag() !== $tag) { |
|
| 48 | + throw new \LogicException( |
|
| 49 | + 'All elements in constructed string must have the same type.'); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + return self::createWithTag($tag, ...$elements); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Create from strings with a given type tag. |
|
| 57 | - * |
|
| 58 | - * @param int $tag Type tag for the constructed string element |
|
| 59 | - * @param StringType ...$elements Any number of elements |
|
| 60 | - * @return self |
|
| 61 | - */ |
|
| 62 | - public static function createWithTag(int $tag, StringType ...$elements) |
|
| 63 | - { |
|
| 64 | - $el = new self(...$elements); |
|
| 65 | - $el->_typeTag = $tag; |
|
| 66 | - return $el; |
|
| 67 | - } |
|
| 55 | + /** |
|
| 56 | + * Create from strings with a given type tag. |
|
| 57 | + * |
|
| 58 | + * @param int $tag Type tag for the constructed string element |
|
| 59 | + * @param StringType ...$elements Any number of elements |
|
| 60 | + * @return self |
|
| 61 | + */ |
|
| 62 | + public static function createWithTag(int $tag, StringType ...$elements) |
|
| 63 | + { |
|
| 64 | + $el = new self(...$elements); |
|
| 65 | + $el->_typeTag = $tag; |
|
| 66 | + return $el; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Get a list of strings in this structure. |
|
| 71 | - * |
|
| 72 | - * @return string[] |
|
| 73 | - */ |
|
| 74 | - public function strings(): array |
|
| 75 | - { |
|
| 76 | - return array_map(function (StringType $el) { |
|
| 77 | - return $el->string(); |
|
| 78 | - }, $this->_elements); |
|
| 79 | - } |
|
| 69 | + /** |
|
| 70 | + * Get a list of strings in this structure. |
|
| 71 | + * |
|
| 72 | + * @return string[] |
|
| 73 | + */ |
|
| 74 | + public function strings(): array |
|
| 75 | + { |
|
| 76 | + return array_map(function (StringType $el) { |
|
| 77 | + return $el->string(); |
|
| 78 | + }, $this->_elements); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Get the contained strings concatenated together. |
|
| 83 | - * |
|
| 84 | - * NOTE: It's unclear how bit strings with unused bits should be |
|
| 85 | - * concatentated. |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function string(): string |
|
| 90 | - { |
|
| 91 | - return implode('', $this->strings()); |
|
| 92 | - } |
|
| 81 | + /** |
|
| 82 | + * Get the contained strings concatenated together. |
|
| 83 | + * |
|
| 84 | + * NOTE: It's unclear how bit strings with unused bits should be |
|
| 85 | + * concatentated. |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function string(): string |
|
| 90 | + { |
|
| 91 | + return implode('', $this->strings()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * |
|
| 96 | - * {@inheritdoc} |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function __toString(): string |
|
| 101 | - { |
|
| 102 | - return $this->string(); |
|
| 103 | - } |
|
| 94 | + /** |
|
| 95 | + * |
|
| 96 | + * {@inheritdoc} |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function __toString(): string |
|
| 101 | + { |
|
| 102 | + return $this->string(); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * |
|
| 107 | - * {@inheritdoc} |
|
| 108 | - * |
|
| 109 | - * @return self |
|
| 110 | - */ |
|
| 111 | - protected static function _decodeFromDER(Identifier $identifier, |
|
| 112 | - string $data, int &$offset): ElementBase |
|
| 113 | - { |
|
| 114 | - /** @var ConstructedString $type */ |
|
| 115 | - $type = forward_static_call_array([parent::class, __FUNCTION__], |
|
| 116 | - [$identifier, $data, &$offset]); |
|
| 117 | - $type->_typeTag = $identifier->intTag(); |
|
| 118 | - return $type; |
|
| 119 | - } |
|
| 105 | + /** |
|
| 106 | + * |
|
| 107 | + * {@inheritdoc} |
|
| 108 | + * |
|
| 109 | + * @return self |
|
| 110 | + */ |
|
| 111 | + protected static function _decodeFromDER(Identifier $identifier, |
|
| 112 | + string $data, int &$offset): ElementBase |
|
| 113 | + { |
|
| 114 | + /** @var ConstructedString $type */ |
|
| 115 | + $type = forward_static_call_array([parent::class, __FUNCTION__], |
|
| 116 | + [$identifier, $data, &$offset]); |
|
| 117 | + $type->_typeTag = $identifier->intTag(); |
|
| 118 | + return $type; |
|
| 119 | + } |
|
| 120 | 120 | } |