@@ -10,26 +10,26 @@ |
||
10 | 10 | */ |
11 | 11 | class PrintableString 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_PRINTABLE_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_PRINTABLE_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - $chars = preg_quote(" '()+,-./:=?]", "/"); |
|
33 | - return preg_match('/[^A-Za-z0-9' . $chars . ']/', $string) == 0; |
|
34 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + $chars = preg_quote(" '()+,-./:=?]", "/"); |
|
33 | + return preg_match('/[^A-Za-z0-9' . $chars . ']/', $string) == 0; |
|
34 | + } |
|
35 | 35 | } |
@@ -10,27 +10,27 @@ |
||
10 | 10 | */ |
11 | 11 | class T61String 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_T61_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_T61_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - // allow everything since there's literally |
|
33 | - // thousands of allowed characters (16 bit composed characters) |
|
34 | - return true; |
|
35 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + // allow everything since there's literally |
|
33 | + // thousands of allowed characters (16 bit composed characters) |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | */ |
11 | 11 | class GraphicString 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_GRAPHIC_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_GRAPHIC_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 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | */ |
11 | 11 | class ObjectDescriptor extends PrimitiveString |
12 | 12 | { |
13 | - use UniversalClass; |
|
13 | + use UniversalClass; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param string $descriptor |
|
19 | - */ |
|
20 | - public function __construct($descriptor) |
|
21 | - { |
|
22 | - $this->_string = $descriptor; |
|
23 | - $this->_typeTag = self::TYPE_OBJECT_DESCRIPTOR; |
|
24 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param string $descriptor |
|
19 | + */ |
|
20 | + public function __construct($descriptor) |
|
21 | + { |
|
22 | + $this->_string = $descriptor; |
|
23 | + $this->_typeTag = self::TYPE_OBJECT_DESCRIPTOR; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get the object descriptor. |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function descriptor() |
|
32 | - { |
|
33 | - return $this->_string; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Get the object descriptor. |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function descriptor() |
|
32 | + { |
|
33 | + return $this->_string; |
|
34 | + } |
|
35 | 35 | } |
@@ -14,112 +14,112 @@ |
||
14 | 14 | */ |
15 | 15 | class GeneralizedTime 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\d\d)' . /* YYYY */ |
|
29 | - '(\d\d)' . /* MM */ |
|
30 | - '(\d\d)' . /* DD */ |
|
31 | - '(\d\d)' . /* hh */ |
|
32 | - '(\d\d)' . /* mm */ |
|
33 | - '(\d\d)' . /* ss */ |
|
34 | - '(?:\.(\d+))?' . /* frac */ |
|
35 | - 'Z' . /* TZ */ |
|
36 | - '$#' /* @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\d\d)' . /* YYYY */ |
|
29 | + '(\d\d)' . /* MM */ |
|
30 | + '(\d\d)' . /* DD */ |
|
31 | + '(\d\d)' . /* hh */ |
|
32 | + '(\d\d)' . /* mm */ |
|
33 | + '(\d\d)' . /* ss */ |
|
34 | + '(?:\.(\d+))?' . /* frac */ |
|
35 | + 'Z' . /* TZ */ |
|
36 | + '$#' /* @formatter:on */; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Cached formatted date. |
|
40 | - * |
|
41 | - * @var string|null |
|
42 | - */ |
|
43 | - private $_formatted; |
|
38 | + /** |
|
39 | + * Cached formatted date. |
|
40 | + * |
|
41 | + * @var string|null |
|
42 | + */ |
|
43 | + private $_formatted; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param \DateTimeImmutable $dt |
|
49 | - */ |
|
50 | - public function __construct(\DateTimeImmutable $dt) |
|
51 | - { |
|
52 | - $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
53 | - parent::__construct($dt); |
|
54 | - } |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param \DateTimeImmutable $dt |
|
49 | + */ |
|
50 | + public function __construct(\DateTimeImmutable $dt) |
|
51 | + { |
|
52 | + $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
53 | + parent::__construct($dt); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Clear cached variables on clone. |
|
58 | - */ |
|
59 | - public function __clone() |
|
60 | - { |
|
61 | - $this->_formatted = null; |
|
62 | - } |
|
56 | + /** |
|
57 | + * Clear cached variables on clone. |
|
58 | + */ |
|
59 | + public function __clone() |
|
60 | + { |
|
61 | + $this->_formatted = null; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - protected function _encodedContentDER() |
|
69 | - { |
|
70 | - if (!isset($this->_formatted)) { |
|
71 | - $dt = $this->_dateTime->setTimezone( |
|
72 | - self::_createTimeZone(self::TZ_UTC)); |
|
73 | - $this->_formatted = $dt->format("YmdHis"); |
|
74 | - // if fractions were used |
|
75 | - $frac = $dt->format("u"); |
|
76 | - if ($frac != 0) { |
|
77 | - $frac = rtrim($frac, "0"); |
|
78 | - $this->_formatted .= ".$frac"; |
|
79 | - } |
|
80 | - // timezone |
|
81 | - $this->_formatted .= "Z"; |
|
82 | - } |
|
83 | - return $this->_formatted; |
|
84 | - } |
|
64 | + /** |
|
65 | + * |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + protected function _encodedContentDER() |
|
69 | + { |
|
70 | + if (!isset($this->_formatted)) { |
|
71 | + $dt = $this->_dateTime->setTimezone( |
|
72 | + self::_createTimeZone(self::TZ_UTC)); |
|
73 | + $this->_formatted = $dt->format("YmdHis"); |
|
74 | + // if fractions were used |
|
75 | + $frac = $dt->format("u"); |
|
76 | + if ($frac != 0) { |
|
77 | + $frac = rtrim($frac, "0"); |
|
78 | + $this->_formatted .= ".$frac"; |
|
79 | + } |
|
80 | + // timezone |
|
81 | + $this->_formatted .= "Z"; |
|
82 | + } |
|
83 | + return $this->_formatted; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * |
|
88 | - * {@inheritdoc} |
|
89 | - * @return self |
|
90 | - */ |
|
91 | - protected static function _decodeFromDER(Identifier $identifier, $data, |
|
92 | - &$offset) |
|
93 | - { |
|
94 | - $idx = $offset; |
|
95 | - $length = Length::expectFromDER($data, $idx); |
|
96 | - $str = substr($data, $idx, $length->length()); |
|
97 | - $idx += $length->length(); |
|
98 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
99 | - throw new DecodeException("Invalid GeneralizedTime format."); |
|
100 | - } |
|
101 | - list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
102 | - if (isset($match[7])) { |
|
103 | - $frac = $match[7]; |
|
104 | - // DER restricts trailing zeroes in fractional seconds component |
|
105 | - if ('0' === $frac[strlen($frac) - 1]) { |
|
106 | - throw new DecodeException( |
|
107 | - "Fractional seconds must omit trailing zeroes."); |
|
108 | - } |
|
109 | - $frac = (int) $frac; |
|
110 | - } else { |
|
111 | - $frac = 0; |
|
112 | - } |
|
113 | - $time = $year . $month . $day . $hour . $minute . $second . "." . $frac . |
|
114 | - self::TZ_UTC; |
|
115 | - $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time, |
|
116 | - self::_createTimeZone(self::TZ_UTC)); |
|
117 | - if (!$dt) { |
|
118 | - throw new DecodeException( |
|
119 | - "Failed to decode GeneralizedTime: " . |
|
120 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
121 | - } |
|
122 | - $offset = $idx; |
|
123 | - return new self($dt); |
|
124 | - } |
|
86 | + /** |
|
87 | + * |
|
88 | + * {@inheritdoc} |
|
89 | + * @return self |
|
90 | + */ |
|
91 | + protected static function _decodeFromDER(Identifier $identifier, $data, |
|
92 | + &$offset) |
|
93 | + { |
|
94 | + $idx = $offset; |
|
95 | + $length = Length::expectFromDER($data, $idx); |
|
96 | + $str = substr($data, $idx, $length->length()); |
|
97 | + $idx += $length->length(); |
|
98 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
99 | + throw new DecodeException("Invalid GeneralizedTime format."); |
|
100 | + } |
|
101 | + list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
102 | + if (isset($match[7])) { |
|
103 | + $frac = $match[7]; |
|
104 | + // DER restricts trailing zeroes in fractional seconds component |
|
105 | + if ('0' === $frac[strlen($frac) - 1]) { |
|
106 | + throw new DecodeException( |
|
107 | + "Fractional seconds must omit trailing zeroes."); |
|
108 | + } |
|
109 | + $frac = (int) $frac; |
|
110 | + } else { |
|
111 | + $frac = 0; |
|
112 | + } |
|
113 | + $time = $year . $month . $day . $hour . $minute . $second . "." . $frac . |
|
114 | + self::TZ_UTC; |
|
115 | + $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time, |
|
116 | + self::_createTimeZone(self::TZ_UTC)); |
|
117 | + if (!$dt) { |
|
118 | + throw new DecodeException( |
|
119 | + "Failed to decode GeneralizedTime: " . |
|
120 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
121 | + } |
|
122 | + $offset = $idx; |
|
123 | + return new self($dt); |
|
124 | + } |
|
125 | 125 | } |
@@ -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 | } |
@@ -14,64 +14,64 @@ |
||
14 | 14 | */ |
15 | 15 | class Boolean extends Element |
16 | 16 | { |
17 | - use UniversalClass; |
|
18 | - use PrimitiveType; |
|
17 | + use UniversalClass; |
|
18 | + use PrimitiveType; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Value. |
|
22 | - * |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - private $_bool; |
|
20 | + /** |
|
21 | + * Value. |
|
22 | + * |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + private $_bool; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Constructor. |
|
29 | - * |
|
30 | - * @param bool $bool |
|
31 | - */ |
|
32 | - public function __construct($bool) |
|
33 | - { |
|
34 | - $this->_typeTag = self::TYPE_BOOLEAN; |
|
35 | - $this->_bool = (bool) $bool; |
|
36 | - } |
|
27 | + /** |
|
28 | + * Constructor. |
|
29 | + * |
|
30 | + * @param bool $bool |
|
31 | + */ |
|
32 | + public function __construct($bool) |
|
33 | + { |
|
34 | + $this->_typeTag = self::TYPE_BOOLEAN; |
|
35 | + $this->_bool = (bool) $bool; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the value. |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function value() |
|
44 | - { |
|
45 | - return $this->_bool; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Get the value. |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function value() |
|
44 | + { |
|
45 | + return $this->_bool; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - protected function _encodedContentDER() |
|
53 | - { |
|
54 | - return $this->_bool ? chr(0xff) : chr(0); |
|
55 | - } |
|
48 | + /** |
|
49 | + * |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + protected function _encodedContentDER() |
|
53 | + { |
|
54 | + return $this->_bool ? chr(0xff) : chr(0); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * |
|
59 | - * {@inheritdoc} |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - protected static function _decodeFromDER(Identifier $identifier, $data, |
|
63 | - &$offset) |
|
64 | - { |
|
65 | - $idx = $offset; |
|
66 | - Length::expectFromDER($data, $idx, 1); |
|
67 | - $byte = ord($data[$idx++]); |
|
68 | - if ($byte != 0) { |
|
69 | - if ($byte != 0xff) { |
|
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($byte != 0); |
|
76 | - } |
|
57 | + /** |
|
58 | + * |
|
59 | + * {@inheritdoc} |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + protected static function _decodeFromDER(Identifier $identifier, $data, |
|
63 | + &$offset) |
|
64 | + { |
|
65 | + $idx = $offset; |
|
66 | + Length::expectFromDER($data, $idx, 1); |
|
67 | + $byte = ord($data[$idx++]); |
|
68 | + if ($byte != 0) { |
|
69 | + if ($byte != 0xff) { |
|
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($byte != 0); |
|
76 | + } |
|
77 | 77 | } |
@@ -10,25 +10,25 @@ |
||
10 | 10 | */ |
11 | 11 | class NumericString 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_NUMERIC_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_NUMERIC_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function _validateString($string) |
|
31 | - { |
|
32 | - return preg_match('/[^0-9 ]/', $string) == 0; |
|
33 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function _validateString($string) |
|
31 | + { |
|
32 | + return preg_match('/[^0-9 ]/', $string) == 0; |
|
33 | + } |
|
34 | 34 | } |
@@ -10,16 +10,16 @@ |
||
10 | 10 | */ |
11 | 11 | class OctetString 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_OCTET_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_OCTET_STRING; |
|
23 | + parent::__construct($string); |
|
24 | + } |
|
25 | 25 | } |