@@ -14,72 +14,72 @@ |
||
14 | 14 | */ |
15 | 15 | class UTCTime extends TimeType |
16 | 16 | { |
17 | - use UniversalClass; |
|
18 | - use PrimitiveType; |
|
17 | + use UniversalClass; |
|
18 | + use PrimitiveType; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Regular expression to parse date. |
|
22 | - * |
|
23 | - * DER restricts format to UTC timezone (Z suffix). |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - const REGEX = /* @formatter:off */ '#^' . |
|
28 | - '(\d\d)' . /* YY */ |
|
29 | - '(\d\d)' . /* MM */ |
|
30 | - '(\d\d)' . /* DD */ |
|
31 | - '(\d\d)' . /* hh */ |
|
32 | - '(\d\d)' . /* mm */ |
|
33 | - '(\d\d)' . /* ss */ |
|
34 | - 'Z' . /* TZ */ |
|
35 | - '$#' /* @formatter:on */; |
|
20 | + /** |
|
21 | + * Regular expression to parse date. |
|
22 | + * |
|
23 | + * DER restricts format to UTC timezone (Z suffix). |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + const REGEX = /* @formatter:off */ '#^' . |
|
28 | + '(\d\d)' . /* YY */ |
|
29 | + '(\d\d)' . /* MM */ |
|
30 | + '(\d\d)' . /* DD */ |
|
31 | + '(\d\d)' . /* hh */ |
|
32 | + '(\d\d)' . /* mm */ |
|
33 | + '(\d\d)' . /* ss */ |
|
34 | + 'Z' . /* TZ */ |
|
35 | + '$#' /* @formatter:on */; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor. |
|
39 | - * |
|
40 | - * @param \DateTimeImmutable $dt |
|
41 | - */ |
|
42 | - public function __construct(\DateTimeImmutable $dt) |
|
43 | - { |
|
44 | - $this->_typeTag = self::TYPE_UTC_TIME; |
|
45 | - parent::__construct($dt); |
|
46 | - } |
|
37 | + /** |
|
38 | + * Constructor. |
|
39 | + * |
|
40 | + * @param \DateTimeImmutable $dt |
|
41 | + */ |
|
42 | + public function __construct(\DateTimeImmutable $dt) |
|
43 | + { |
|
44 | + $this->_typeTag = self::TYPE_UTC_TIME; |
|
45 | + parent::__construct($dt); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - protected function _encodedContentDER() |
|
53 | - { |
|
54 | - $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
55 | - return $dt->format("ymdHis\Z"); |
|
56 | - } |
|
48 | + /** |
|
49 | + * |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + protected function _encodedContentDER() |
|
53 | + { |
|
54 | + $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
55 | + return $dt->format("ymdHis\Z"); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * |
|
60 | - * {@inheritdoc} |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - protected static function _decodeFromDER(Identifier $identifier, $data, |
|
64 | - &$offset) |
|
65 | - { |
|
66 | - $idx = $offset; |
|
67 | - $length = Length::expectFromDER($data, $idx); |
|
68 | - $str = substr($data, $idx, $length->length()); |
|
69 | - $idx += $length->length(); |
|
70 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
71 | - throw new DecodeException("Invalid UTCTime format."); |
|
72 | - } |
|
73 | - list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
74 | - $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
75 | - $dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time, |
|
76 | - self::_createTimeZone(self::TZ_UTC)); |
|
77 | - if (!$dt) { |
|
78 | - throw new DecodeException( |
|
79 | - "Failed to decode UTCTime: " . |
|
80 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
81 | - } |
|
82 | - $offset = $idx; |
|
83 | - return new self($dt); |
|
84 | - } |
|
58 | + /** |
|
59 | + * |
|
60 | + * {@inheritdoc} |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + protected static function _decodeFromDER(Identifier $identifier, $data, |
|
64 | + &$offset) |
|
65 | + { |
|
66 | + $idx = $offset; |
|
67 | + $length = Length::expectFromDER($data, $idx); |
|
68 | + $str = substr($data, $idx, $length->length()); |
|
69 | + $idx += $length->length(); |
|
70 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
71 | + throw new DecodeException("Invalid UTCTime format."); |
|
72 | + } |
|
73 | + list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
74 | + $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
75 | + $dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time, |
|
76 | + self::_createTimeZone(self::TZ_UTC)); |
|
77 | + if (!$dt) { |
|
78 | + throw new DecodeException( |
|
79 | + "Failed to decode UTCTime: " . |
|
80 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
81 | + } |
|
82 | + $offset = $idx; |
|
83 | + return new self($dt); |
|
84 | + } |
|
85 | 85 | } |