@@ -7,14 +7,14 @@ |
||
7 | 7 | */ |
8 | 8 | class Enumerated extends Integer |
9 | 9 | { |
10 | - /** |
|
11 | - * Constructor. |
|
12 | - * |
|
13 | - * @param int|string $number |
|
14 | - */ |
|
15 | - public function __construct($number) |
|
16 | - { |
|
17 | - parent::__construct($number); |
|
18 | - $this->_typeTag = self::TYPE_ENUMERATED; |
|
19 | - } |
|
10 | + /** |
|
11 | + * Constructor. |
|
12 | + * |
|
13 | + * @param int|string $number |
|
14 | + */ |
|
15 | + public function __construct($number) |
|
16 | + { |
|
17 | + parent::__construct($number); |
|
18 | + $this->_typeTag = self::TYPE_ENUMERATED; |
|
19 | + } |
|
20 | 20 | } |
@@ -9,10 +9,10 @@ |
||
9 | 9 | */ |
10 | 10 | interface Encodable |
11 | 11 | { |
12 | - /** |
|
13 | - * Encode object to DER. |
|
14 | - * |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function toDER(): string; |
|
12 | + /** |
|
13 | + * Encode object to DER. |
|
14 | + * |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function toDER(): string; |
|
18 | 18 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | */ |
13 | 13 | class OctetString 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_OCTET_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_OCTET_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | } |
@@ -9,16 +9,16 @@ |
||
9 | 9 | |
10 | 10 | class CharacterString extends PrimitiveString |
11 | 11 | { |
12 | - use UniversalClass; |
|
12 | + use UniversalClass; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor. |
|
16 | - * |
|
17 | - * @param string $string |
|
18 | - */ |
|
19 | - public function __construct(string $string) |
|
20 | - { |
|
21 | - $this->_typeTag = self::TYPE_CHARACTER_STRING; |
|
22 | - parent::__construct($string); |
|
23 | - } |
|
14 | + /** |
|
15 | + * Constructor. |
|
16 | + * |
|
17 | + * @param string $string |
|
18 | + */ |
|
19 | + public function __construct(string $string) |
|
20 | + { |
|
21 | + $this->_typeTag = self::TYPE_CHARACTER_STRING; |
|
22 | + parent::__construct($string); |
|
23 | + } |
|
24 | 24 | } |
@@ -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 | } |
@@ -12,14 +12,14 @@ |
||
12 | 12 | */ |
13 | 13 | class Sequence extends Structure |
14 | 14 | { |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param Element ...$elements Any number of elements |
|
19 | - */ |
|
20 | - public function __construct(Element ...$elements) |
|
21 | - { |
|
22 | - $this->_typeTag = self::TYPE_SEQUENCE; |
|
23 | - parent::__construct(...$elements); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param Element ...$elements Any number of elements |
|
19 | + */ |
|
20 | + public function __construct(Element ...$elements) |
|
21 | + { |
|
22 | + $this->_typeTag = self::TYPE_SEQUENCE; |
|
23 | + parent::__construct(...$elements); |
|
24 | + } |
|
25 | 25 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | */ |
12 | 12 | trait UniversalClass |
13 | 13 | { |
14 | - /** |
|
15 | - * @see \Sop\ASN1\Feature\ElementBase::typeClass() |
|
16 | - * |
|
17 | - * @return int |
|
18 | - */ |
|
19 | - public function typeClass(): int |
|
20 | - { |
|
21 | - return Identifier::CLASS_UNIVERSAL; |
|
22 | - } |
|
14 | + /** |
|
15 | + * @see \Sop\ASN1\Feature\ElementBase::typeClass() |
|
16 | + * |
|
17 | + * @return int |
|
18 | + */ |
|
19 | + public function typeClass(): int |
|
20 | + { |
|
21 | + return Identifier::CLASS_UNIVERSAL; |
|
22 | + } |
|
23 | 23 | } |
@@ -14,36 +14,36 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class PrimitiveString extends StringType |
16 | 16 | { |
17 | - use PrimitiveType; |
|
17 | + use PrimitiveType; |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - */ |
|
22 | - protected function _encodedContentDER(): string |
|
23 | - { |
|
24 | - return $this->_string; |
|
25 | - } |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + */ |
|
22 | + protected function _encodedContentDER(): string |
|
23 | + { |
|
24 | + return $this->_string; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected static function _decodeFromDER(Identifier $identifier, |
|
31 | - string $data, int &$offset): ElementBase |
|
32 | - { |
|
33 | - $idx = $offset; |
|
34 | - if (!$identifier->isPrimitive()) { |
|
35 | - throw new DecodeException('DER encoded string must be primitive.'); |
|
36 | - } |
|
37 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
38 | - $str = $length ? substr($data, $idx, $length) : ''; |
|
39 | - // substr should never return false, since length is |
|
40 | - // checked by Length::expectFromDER. |
|
41 | - assert(is_string($str), new DecodeException('substr')); |
|
42 | - $offset = $idx + $length; |
|
43 | - try { |
|
44 | - return new static($str); |
|
45 | - } catch (\InvalidArgumentException $e) { |
|
46 | - throw new DecodeException($e->getMessage(), 0, $e); |
|
47 | - } |
|
48 | - } |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected static function _decodeFromDER(Identifier $identifier, |
|
31 | + string $data, int &$offset): ElementBase |
|
32 | + { |
|
33 | + $idx = $offset; |
|
34 | + if (!$identifier->isPrimitive()) { |
|
35 | + throw new DecodeException('DER encoded string must be primitive.'); |
|
36 | + } |
|
37 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
38 | + $str = $length ? substr($data, $idx, $length) : ''; |
|
39 | + // substr should never return false, since length is |
|
40 | + // checked by Length::expectFromDER. |
|
41 | + assert(is_string($str), new DecodeException('substr')); |
|
42 | + $offset = $idx + $length; |
|
43 | + try { |
|
44 | + return new static($str); |
|
45 | + } catch (\InvalidArgumentException $e) { |
|
46 | + throw new DecodeException($e->getMessage(), 0, $e); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -11,93 +11,93 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class TimeType extends Element |
13 | 13 | { |
14 | - /** |
|
15 | - * UTC timezone. |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const TZ_UTC = 'UTC'; |
|
14 | + /** |
|
15 | + * UTC timezone. |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const TZ_UTC = 'UTC'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Date and time. |
|
23 | - * |
|
24 | - * @var \DateTimeImmutable |
|
25 | - */ |
|
26 | - protected $_dateTime; |
|
21 | + /** |
|
22 | + * Date and time. |
|
23 | + * |
|
24 | + * @var \DateTimeImmutable |
|
25 | + */ |
|
26 | + protected $_dateTime; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Constructor. |
|
30 | - * |
|
31 | - * @param \DateTimeImmutable $dt |
|
32 | - */ |
|
33 | - public function __construct(\DateTimeImmutable $dt) |
|
34 | - { |
|
35 | - $this->_dateTime = $dt; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Constructor. |
|
30 | + * |
|
31 | + * @param \DateTimeImmutable $dt |
|
32 | + */ |
|
33 | + public function __construct(\DateTimeImmutable $dt) |
|
34 | + { |
|
35 | + $this->_dateTime = $dt; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Initialize from datetime string. |
|
40 | - * |
|
41 | - * @see http://php.net/manual/en/datetime.formats.php |
|
42 | - * |
|
43 | - * @param string $time Time string |
|
44 | - * @param null|string $tz timezone, if null use default |
|
45 | - * |
|
46 | - * @throws \RuntimeException |
|
47 | - * |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromString(string $time, ?string $tz = null): self |
|
51 | - { |
|
52 | - try { |
|
53 | - if (!isset($tz)) { |
|
54 | - $tz = date_default_timezone_get(); |
|
55 | - } |
|
56 | - return new static( |
|
57 | - new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
58 | - } catch (\Exception $e) { |
|
59 | - throw new \RuntimeException( |
|
60 | - 'Failed to create DateTime: ' . |
|
61 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
62 | - } |
|
63 | - } |
|
38 | + /** |
|
39 | + * Initialize from datetime string. |
|
40 | + * |
|
41 | + * @see http://php.net/manual/en/datetime.formats.php |
|
42 | + * |
|
43 | + * @param string $time Time string |
|
44 | + * @param null|string $tz timezone, if null use default |
|
45 | + * |
|
46 | + * @throws \RuntimeException |
|
47 | + * |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromString(string $time, ?string $tz = null): self |
|
51 | + { |
|
52 | + try { |
|
53 | + if (!isset($tz)) { |
|
54 | + $tz = date_default_timezone_get(); |
|
55 | + } |
|
56 | + return new static( |
|
57 | + new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
58 | + } catch (\Exception $e) { |
|
59 | + throw new \RuntimeException( |
|
60 | + 'Failed to create DateTime: ' . |
|
61 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get the date and time. |
|
67 | - * |
|
68 | - * @return \DateTimeImmutable |
|
69 | - */ |
|
70 | - public function dateTime(): \DateTimeImmutable |
|
71 | - { |
|
72 | - return $this->_dateTime; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Get the date and time. |
|
67 | + * |
|
68 | + * @return \DateTimeImmutable |
|
69 | + */ |
|
70 | + public function dateTime(): \DateTimeImmutable |
|
71 | + { |
|
72 | + return $this->_dateTime; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Create DateTimeZone object from string. |
|
77 | - * |
|
78 | - * @param string $tz |
|
79 | - * |
|
80 | - * @throws \UnexpectedValueException If timezone is invalid |
|
81 | - * |
|
82 | - * @return \DateTimeZone |
|
83 | - */ |
|
84 | - protected static function _createTimeZone(string $tz): \DateTimeZone |
|
85 | - { |
|
86 | - try { |
|
87 | - return new \DateTimeZone($tz); |
|
88 | - } catch (\Exception $e) { |
|
89 | - throw new \UnexpectedValueException('Invalid timezone.', 0, $e); |
|
90 | - } |
|
91 | - } |
|
75 | + /** |
|
76 | + * Create DateTimeZone object from string. |
|
77 | + * |
|
78 | + * @param string $tz |
|
79 | + * |
|
80 | + * @throws \UnexpectedValueException If timezone is invalid |
|
81 | + * |
|
82 | + * @return \DateTimeZone |
|
83 | + */ |
|
84 | + protected static function _createTimeZone(string $tz): \DateTimeZone |
|
85 | + { |
|
86 | + try { |
|
87 | + return new \DateTimeZone($tz); |
|
88 | + } catch (\Exception $e) { |
|
89 | + throw new \UnexpectedValueException('Invalid timezone.', 0, $e); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get last error caused by DateTimeImmutable. |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
99 | - { |
|
100 | - $errors = \DateTimeImmutable::getLastErrors()['errors']; |
|
101 | - return implode(', ', $errors); |
|
102 | - } |
|
93 | + /** |
|
94 | + * Get last error caused by DateTimeImmutable. |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
99 | + { |
|
100 | + $errors = \DateTimeImmutable::getLastErrors()['errors']; |
|
101 | + return implode(', ', $errors); |
|
102 | + } |
|
103 | 103 | } |