@@ -10,25 +10,25 @@ |
||
10 | 10 | */ |
11 | 11 | class IA5String extends PrimitiveString |
12 | 12 | { |
13 | - use UniversalClass; |
|
13 | + use UniversalClass; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor |
|
17 | - * |
|
18 | - * @param string $string |
|
19 | - */ |
|
20 | - public function __construct($string) |
|
21 | - { |
|
22 | - $this->_typeTag = self::TYPE_IA5_STRING; |
|
23 | - parent::__construct($string); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor |
|
17 | + * |
|
18 | + * @param string $string |
|
19 | + */ |
|
20 | + public function __construct($string) |
|
21 | + { |
|
22 | + $this->_typeTag = self::TYPE_IA5_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - return preg_match('/[^\x01-\x7f]/', $string) == 0; |
|
33 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + return preg_match('/[^\x01-\x7f]/', $string) == 0; |
|
33 | + } |
|
34 | 34 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | */ |
11 | 11 | class GeneralString extends PrimitiveString |
12 | 12 | { |
13 | - use UniversalClass; |
|
13 | + use UniversalClass; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param string $string |
|
19 | - */ |
|
20 | - public function __construct($string) |
|
21 | - { |
|
22 | - $this->_typeTag = self::TYPE_GENERAL_STRING; |
|
23 | - parent::__construct($string); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param string $string |
|
19 | + */ |
|
20 | + public function __construct($string) |
|
21 | + { |
|
22 | + $this->_typeTag = self::TYPE_GENERAL_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - // allow everything |
|
33 | - return true; |
|
34 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + // allow everything |
|
33 | + return true; |
|
34 | + } |
|
35 | 35 | } |
@@ -7,16 +7,16 @@ |
||
7 | 7 | |
8 | 8 | class CharacterString extends PrimitiveString |
9 | 9 | { |
10 | - use UniversalClass; |
|
10 | + use UniversalClass; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructor. |
|
14 | - * |
|
15 | - * @param string $string |
|
16 | - */ |
|
17 | - public function __construct($string) |
|
18 | - { |
|
19 | - $this->_typeTag = self::TYPE_CHARACTER_STRING; |
|
20 | - parent::__construct($string); |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructor. |
|
14 | + * |
|
15 | + * @param string $string |
|
16 | + */ |
|
17 | + public function __construct($string) |
|
18 | + { |
|
19 | + $this->_typeTag = self::TYPE_CHARACTER_STRING; |
|
20 | + parent::__construct($string); |
|
21 | + } |
|
22 | 22 | } |
@@ -14,41 +14,41 @@ |
||
14 | 14 | */ |
15 | 15 | class NullType extends Element |
16 | 16 | { |
17 | - use UniversalClass; |
|
18 | - use PrimitiveType; |
|
17 | + use UniversalClass; |
|
18 | + use PrimitiveType; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->_typeTag = self::TYPE_NULL; |
|
26 | - } |
|
20 | + /** |
|
21 | + * Constructor. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->_typeTag = self::TYPE_NULL; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected function _encodedContentDER() |
|
33 | - { |
|
34 | - return ""; |
|
35 | - } |
|
28 | + /** |
|
29 | + * |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected function _encodedContentDER() |
|
33 | + { |
|
34 | + return ""; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - * {@inheritdoc} |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - protected static function _decodeFromDER(Identifier $identifier, $data, |
|
43 | - &$offset) |
|
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 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + * {@inheritdoc} |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + protected static function _decodeFromDER(Identifier $identifier, $data, |
|
43 | + &$offset) |
|
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 | } |
@@ -13,29 +13,29 @@ |
||
13 | 13 | */ |
14 | 14 | class BMPString extends PrimitiveString |
15 | 15 | { |
16 | - use UniversalClass; |
|
16 | + use UniversalClass; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Constructor. |
|
20 | - * |
|
21 | - * @param string $string |
|
22 | - */ |
|
23 | - public function __construct($string) |
|
24 | - { |
|
25 | - $this->_typeTag = self::TYPE_BMP_STRING; |
|
26 | - parent::__construct($string); |
|
27 | - } |
|
18 | + /** |
|
19 | + * Constructor. |
|
20 | + * |
|
21 | + * @param string $string |
|
22 | + */ |
|
23 | + public function __construct($string) |
|
24 | + { |
|
25 | + $this->_typeTag = self::TYPE_BMP_STRING; |
|
26 | + parent::__construct($string); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function _validateString($string) |
|
34 | - { |
|
35 | - // UCS-2 has fixed with of 2 octets (16 bits) |
|
36 | - if (strlen($string) % 2 !== 0) { |
|
37 | - return false; |
|
38 | - } |
|
39 | - return true; |
|
40 | - } |
|
29 | + /** |
|
30 | + * |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function _validateString($string) |
|
34 | + { |
|
35 | + // UCS-2 has fixed with of 2 octets (16 bits) |
|
36 | + if (strlen($string) % 2 !== 0) { |
|
37 | + return false; |
|
38 | + } |
|
39 | + return true; |
|
40 | + } |
|
41 | 41 | } |
@@ -10,25 +10,25 @@ |
||
10 | 10 | */ |
11 | 11 | class VisibleString extends PrimitiveString |
12 | 12 | { |
13 | - use UniversalClass; |
|
13 | + use UniversalClass; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param string $string |
|
19 | - */ |
|
20 | - public function __construct($string) |
|
21 | - { |
|
22 | - $this->_typeTag = self::TYPE_VISIBLE_STRING; |
|
23 | - parent::__construct($string); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param string $string |
|
19 | + */ |
|
20 | + public function __construct($string) |
|
21 | + { |
|
22 | + $this->_typeTag = self::TYPE_VISIBLE_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - return preg_match('/[^\x20-\x7e]/', $string) == 0; |
|
33 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + return preg_match('/[^\x20-\x7e]/', $string) == 0; |
|
33 | + } |
|
34 | 34 | } |
@@ -10,39 +10,39 @@ |
||
10 | 10 | */ |
11 | 11 | class RelativeOID extends ObjectIdentifier |
12 | 12 | { |
13 | - /** |
|
14 | - * Constructor. |
|
15 | - * |
|
16 | - * @param string $oid OID in dotted format |
|
17 | - */ |
|
18 | - public function __construct($oid) |
|
19 | - { |
|
20 | - assert('is_string($oid)', "got " . gettype($oid)); |
|
21 | - $this->_oid = $oid; |
|
22 | - $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
23 | - } |
|
13 | + /** |
|
14 | + * Constructor. |
|
15 | + * |
|
16 | + * @param string $oid OID in dotted format |
|
17 | + */ |
|
18 | + public function __construct($oid) |
|
19 | + { |
|
20 | + assert('is_string($oid)', "got " . gettype($oid)); |
|
21 | + $this->_oid = $oid; |
|
22 | + $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - protected function _encodedContentDER() |
|
30 | - { |
|
31 | - return self::_encodeSubIDs(...self::_explodeDottedOID($this->_oid)); |
|
32 | - } |
|
25 | + /** |
|
26 | + * |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + protected function _encodedContentDER() |
|
30 | + { |
|
31 | + return self::_encodeSubIDs(...self::_explodeDottedOID($this->_oid)); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * {@inheritdoc} |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - protected static function _decodeFromDER(Identifier $identifier, $data, |
|
40 | - &$offset) |
|
41 | - { |
|
42 | - $idx = $offset; |
|
43 | - $len = Length::expectFromDER($data, $idx)->length(); |
|
44 | - $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | - $offset = $idx + $len; |
|
46 | - return new self(self::_implodeSubIDs(...$subids)); |
|
47 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * {@inheritdoc} |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + protected static function _decodeFromDER(Identifier $identifier, $data, |
|
40 | + &$offset) |
|
41 | + { |
|
42 | + $idx = $offset; |
|
43 | + $len = Length::expectFromDER($data, $idx)->length(); |
|
44 | + $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | + $offset = $idx + $len; |
|
46 | + return new self(self::_implodeSubIDs(...$subids)); |
|
47 | + } |
|
48 | 48 | } |
@@ -14,17 +14,17 @@ discard block |
||
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 */ '#^' . |
|
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 | 28 | '(\d\d)' . /* YY */ |
29 | 29 | '(\d\d)' . /* MM */ |
30 | 30 | '(\d\d)' . /* DD */ |
@@ -34,52 +34,52 @@ discard block |
||
34 | 34 | 'Z' . /* TZ */ |
35 | 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 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | */ |
11 | 11 | class VideotexString extends PrimitiveString |
12 | 12 | { |
13 | - use UniversalClass; |
|
13 | + use UniversalClass; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param string $string |
|
19 | - */ |
|
20 | - public function __construct($string) |
|
21 | - { |
|
22 | - $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
23 | - parent::__construct($string); |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param string $string |
|
19 | + */ |
|
20 | + public function __construct($string) |
|
21 | + { |
|
22 | + $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - // allow everything |
|
33 | - return true; |
|
34 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + // allow everything |
|
33 | + return true; |
|
34 | + } |
|
35 | 35 | } |