@@ -12,24 +12,24 @@ |
||
12 | 12 | */ |
13 | 13 | class VisibleString extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_VISIBLE_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_VISIBLE_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - return 0 == preg_match('/[^\x20-\x7e]/', $string); |
|
34 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + return 0 == preg_match('/[^\x20-\x7e]/', $string); |
|
34 | + } |
|
35 | 35 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -17,38 +17,38 @@ |
||
17 | 17 | */ |
18 | 18 | class EOC extends Element |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->_typeTag = self::TYPE_EOC; |
|
29 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->_typeTag = self::TYPE_EOC; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _encodedContentDER(): string |
|
35 | - { |
|
36 | - return ''; |
|
37 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _encodedContentDER(): string |
|
35 | + { |
|
36 | + return ''; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - protected static function _decodeFromDER(Identifier $identifier, |
|
43 | - string $data, int &$offset): ElementBase |
|
44 | - { |
|
45 | - $idx = $offset; |
|
46 | - if (!$identifier->isPrimitive()) { |
|
47 | - throw new DecodeException('EOC value must be primitive.'); |
|
48 | - } |
|
49 | - // EOC type has always zero length |
|
50 | - Length::expectFromDER($data, $idx, 0); |
|
51 | - $offset = $idx; |
|
52 | - return new self(); |
|
53 | - } |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + protected static function _decodeFromDER(Identifier $identifier, |
|
43 | + string $data, int &$offset): ElementBase |
|
44 | + { |
|
45 | + $idx = $offset; |
|
46 | + if (!$identifier->isPrimitive()) { |
|
47 | + throw new DecodeException('EOC value must be primitive.'); |
|
48 | + } |
|
49 | + // EOC type has always zero length |
|
50 | + Length::expectFromDER($data, $idx, 0); |
|
51 | + $offset = $idx; |
|
52 | + return new self(); |
|
53 | + } |
|
54 | 54 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -12,25 +12,25 @@ |
||
12 | 12 | */ |
13 | 13 | class VideotexString extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything |
|
34 | - return true; |
|
35 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -15,28 +15,28 @@ |
||
15 | 15 | */ |
16 | 16 | class BMPString extends PrimitiveString |
17 | 17 | { |
18 | - use UniversalClass; |
|
18 | + use UniversalClass; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor. |
|
22 | - * |
|
23 | - * @param string $string |
|
24 | - */ |
|
25 | - public function __construct(string $string) |
|
26 | - { |
|
27 | - $this->_typeTag = self::TYPE_BMP_STRING; |
|
28 | - parent::__construct($string); |
|
29 | - } |
|
20 | + /** |
|
21 | + * Constructor. |
|
22 | + * |
|
23 | + * @param string $string |
|
24 | + */ |
|
25 | + public function __construct(string $string) |
|
26 | + { |
|
27 | + $this->_typeTag = self::TYPE_BMP_STRING; |
|
28 | + parent::__construct($string); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _validateString(string $string): bool |
|
35 | - { |
|
36 | - // UCS-2 has fixed with of 2 octets (16 bits) |
|
37 | - if (0 !== strlen($string) % 2) { |
|
38 | - return false; |
|
39 | - } |
|
40 | - return true; |
|
41 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _validateString(string $string): bool |
|
35 | + { |
|
36 | + // UCS-2 has fixed with of 2 octets (16 bits) |
|
37 | + if (0 !== strlen($string) % 2) { |
|
38 | + return false; |
|
39 | + } |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -13,36 +13,36 @@ |
||
13 | 13 | */ |
14 | 14 | class RelativeOID extends ObjectIdentifier |
15 | 15 | { |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $oid OID in dotted format |
|
20 | - */ |
|
21 | - public function __construct(string $oid) |
|
22 | - { |
|
23 | - $this->_oid = $oid; |
|
24 | - $this->_subids = self::_explodeDottedOID($oid); |
|
25 | - $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $oid OID in dotted format |
|
20 | + */ |
|
21 | + public function __construct(string $oid) |
|
22 | + { |
|
23 | + $this->_oid = $oid; |
|
24 | + $this->_subids = self::_explodeDottedOID($oid); |
|
25 | + $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _encodedContentDER(): string |
|
32 | - { |
|
33 | - return self::_encodeSubIDs(...$this->_subids); |
|
34 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _encodedContentDER(): string |
|
32 | + { |
|
33 | + return self::_encodeSubIDs(...$this->_subids); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * {@inheritdoc} |
|
38 | - */ |
|
39 | - protected static function _decodeFromDER(Identifier $identifier, |
|
40 | - string $data, int &$offset): ElementBase |
|
41 | - { |
|
42 | - $idx = $offset; |
|
43 | - $len = Length::expectFromDER($data, $idx)->intLength(); |
|
44 | - $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | - $offset = $idx + $len; |
|
46 | - return new self(self::_implodeSubIDs(...$subids)); |
|
47 | - } |
|
36 | + /** |
|
37 | + * {@inheritdoc} |
|
38 | + */ |
|
39 | + protected static function _decodeFromDER(Identifier $identifier, |
|
40 | + string $data, int &$offset): ElementBase |
|
41 | + { |
|
42 | + $idx = $offset; |
|
43 | + $len = Length::expectFromDER($data, $idx)->intLength(); |
|
44 | + $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | + $offset = $idx + $len; |
|
46 | + return new self(self::_implodeSubIDs(...$subids)); |
|
47 | + } |
|
48 | 48 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -12,25 +12,25 @@ |
||
12 | 12 | */ |
13 | 13 | class GraphicString extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_GRAPHIC_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_GRAPHIC_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything |
|
34 | - return true; |
|
35 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -9,13 +9,13 @@ |
||
9 | 9 | */ |
10 | 10 | trait PrimitiveType |
11 | 11 | { |
12 | - /** |
|
13 | - * @see \Sop\ASN1\Feature\ElementBase::isConstructed() |
|
14 | - * |
|
15 | - * @return bool |
|
16 | - */ |
|
17 | - public function isConstructed(): bool |
|
18 | - { |
|
19 | - return false; |
|
20 | - } |
|
12 | + /** |
|
13 | + * @see \Sop\ASN1\Feature\ElementBase::isConstructed() |
|
14 | + * |
|
15 | + * @return bool |
|
16 | + */ |
|
17 | + public function isConstructed(): bool |
|
18 | + { |
|
19 | + return false; |
|
20 | + } |
|
21 | 21 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type; |
6 | 6 |
@@ -14,79 +14,79 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class TaggedType extends Element |
16 | 16 | { |
17 | - /** |
|
18 | - * Check whether element supports explicit tagging. |
|
19 | - * |
|
20 | - * @param null|int $expectedTag Optional outer tag expectation |
|
21 | - * |
|
22 | - * @throws \UnexpectedValueException If expectation fails |
|
23 | - * |
|
24 | - * @return ExplicitTagging |
|
25 | - */ |
|
26 | - public function expectExplicit(?int $expectedTag = null): ExplicitTagging |
|
27 | - { |
|
28 | - $el = $this; |
|
29 | - if (!$el instanceof ExplicitTagging) { |
|
30 | - throw new \UnexpectedValueException( |
|
31 | - "Element doesn't implement explicit tagging."); |
|
32 | - } |
|
33 | - if (isset($expectedTag)) { |
|
34 | - $el->expectTagged($expectedTag); |
|
35 | - } |
|
36 | - return $el; |
|
37 | - } |
|
17 | + /** |
|
18 | + * Check whether element supports explicit tagging. |
|
19 | + * |
|
20 | + * @param null|int $expectedTag Optional outer tag expectation |
|
21 | + * |
|
22 | + * @throws \UnexpectedValueException If expectation fails |
|
23 | + * |
|
24 | + * @return ExplicitTagging |
|
25 | + */ |
|
26 | + public function expectExplicit(?int $expectedTag = null): ExplicitTagging |
|
27 | + { |
|
28 | + $el = $this; |
|
29 | + if (!$el instanceof ExplicitTagging) { |
|
30 | + throw new \UnexpectedValueException( |
|
31 | + "Element doesn't implement explicit tagging."); |
|
32 | + } |
|
33 | + if (isset($expectedTag)) { |
|
34 | + $el->expectTagged($expectedTag); |
|
35 | + } |
|
36 | + return $el; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the wrapped inner element employing explicit tagging. |
|
41 | - * |
|
42 | - * @param null|int $expectedTag Optional outer tag expectation |
|
43 | - * |
|
44 | - * @throws \UnexpectedValueException If expectation fails |
|
45 | - * |
|
46 | - * @return UnspecifiedType |
|
47 | - */ |
|
48 | - public function asExplicit(?int $expectedTag = null): UnspecifiedType |
|
49 | - { |
|
50 | - return $this->expectExplicit($expectedTag)->explicit(); |
|
51 | - } |
|
39 | + /** |
|
40 | + * Get the wrapped inner element employing explicit tagging. |
|
41 | + * |
|
42 | + * @param null|int $expectedTag Optional outer tag expectation |
|
43 | + * |
|
44 | + * @throws \UnexpectedValueException If expectation fails |
|
45 | + * |
|
46 | + * @return UnspecifiedType |
|
47 | + */ |
|
48 | + public function asExplicit(?int $expectedTag = null): UnspecifiedType |
|
49 | + { |
|
50 | + return $this->expectExplicit($expectedTag)->explicit(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Check whether element supports implicit tagging. |
|
55 | - * |
|
56 | - * @param null|int $expectedTag Optional outer tag expectation |
|
57 | - * |
|
58 | - * @throws \UnexpectedValueException If expectation fails |
|
59 | - * |
|
60 | - * @return ImplicitTagging |
|
61 | - */ |
|
62 | - public function expectImplicit(?int $expectedTag = null): ImplicitTagging |
|
63 | - { |
|
64 | - $el = $this; |
|
65 | - if (!$el instanceof ImplicitTagging) { |
|
66 | - throw new \UnexpectedValueException( |
|
67 | - "Element doesn't implement implicit tagging."); |
|
68 | - } |
|
69 | - if (isset($expectedTag)) { |
|
70 | - $el->expectTagged($expectedTag); |
|
71 | - } |
|
72 | - return $el; |
|
73 | - } |
|
53 | + /** |
|
54 | + * Check whether element supports implicit tagging. |
|
55 | + * |
|
56 | + * @param null|int $expectedTag Optional outer tag expectation |
|
57 | + * |
|
58 | + * @throws \UnexpectedValueException If expectation fails |
|
59 | + * |
|
60 | + * @return ImplicitTagging |
|
61 | + */ |
|
62 | + public function expectImplicit(?int $expectedTag = null): ImplicitTagging |
|
63 | + { |
|
64 | + $el = $this; |
|
65 | + if (!$el instanceof ImplicitTagging) { |
|
66 | + throw new \UnexpectedValueException( |
|
67 | + "Element doesn't implement implicit tagging."); |
|
68 | + } |
|
69 | + if (isset($expectedTag)) { |
|
70 | + $el->expectTagged($expectedTag); |
|
71 | + } |
|
72 | + return $el; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get the wrapped inner element employing implicit tagging. |
|
77 | - * |
|
78 | - * @param int $tag Type tag of the inner element |
|
79 | - * @param null|int $expectedTag Optional outer tag expectation |
|
80 | - * @param int $expectedClass Optional inner type class expectation |
|
81 | - * |
|
82 | - * @throws \UnexpectedValueException If expectation fails |
|
83 | - * |
|
84 | - * @return UnspecifiedType |
|
85 | - */ |
|
86 | - public function asImplicit(int $tag, ?int $expectedTag = null, |
|
87 | - int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
88 | - { |
|
89 | - return $this->expectImplicit($expectedTag)->implicit($tag, |
|
90 | - $expectedClass); |
|
91 | - } |
|
75 | + /** |
|
76 | + * Get the wrapped inner element employing implicit tagging. |
|
77 | + * |
|
78 | + * @param int $tag Type tag of the inner element |
|
79 | + * @param null|int $expectedTag Optional outer tag expectation |
|
80 | + * @param int $expectedClass Optional inner type class expectation |
|
81 | + * |
|
82 | + * @throws \UnexpectedValueException If expectation fails |
|
83 | + * |
|
84 | + * @return UnspecifiedType |
|
85 | + */ |
|
86 | + public function asImplicit(int $tag, ?int $expectedTag = null, |
|
87 | + int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
88 | + { |
|
89 | + return $this->expectImplicit($expectedTag)->implicit($tag, |
|
90 | + $expectedClass); |
|
91 | + } |
|
92 | 92 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type; |
6 | 6 |
@@ -11,50 +11,50 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class StringType extends Element |
13 | 13 | { |
14 | - /** |
|
15 | - * String value. |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $_string; |
|
14 | + /** |
|
15 | + * String value. |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $_string; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param string $string |
|
25 | - * |
|
26 | - * @throws \InvalidArgumentException |
|
27 | - */ |
|
28 | - public function __construct(string $string) |
|
29 | - { |
|
30 | - if (!$this->_validateString($string)) { |
|
31 | - throw new \InvalidArgumentException( |
|
32 | - sprintf('Not a valid %s string.', |
|
33 | - self::tagToName($this->_typeTag))); |
|
34 | - } |
|
35 | - $this->_string = $string; |
|
36 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param string $string |
|
25 | + * |
|
26 | + * @throws \InvalidArgumentException |
|
27 | + */ |
|
28 | + public function __construct(string $string) |
|
29 | + { |
|
30 | + if (!$this->_validateString($string)) { |
|
31 | + throw new \InvalidArgumentException( |
|
32 | + sprintf('Not a valid %s string.', |
|
33 | + self::tagToName($this->_typeTag))); |
|
34 | + } |
|
35 | + $this->_string = $string; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the string value. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function string(): string |
|
44 | - { |
|
45 | - return $this->_string; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Get the string value. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function string(): string |
|
44 | + { |
|
45 | + return $this->_string; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Check whether string is valid for the concrete type. |
|
50 | - * |
|
51 | - * @param string $string |
|
52 | - * |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - protected function _validateString(string $string): bool |
|
56 | - { |
|
57 | - // Override in derived classes |
|
58 | - return true; |
|
59 | - } |
|
48 | + /** |
|
49 | + * Check whether string is valid for the concrete type. |
|
50 | + * |
|
51 | + * @param string $string |
|
52 | + * |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + protected function _validateString(string $string): bool |
|
56 | + { |
|
57 | + // Override in derived classes |
|
58 | + return true; |
|
59 | + } |
|
60 | 60 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type; |
6 | 6 |