@@ -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 | } |
@@ -13,15 +13,15 @@ |
||
13 | 13 | */ |
14 | 14 | interface ImplicitTagging extends ElementBase |
15 | 15 | { |
16 | - /** |
|
17 | - * Get implicitly tagged wrapped element. |
|
18 | - * |
|
19 | - * @param int $tag Tag of the element |
|
20 | - * @param int $class Expected type class of the element |
|
21 | - * |
|
22 | - * @throws \UnexpectedValueException If expectation fails |
|
23 | - * |
|
24 | - * @return \Sop\ASN1\Type\UnspecifiedType |
|
25 | - */ |
|
26 | - public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType; |
|
16 | + /** |
|
17 | + * Get implicitly tagged wrapped element. |
|
18 | + * |
|
19 | + * @param int $tag Tag of the element |
|
20 | + * @param int $class Expected type class of the element |
|
21 | + * |
|
22 | + * @throws \UnexpectedValueException If expectation fails |
|
23 | + * |
|
24 | + * @return \Sop\ASN1\Type\UnspecifiedType |
|
25 | + */ |
|
26 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType; |
|
27 | 27 | } |
@@ -17,52 +17,52 @@ |
||
17 | 17 | */ |
18 | 18 | class ImplicitlyTaggedType extends TaggedTypeWrap implements ImplicitTagging |
19 | 19 | { |
20 | - /** |
|
21 | - * Constructor. |
|
22 | - * |
|
23 | - * @param int $tag Tag number |
|
24 | - * @param Element $element Wrapped element |
|
25 | - * @param int $class Type class |
|
26 | - */ |
|
27 | - public function __construct(int $tag, Element $element, |
|
28 | - int $class = Identifier::CLASS_CONTEXT_SPECIFIC) |
|
29 | - { |
|
30 | - $this->_typeTag = $tag; |
|
31 | - $this->_element = $element; |
|
32 | - $this->_class = $class; |
|
33 | - } |
|
20 | + /** |
|
21 | + * Constructor. |
|
22 | + * |
|
23 | + * @param int $tag Tag number |
|
24 | + * @param Element $element Wrapped element |
|
25 | + * @param int $class Type class |
|
26 | + */ |
|
27 | + public function __construct(int $tag, Element $element, |
|
28 | + int $class = Identifier::CLASS_CONTEXT_SPECIFIC) |
|
29 | + { |
|
30 | + $this->_typeTag = $tag; |
|
31 | + $this->_element = $element; |
|
32 | + $this->_class = $class; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - */ |
|
38 | - public function isConstructed(): bool |
|
39 | - { |
|
40 | - // depends on the underlying type |
|
41 | - return $this->_element->isConstructed(); |
|
42 | - } |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + */ |
|
38 | + public function isConstructed(): bool |
|
39 | + { |
|
40 | + // depends on the underlying type |
|
41 | + return $this->_element->isConstructed(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inheritdoc} |
|
46 | - */ |
|
47 | - public function implicit( |
|
48 | - int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
49 | - { |
|
50 | - $this->_element->expectType($tag); |
|
51 | - if ($this->_element->typeClass() != $class) { |
|
52 | - throw new \UnexpectedValueException( |
|
53 | - sprintf('Type class %s expected, got %s.', |
|
54 | - Identifier::classToName($class), |
|
55 | - Identifier::classToName($this->_element->typeClass()))); |
|
56 | - } |
|
57 | - return $this->_element->asUnspecified(); |
|
58 | - } |
|
44 | + /** |
|
45 | + * {@inheritdoc} |
|
46 | + */ |
|
47 | + public function implicit( |
|
48 | + int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
49 | + { |
|
50 | + $this->_element->expectType($tag); |
|
51 | + if ($this->_element->typeClass() != $class) { |
|
52 | + throw new \UnexpectedValueException( |
|
53 | + sprintf('Type class %s expected, got %s.', |
|
54 | + Identifier::classToName($class), |
|
55 | + Identifier::classToName($this->_element->typeClass()))); |
|
56 | + } |
|
57 | + return $this->_element->asUnspecified(); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - protected function _encodedContentDER(): string |
|
64 | - { |
|
65 | - // get only the content of the wrapped element. |
|
66 | - return $this->_element->_encodedContentDER(); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + protected function _encodedContentDER(): string |
|
64 | + { |
|
65 | + // get only the content of the wrapped element. |
|
66 | + return $this->_element->_encodedContentDER(); |
|
67 | + } |
|
68 | 68 | } |
@@ -11,27 +11,27 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class TaggedTypeWrap extends TaggedType |
13 | 13 | { |
14 | - /** |
|
15 | - * Wrapped element. |
|
16 | - * |
|
17 | - * @var \Sop\ASN1\Element |
|
18 | - */ |
|
19 | - protected $_element; |
|
14 | + /** |
|
15 | + * Wrapped element. |
|
16 | + * |
|
17 | + * @var \Sop\ASN1\Element |
|
18 | + */ |
|
19 | + protected $_element; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Type class. |
|
23 | - * |
|
24 | - * @var int |
|
25 | - */ |
|
26 | - protected $_class; |
|
21 | + /** |
|
22 | + * Type class. |
|
23 | + * |
|
24 | + * @var int |
|
25 | + */ |
|
26 | + protected $_class; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @see \Sop\ASN1\Element::typeClass() |
|
30 | - * |
|
31 | - * @return int |
|
32 | - */ |
|
33 | - public function typeClass(): int |
|
34 | - { |
|
35 | - return $this->_class; |
|
36 | - } |
|
28 | + /** |
|
29 | + * @see \Sop\ASN1\Element::typeClass() |
|
30 | + * |
|
31 | + * @return int |
|
32 | + */ |
|
33 | + public function typeClass(): int |
|
34 | + { |
|
35 | + return $this->_class; |
|
36 | + } |
|
37 | 37 | } |
@@ -17,38 +17,38 @@ |
||
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 | - * {@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('Null value must be primitive.'); |
|
48 | - } |
|
49 | - // null 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('Null value must be primitive.'); |
|
48 | + } |
|
49 | + // null type has always zero length |
|
50 | + Length::expectFromDER($data, $idx, 0); |
|
51 | + $offset = $idx; |
|
52 | + return new self(); |
|
53 | + } |
|
54 | 54 | } |
@@ -17,61 +17,61 @@ |
||
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 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - protected function _encodedContentDER(): string |
|
55 | - { |
|
56 | - return $this->_bool ? chr(0xff) : chr(0); |
|
57 | - } |
|
51 | + /** |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + protected function _encodedContentDER(): string |
|
55 | + { |
|
56 | + return $this->_bool ? chr(0xff) : chr(0); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritdoc} |
|
61 | - */ |
|
62 | - protected static function _decodeFromDER(Identifier $identifier, |
|
63 | - string $data, int &$offset): ElementBase |
|
64 | - { |
|
65 | - $idx = $offset; |
|
66 | - Length::expectFromDER($data, $idx, 1); |
|
67 | - $byte = ord($data[$idx++]); |
|
68 | - if (0 !== $byte) { |
|
69 | - if (0xff != $byte) { |
|
70 | - throw new DecodeException( |
|
71 | - 'DER encoded boolean true must have all bits set to 1.'); |
|
72 | - } |
|
73 | - } |
|
74 | - $offset = $idx; |
|
75 | - return new self(0 !== $byte); |
|
76 | - } |
|
59 | + /** |
|
60 | + * {@inheritdoc} |
|
61 | + */ |
|
62 | + protected static function _decodeFromDER(Identifier $identifier, |
|
63 | + string $data, int &$offset): ElementBase |
|
64 | + { |
|
65 | + $idx = $offset; |
|
66 | + Length::expectFromDER($data, $idx, 1); |
|
67 | + $byte = ord($data[$idx++]); |
|
68 | + if (0 !== $byte) { |
|
69 | + if (0xff != $byte) { |
|
70 | + throw new DecodeException( |
|
71 | + 'DER encoded boolean true must have all bits set to 1.'); |
|
72 | + } |
|
73 | + } |
|
74 | + $offset = $idx; |
|
75 | + return new self(0 !== $byte); |
|
76 | + } |
|
77 | 77 | } |
@@ -12,26 +12,26 @@ |
||
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 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything since there's literally |
|
34 | - // thousands of allowed characters (16 bit composed characters) |
|
35 | - return true; |
|
36 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything since there's literally |
|
34 | + // thousands of allowed characters (16 bit composed characters) |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | } |
@@ -17,110 +17,110 @@ |
||
17 | 17 | */ |
18 | 18 | class GeneralizedTime extends TimeType |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Regular expression to parse date. |
|
25 | - * |
|
26 | - * DER restricts format to UTC timezone (Z suffix). |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - const REGEX = '#^' . |
|
31 | - '(\d\d\d\d)' . // YYYY |
|
32 | - '(\d\d)' . // MM |
|
33 | - '(\d\d)' . // DD |
|
34 | - '(\d\d)' . // hh |
|
35 | - '(\d\d)' . // mm |
|
36 | - '(\d\d)' . // ss |
|
37 | - '(?:\.(\d+))?' . // frac |
|
38 | - 'Z' . // TZ |
|
39 | - '$#'; |
|
23 | + /** |
|
24 | + * Regular expression to parse date. |
|
25 | + * |
|
26 | + * DER restricts format to UTC timezone (Z suffix). |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + const REGEX = '#^' . |
|
31 | + '(\d\d\d\d)' . // YYYY |
|
32 | + '(\d\d)' . // MM |
|
33 | + '(\d\d)' . // DD |
|
34 | + '(\d\d)' . // hh |
|
35 | + '(\d\d)' . // mm |
|
36 | + '(\d\d)' . // ss |
|
37 | + '(?:\.(\d+))?' . // frac |
|
38 | + 'Z' . // TZ |
|
39 | + '$#'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Cached formatted date. |
|
43 | - * |
|
44 | - * @var null|string |
|
45 | - */ |
|
46 | - private $_formatted; |
|
41 | + /** |
|
42 | + * Cached formatted date. |
|
43 | + * |
|
44 | + * @var null|string |
|
45 | + */ |
|
46 | + private $_formatted; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Constructor. |
|
50 | - * |
|
51 | - * @param \DateTimeImmutable $dt |
|
52 | - */ |
|
53 | - public function __construct(\DateTimeImmutable $dt) |
|
54 | - { |
|
55 | - $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
56 | - parent::__construct($dt); |
|
57 | - } |
|
48 | + /** |
|
49 | + * Constructor. |
|
50 | + * |
|
51 | + * @param \DateTimeImmutable $dt |
|
52 | + */ |
|
53 | + public function __construct(\DateTimeImmutable $dt) |
|
54 | + { |
|
55 | + $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
56 | + parent::__construct($dt); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Clear cached variables on clone. |
|
61 | - */ |
|
62 | - public function __clone() |
|
63 | - { |
|
64 | - $this->_formatted = null; |
|
65 | - } |
|
59 | + /** |
|
60 | + * Clear cached variables on clone. |
|
61 | + */ |
|
62 | + public function __clone() |
|
63 | + { |
|
64 | + $this->_formatted = null; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - protected function _encodedContentDER(): string |
|
71 | - { |
|
72 | - if (!isset($this->_formatted)) { |
|
73 | - $dt = $this->_dateTime->setTimezone( |
|
74 | - self::_createTimeZone(self::TZ_UTC)); |
|
75 | - $this->_formatted = $dt->format('YmdHis'); |
|
76 | - // if fractions were used |
|
77 | - $frac = $dt->format('u'); |
|
78 | - if (0 != $frac) { |
|
79 | - $frac = rtrim($frac, '0'); |
|
80 | - $this->_formatted .= ".${frac}"; |
|
81 | - } |
|
82 | - // timezone |
|
83 | - $this->_formatted .= 'Z'; |
|
84 | - } |
|
85 | - return $this->_formatted; |
|
86 | - } |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + protected function _encodedContentDER(): string |
|
71 | + { |
|
72 | + if (!isset($this->_formatted)) { |
|
73 | + $dt = $this->_dateTime->setTimezone( |
|
74 | + self::_createTimeZone(self::TZ_UTC)); |
|
75 | + $this->_formatted = $dt->format('YmdHis'); |
|
76 | + // if fractions were used |
|
77 | + $frac = $dt->format('u'); |
|
78 | + if (0 != $frac) { |
|
79 | + $frac = rtrim($frac, '0'); |
|
80 | + $this->_formatted .= ".${frac}"; |
|
81 | + } |
|
82 | + // timezone |
|
83 | + $this->_formatted .= 'Z'; |
|
84 | + } |
|
85 | + return $this->_formatted; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * {@inheritdoc} |
|
90 | - */ |
|
91 | - protected static function _decodeFromDER(Identifier $identifier, |
|
92 | - string $data, int &$offset): ElementBase |
|
93 | - { |
|
94 | - $idx = $offset; |
|
95 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
96 | - $str = substr($data, $idx, $length); |
|
97 | - $idx += $length; |
|
98 | - /** @var string[] $match */ |
|
99 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
100 | - throw new DecodeException('Invalid GeneralizedTime format.'); |
|
101 | - } |
|
102 | - [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
103 | - if (isset($match[7])) { |
|
104 | - $frac = $match[7]; |
|
105 | - // DER restricts trailing zeroes in fractional seconds component |
|
106 | - if ('0' === $frac[strlen($frac) - 1]) { |
|
107 | - throw new DecodeException( |
|
108 | - 'Fractional seconds must omit trailing zeroes.'); |
|
109 | - } |
|
110 | - $frac = (int) $frac; |
|
111 | - } else { |
|
112 | - $frac = 0; |
|
113 | - } |
|
114 | - $time = $year . $month . $day . $hour . $minute . $second . '.' . $frac . |
|
115 | - self::TZ_UTC; |
|
116 | - $dt = \DateTimeImmutable::createFromFormat('!YmdHis.uT', $time, |
|
117 | - self::_createTimeZone(self::TZ_UTC)); |
|
118 | - if (!$dt) { |
|
119 | - throw new DecodeException( |
|
120 | - 'Failed to decode GeneralizedTime: ' . |
|
121 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
122 | - } |
|
123 | - $offset = $idx; |
|
124 | - return new self($dt); |
|
125 | - } |
|
88 | + /** |
|
89 | + * {@inheritdoc} |
|
90 | + */ |
|
91 | + protected static function _decodeFromDER(Identifier $identifier, |
|
92 | + string $data, int &$offset): ElementBase |
|
93 | + { |
|
94 | + $idx = $offset; |
|
95 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
96 | + $str = substr($data, $idx, $length); |
|
97 | + $idx += $length; |
|
98 | + /** @var string[] $match */ |
|
99 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
100 | + throw new DecodeException('Invalid GeneralizedTime format.'); |
|
101 | + } |
|
102 | + [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
103 | + if (isset($match[7])) { |
|
104 | + $frac = $match[7]; |
|
105 | + // DER restricts trailing zeroes in fractional seconds component |
|
106 | + if ('0' === $frac[strlen($frac) - 1]) { |
|
107 | + throw new DecodeException( |
|
108 | + 'Fractional seconds must omit trailing zeroes.'); |
|
109 | + } |
|
110 | + $frac = (int) $frac; |
|
111 | + } else { |
|
112 | + $frac = 0; |
|
113 | + } |
|
114 | + $time = $year . $month . $day . $hour . $minute . $second . '.' . $frac . |
|
115 | + self::TZ_UTC; |
|
116 | + $dt = \DateTimeImmutable::createFromFormat('!YmdHis.uT', $time, |
|
117 | + self::_createTimeZone(self::TZ_UTC)); |
|
118 | + if (!$dt) { |
|
119 | + throw new DecodeException( |
|
120 | + 'Failed to decode GeneralizedTime: ' . |
|
121 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
122 | + } |
|
123 | + $offset = $idx; |
|
124 | + return new self($dt); |
|
125 | + } |
|
126 | 126 | } |
@@ -14,24 +14,24 @@ |
||
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 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function _validateString(string $string): bool |
|
34 | - { |
|
35 | - return mb_check_encoding($string, 'UTF-8'); |
|
36 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function _validateString(string $string): bool |
|
34 | + { |
|
35 | + return mb_check_encoding($string, 'UTF-8'); |
|
36 | + } |
|
37 | 37 | } |