@@ -14,29 +14,29 @@ |
||
14 | 14 | */ |
15 | 15 | class UniversalString extends PrimitiveString |
16 | 16 | { |
17 | - use UniversalClass; |
|
17 | + use UniversalClass; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param string $string |
|
23 | - */ |
|
24 | - public function __construct(string $string) |
|
25 | - { |
|
26 | - $this->_typeTag = self::TYPE_UNIVERSAL_STRING; |
|
27 | - parent::__construct($string); |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param string $string |
|
23 | + */ |
|
24 | + public function __construct(string $string) |
|
25 | + { |
|
26 | + $this->_typeTag = self::TYPE_UNIVERSAL_STRING; |
|
27 | + parent::__construct($string); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _validateString(string $string): bool |
|
35 | - { |
|
36 | - // UCS-4 has fixed with of 4 octets (32 bits) |
|
37 | - if (strlen($string) % 4 != 0) { |
|
38 | - return false; |
|
39 | - } |
|
40 | - return true; |
|
41 | - } |
|
30 | + /** |
|
31 | + * |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _validateString(string $string): bool |
|
35 | + { |
|
36 | + // UCS-4 has fixed with of 4 octets (32 bits) |
|
37 | + if (strlen($string) % 4 != 0) { |
|
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 ASN1\Type\Primitive; |
6 | 6 |
@@ -14,25 +14,25 @@ |
||
14 | 14 | */ |
15 | 15 | class UTF8String extends PrimitiveString |
16 | 16 | { |
17 | - use UniversalClass; |
|
17 | + use UniversalClass; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param string $string |
|
23 | - */ |
|
24 | - public function __construct(string $string) |
|
25 | - { |
|
26 | - $this->_typeTag = self::TYPE_UTF8_STRING; |
|
27 | - parent::__construct($string); |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param string $string |
|
23 | + */ |
|
24 | + public function __construct(string $string) |
|
25 | + { |
|
26 | + $this->_typeTag = self::TYPE_UTF8_STRING; |
|
27 | + parent::__construct($string); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _validateString(string $string): bool |
|
35 | - { |
|
36 | - return mb_check_encoding($string, "UTF-8"); |
|
37 | - } |
|
30 | + /** |
|
31 | + * |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _validateString(string $string): bool |
|
35 | + { |
|
36 | + return mb_check_encoding($string, "UTF-8"); |
|
37 | + } |
|
38 | 38 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -12,27 +12,27 @@ |
||
12 | 12 | */ |
13 | 13 | class T61String 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_T61_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_T61_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected function _validateString(string $string): bool |
|
33 | - { |
|
34 | - // allow everything since there's literally |
|
35 | - // thousands of allowed characters (16 bit composed characters) |
|
36 | - return true; |
|
37 | - } |
|
28 | + /** |
|
29 | + * |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected function _validateString(string $string): bool |
|
33 | + { |
|
34 | + // allow everything since there's literally |
|
35 | + // thousands of allowed characters (16 bit composed characters) |
|
36 | + return true; |
|
37 | + } |
|
38 | 38 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -12,25 +12,25 @@ |
||
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 | - * |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected function _validateString(string $string): bool |
|
33 | - { |
|
34 | - return preg_match('/[^\x20-\x7e]/', $string) == 0; |
|
35 | - } |
|
28 | + /** |
|
29 | + * |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected function _validateString(string $string): bool |
|
33 | + { |
|
34 | + return preg_match('/[^\x20-\x7e]/', $string) == 0; |
|
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 ASN1\Type\Primitive; |
6 | 6 |
@@ -12,26 +12,26 @@ |
||
12 | 12 | */ |
13 | 13 | class ObjectDescriptor extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $descriptor |
|
21 | - */ |
|
22 | - public function __construct(string $descriptor) |
|
23 | - { |
|
24 | - $this->_string = $descriptor; |
|
25 | - $this->_typeTag = self::TYPE_OBJECT_DESCRIPTOR; |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $descriptor |
|
21 | + */ |
|
22 | + public function __construct(string $descriptor) |
|
23 | + { |
|
24 | + $this->_string = $descriptor; |
|
25 | + $this->_typeTag = self::TYPE_OBJECT_DESCRIPTOR; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Get the object descriptor. |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function descriptor(): string |
|
34 | - { |
|
35 | - return $this->_string; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Get the object descriptor. |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function descriptor(): string |
|
34 | + { |
|
35 | + return $this->_string; |
|
36 | + } |
|
37 | 37 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -12,25 +12,25 @@ |
||
12 | 12 | */ |
13 | 13 | class NumericString 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_NUMERIC_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_NUMERIC_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected function _validateString(string $string): bool |
|
33 | - { |
|
34 | - return preg_match('/[^0-9 ]/', $string) == 0; |
|
35 | - } |
|
28 | + /** |
|
29 | + * |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected function _validateString(string $string): bool |
|
33 | + { |
|
34 | + return preg_match('/[^0-9 ]/', $string) == 0; |
|
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 ASN1\Type\Primitive; |
6 | 6 |
@@ -17,41 +17,41 @@ |
||
17 | 17 | */ |
18 | 18 | class NullType 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_NULL; |
|
29 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->_typeTag = self::TYPE_NULL; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * |
|
33 | - * {@inheritdoc} |
|
34 | - */ |
|
35 | - protected function _encodedContentDER(): string |
|
36 | - { |
|
37 | - return ""; |
|
38 | - } |
|
31 | + /** |
|
32 | + * |
|
33 | + * {@inheritdoc} |
|
34 | + */ |
|
35 | + protected function _encodedContentDER(): string |
|
36 | + { |
|
37 | + return ""; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * |
|
42 | - * {@inheritdoc} |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
46 | - int &$offset): ElementBase |
|
47 | - { |
|
48 | - $idx = $offset; |
|
49 | - if (!$identifier->isPrimitive()) { |
|
50 | - throw new DecodeException("Null value must be primitive."); |
|
51 | - } |
|
52 | - // null type has always zero length |
|
53 | - Length::expectFromDER($data, $idx, 0); |
|
54 | - $offset = $idx; |
|
55 | - return new self(); |
|
56 | - } |
|
40 | + /** |
|
41 | + * |
|
42 | + * {@inheritdoc} |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
46 | + int &$offset): ElementBase |
|
47 | + { |
|
48 | + $idx = $offset; |
|
49 | + if (!$identifier->isPrimitive()) { |
|
50 | + throw new DecodeException("Null value must be primitive."); |
|
51 | + } |
|
52 | + // null type has always zero length |
|
53 | + Length::expectFromDER($data, $idx, 0); |
|
54 | + $offset = $idx; |
|
55 | + return new self(); |
|
56 | + } |
|
57 | 57 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -17,64 +17,64 @@ |
||
17 | 17 | */ |
18 | 18 | class Boolean extends Element |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Value. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - private $_bool; |
|
23 | + /** |
|
24 | + * Value. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + private $_bool; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor. |
|
32 | - * |
|
33 | - * @param bool $bool |
|
34 | - */ |
|
35 | - public function __construct(bool $bool) |
|
36 | - { |
|
37 | - $this->_typeTag = self::TYPE_BOOLEAN; |
|
38 | - $this->_bool = $bool; |
|
39 | - } |
|
30 | + /** |
|
31 | + * Constructor. |
|
32 | + * |
|
33 | + * @param bool $bool |
|
34 | + */ |
|
35 | + public function __construct(bool $bool) |
|
36 | + { |
|
37 | + $this->_typeTag = self::TYPE_BOOLEAN; |
|
38 | + $this->_bool = $bool; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get the value. |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function value(): bool |
|
47 | - { |
|
48 | - return $this->_bool; |
|
49 | - } |
|
41 | + /** |
|
42 | + * Get the value. |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function value(): bool |
|
47 | + { |
|
48 | + return $this->_bool; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * |
|
53 | - * {@inheritdoc} |
|
54 | - */ |
|
55 | - protected function _encodedContentDER(): string |
|
56 | - { |
|
57 | - return $this->_bool ? chr(0xff) : chr(0); |
|
58 | - } |
|
51 | + /** |
|
52 | + * |
|
53 | + * {@inheritdoc} |
|
54 | + */ |
|
55 | + protected function _encodedContentDER(): string |
|
56 | + { |
|
57 | + return $this->_bool ? chr(0xff) : chr(0); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * |
|
62 | - * {@inheritdoc} |
|
63 | - * @return self |
|
64 | - */ |
|
65 | - protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
66 | - int &$offset): ElementBase |
|
67 | - { |
|
68 | - $idx = $offset; |
|
69 | - Length::expectFromDER($data, $idx, 1); |
|
70 | - $byte = ord($data[$idx++]); |
|
71 | - if ($byte !== 0) { |
|
72 | - if ($byte != 0xff) { |
|
73 | - throw new DecodeException( |
|
74 | - "DER encoded boolean true must have all bits set to 1."); |
|
75 | - } |
|
76 | - } |
|
77 | - $offset = $idx; |
|
78 | - return new self($byte !== 0); |
|
79 | - } |
|
60 | + /** |
|
61 | + * |
|
62 | + * {@inheritdoc} |
|
63 | + * @return self |
|
64 | + */ |
|
65 | + protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
66 | + int &$offset): ElementBase |
|
67 | + { |
|
68 | + $idx = $offset; |
|
69 | + Length::expectFromDER($data, $idx, 1); |
|
70 | + $byte = ord($data[$idx++]); |
|
71 | + if ($byte !== 0) { |
|
72 | + if ($byte != 0xff) { |
|
73 | + throw new DecodeException( |
|
74 | + "DER encoded boolean true must have all bits set to 1."); |
|
75 | + } |
|
76 | + } |
|
77 | + $offset = $idx; |
|
78 | + return new self($byte !== 0); |
|
79 | + } |
|
80 | 80 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -11,48 +11,48 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class StringType extends Element |
13 | 13 | { |
14 | - /** |
|
15 | - * String value. |
|
16 | - * |
|
17 | - * @var string $_string |
|
18 | - */ |
|
19 | - protected $_string; |
|
14 | + /** |
|
15 | + * String value. |
|
16 | + * |
|
17 | + * @var string $_string |
|
18 | + */ |
|
19 | + protected $_string; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param string $string |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - public function __construct(string $string) |
|
28 | - { |
|
29 | - if (!$this->_validateString($string)) { |
|
30 | - throw new \InvalidArgumentException( |
|
31 | - sprintf("Not a valid %s string.", |
|
32 | - self::tagToName($this->_typeTag))); |
|
33 | - } |
|
34 | - $this->_string = $string; |
|
35 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param string $string |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + public function __construct(string $string) |
|
28 | + { |
|
29 | + if (!$this->_validateString($string)) { |
|
30 | + throw new \InvalidArgumentException( |
|
31 | + sprintf("Not a valid %s string.", |
|
32 | + self::tagToName($this->_typeTag))); |
|
33 | + } |
|
34 | + $this->_string = $string; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the string value. |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function string(): string |
|
43 | - { |
|
44 | - return $this->_string; |
|
45 | - } |
|
37 | + /** |
|
38 | + * Get the string value. |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function string(): string |
|
43 | + { |
|
44 | + return $this->_string; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Check whether string is valid for the concrete type. |
|
49 | - * |
|
50 | - * @param string $string |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - protected function _validateString(string $string): bool |
|
54 | - { |
|
55 | - // Override in derived classes |
|
56 | - return true; |
|
57 | - } |
|
47 | + /** |
|
48 | + * Check whether string is valid for the concrete type. |
|
49 | + * |
|
50 | + * @param string $string |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + protected function _validateString(string $string): bool |
|
54 | + { |
|
55 | + // Override in derived classes |
|
56 | + return true; |
|
57 | + } |
|
58 | 58 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type; |
6 | 6 |