@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -17,70 +17,70 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class UTCTime 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)' . // YY |
|
| 32 | - '(\d\d)' . // MM |
|
| 33 | - '(\d\d)' . // DD |
|
| 34 | - '(\d\d)' . // hh |
|
| 35 | - '(\d\d)' . // mm |
|
| 36 | - '(\d\d)' . // ss |
|
| 37 | - 'Z' . // TZ |
|
| 38 | - '$#'; |
|
| 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)' . // YY |
|
| 32 | + '(\d\d)' . // MM |
|
| 33 | + '(\d\d)' . // DD |
|
| 34 | + '(\d\d)' . // hh |
|
| 35 | + '(\d\d)' . // mm |
|
| 36 | + '(\d\d)' . // ss |
|
| 37 | + 'Z' . // TZ |
|
| 38 | + '$#'; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor. |
|
| 42 | - * |
|
| 43 | - * @param \DateTimeImmutable $dt |
|
| 44 | - */ |
|
| 45 | - public function __construct(\DateTimeImmutable $dt) |
|
| 46 | - { |
|
| 47 | - $this->_typeTag = self::TYPE_UTC_TIME; |
|
| 48 | - parent::__construct($dt); |
|
| 49 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor. |
|
| 42 | + * |
|
| 43 | + * @param \DateTimeImmutable $dt |
|
| 44 | + */ |
|
| 45 | + public function __construct(\DateTimeImmutable $dt) |
|
| 46 | + { |
|
| 47 | + $this->_typeTag = self::TYPE_UTC_TIME; |
|
| 48 | + parent::__construct($dt); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritdoc} |
|
| 53 | - */ |
|
| 54 | - protected function _encodedContentDER(): string |
|
| 55 | - { |
|
| 56 | - $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
| 57 | - return $dt->format('ymdHis\\Z'); |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritdoc} |
|
| 53 | + */ |
|
| 54 | + protected function _encodedContentDER(): string |
|
| 55 | + { |
|
| 56 | + $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
| 57 | + return $dt->format('ymdHis\\Z'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritdoc} |
|
| 62 | - */ |
|
| 63 | - protected static function _decodeFromDER(Identifier $identifier, |
|
| 64 | - string $data, int &$offset): ElementBase |
|
| 65 | - { |
|
| 66 | - $idx = $offset; |
|
| 67 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 68 | - $str = substr($data, $idx, $length); |
|
| 69 | - $idx += $length; |
|
| 70 | - /** @var string[] $match */ |
|
| 71 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
| 72 | - throw new DecodeException('Invalid UTCTime format.'); |
|
| 73 | - } |
|
| 74 | - [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
| 75 | - $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
| 76 | - $dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time, |
|
| 77 | - self::_createTimeZone(self::TZ_UTC)); |
|
| 78 | - if (!$dt) { |
|
| 79 | - throw new DecodeException( |
|
| 80 | - 'Failed to decode UTCTime: ' . |
|
| 81 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
| 82 | - } |
|
| 83 | - $offset = $idx; |
|
| 84 | - return new self($dt); |
|
| 85 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritdoc} |
|
| 62 | + */ |
|
| 63 | + protected static function _decodeFromDER(Identifier $identifier, |
|
| 64 | + string $data, int &$offset): ElementBase |
|
| 65 | + { |
|
| 66 | + $idx = $offset; |
|
| 67 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 68 | + $str = substr($data, $idx, $length); |
|
| 69 | + $idx += $length; |
|
| 70 | + /** @var string[] $match */ |
|
| 71 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
| 72 | + throw new DecodeException('Invalid UTCTime format.'); |
|
| 73 | + } |
|
| 74 | + [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
| 75 | + $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
| 76 | + $dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time, |
|
| 77 | + self::_createTimeZone(self::TZ_UTC)); |
|
| 78 | + if (!$dt) { |
|
| 79 | + throw new DecodeException( |
|
| 80 | + 'Failed to decode UTCTime: ' . |
|
| 81 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
| 82 | + } |
|
| 83 | + $offset = $idx; |
|
| 84 | + return new self($dt); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GeneralString 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_GENERAL_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_GENERAL_STRING; |
|
| 25 | + parent::__construct($string); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function _validateString(string $string): bool |
|
| 32 | - { |
|
| 33 | - // allow everything |
|
| 34 | - return true; |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function _validateString(string $string): bool |
|
| 32 | + { |
|
| 33 | + // allow everything |
|
| 34 | + return true; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -12,24 +12,24 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class NumericString 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_NUMERIC_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_NUMERIC_STRING; |
|
| 25 | + parent::__construct($string); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function _validateString(string $string): bool |
|
| 32 | - { |
|
| 33 | - return 0 == preg_match('/[^0-9 ]/', $string); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function _validateString(string $string): bool |
|
| 32 | + { |
|
| 33 | + return 0 == preg_match('/[^0-9 ]/', $string); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -12,24 +12,24 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class IA5String 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_IA5_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_IA5_STRING; |
|
| 25 | + parent::__construct($string); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function _validateString(string $string): bool |
|
| 32 | - { |
|
| 33 | - return 0 == preg_match('/[^\x01-\x7f]/', $string); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function _validateString(string $string): bool |
|
| 32 | + { |
|
| 33 | + return 0 == preg_match('/[^\x01-\x7f]/', $string); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class PrintableString 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_PRINTABLE_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_PRINTABLE_STRING; |
|
| 25 | + parent::__construct($string); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function _validateString(string $string): bool |
|
| 32 | - { |
|
| 33 | - $chars = preg_quote(" '()+,-./:=?]", '/'); |
|
| 34 | - return 0 == preg_match('/[^A-Za-z0-9' . $chars . ']/', $string); |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function _validateString(string $string): bool |
|
| 32 | + { |
|
| 33 | + $chars = preg_quote(" '()+,-./:=?]", '/'); |
|
| 34 | + return 0 == preg_match('/[^A-Za-z0-9' . $chars . ']/', $string); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -12,24 +12,24 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class VisibleString 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_VISIBLE_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_VISIBLE_STRING; |
|
| 25 | + parent::__construct($string); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - protected function _validateString(string $string): bool |
|
| 32 | - { |
|
| 33 | - return 0 == preg_match('/[^\x20-\x7e]/', $string); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + protected function _validateString(string $string): bool |
|
| 32 | + { |
|
| 33 | + return 0 == preg_match('/[^\x20-\x7e]/', $string); |
|
| 34 | + } |
|
| 35 | 35 | } |