@@ -14,61 +14,61 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class PrimitiveString extends StringType |
16 | 16 | { |
17 | - use PrimitiveType; |
|
17 | + use PrimitiveType; |
|
18 | 18 | |
19 | - /** |
|
20 | - * |
|
21 | - * @see \ASN1\Element::_encodedContentDER() |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - protected function _encodedContentDER(): string |
|
25 | - { |
|
26 | - return $this->_string; |
|
27 | - } |
|
19 | + /** |
|
20 | + * |
|
21 | + * @see \ASN1\Element::_encodedContentDER() |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + protected function _encodedContentDER(): string |
|
25 | + { |
|
26 | + return $this->_string; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * |
|
31 | - * {@inheritdoc} |
|
32 | - * @see \ASN1\Element::_decodeFromDER() |
|
33 | - * @return self |
|
34 | - */ |
|
35 | - protected static function _decodeFromDER(Identifier $identifier, |
|
36 | - string $data, int &$offset): ElementBase |
|
37 | - { |
|
38 | - $idx = $offset; |
|
39 | - if (!$identifier->isPrimitive()) { |
|
40 | - $length = Length::expectFromDER($data, $idx); |
|
29 | + /** |
|
30 | + * |
|
31 | + * {@inheritdoc} |
|
32 | + * @see \ASN1\Element::_decodeFromDER() |
|
33 | + * @return self |
|
34 | + */ |
|
35 | + protected static function _decodeFromDER(Identifier $identifier, |
|
36 | + string $data, int &$offset): ElementBase |
|
37 | + { |
|
38 | + $idx = $offset; |
|
39 | + if (!$identifier->isPrimitive()) { |
|
40 | + $length = Length::expectFromDER($data, $idx); |
|
41 | 41 | |
42 | - /* |
|
42 | + /* |
|
43 | 43 | * A primitive string is not a constructed type by definition. |
44 | 44 | * Alas, if it is encoded as constructed type (0x24), we expect that |
45 | 45 | * some primitive OCTET_STRINGs follow. So loop over them, create a |
46 | 46 | * concatenated big string and return it. |
47 | 47 | */ |
48 | - if ($length->isIndefinite()) { |
|
49 | - $str = ''; |
|
50 | - do { |
|
51 | - $offset = $idx; |
|
52 | - $element = Element::fromDER($data, $offset); |
|
53 | - if ($element instanceof PrimitiveString) { |
|
54 | - $str .= $element->string(); |
|
55 | - $idx = $offset; |
|
56 | - } |
|
57 | - } while ($element instanceof PrimitiveString); |
|
58 | - return new static($str); |
|
59 | - } |
|
60 | - } else { |
|
61 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
62 | - } |
|
63 | - $str = $length ? substr($data, $idx, $length) : ""; |
|
64 | - // substr should never return false, since length is |
|
65 | - // checked by Length::expectFromDER. |
|
66 | - assert(is_string($str), new DecodeException("substr")); |
|
67 | - $offset = $idx + $length; |
|
68 | - try { |
|
69 | - return new static($str); |
|
70 | - } catch (\InvalidArgumentException $e) { |
|
71 | - throw new DecodeException($e->getMessage(), 0, $e); |
|
72 | - } |
|
73 | - } |
|
48 | + if ($length->isIndefinite()) { |
|
49 | + $str = ''; |
|
50 | + do { |
|
51 | + $offset = $idx; |
|
52 | + $element = Element::fromDER($data, $offset); |
|
53 | + if ($element instanceof PrimitiveString) { |
|
54 | + $str .= $element->string(); |
|
55 | + $idx = $offset; |
|
56 | + } |
|
57 | + } while ($element instanceof PrimitiveString); |
|
58 | + return new static($str); |
|
59 | + } |
|
60 | + } else { |
|
61 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
62 | + } |
|
63 | + $str = $length ? substr($data, $idx, $length) : ""; |
|
64 | + // substr should never return false, since length is |
|
65 | + // checked by Length::expectFromDER. |
|
66 | + assert(is_string($str), new DecodeException("substr")); |
|
67 | + $offset = $idx + $length; |
|
68 | + try { |
|
69 | + return new static($str); |
|
70 | + } catch (\InvalidArgumentException $e) { |
|
71 | + throw new DecodeException($e->getMessage(), 0, $e); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | } |