@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type; |
| 6 | 6 | |
@@ -18,36 +18,36 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class PrimitiveString extends BaseString |
| 20 | 20 | { |
| 21 | - use PrimitiveType; |
|
| 21 | + use PrimitiveType; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * {@inheritdoc} |
|
| 25 | - */ |
|
| 26 | - protected function _encodedContentDER(): string |
|
| 27 | - { |
|
| 28 | - return $this->_string; |
|
| 29 | - } |
|
| 23 | + /** |
|
| 24 | + * {@inheritdoc} |
|
| 25 | + */ |
|
| 26 | + protected function _encodedContentDER(): string |
|
| 27 | + { |
|
| 28 | + return $this->_string; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * {@inheritdoc} |
|
| 33 | - */ |
|
| 34 | - protected static function _decodeFromDER(Identifier $identifier, |
|
| 35 | - string $data, int &$offset): ElementBase |
|
| 36 | - { |
|
| 37 | - $idx = $offset; |
|
| 38 | - if (!$identifier->isPrimitive()) { |
|
| 39 | - throw new DecodeException('DER encoded string must be primitive.'); |
|
| 40 | - } |
|
| 41 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 42 | - $str = $length ? substr($data, $idx, $length) : ''; |
|
| 43 | - // substr should never return false, since length is |
|
| 44 | - // checked by Length::expectFromDER. |
|
| 45 | - assert(is_string($str), new DecodeException('substr')); |
|
| 46 | - $offset = $idx + $length; |
|
| 47 | - try { |
|
| 48 | - return new static($str); |
|
| 49 | - } catch (\InvalidArgumentException $e) { |
|
| 50 | - throw new DecodeException($e->getMessage(), 0, $e); |
|
| 51 | - } |
|
| 52 | - } |
|
| 31 | + /** |
|
| 32 | + * {@inheritdoc} |
|
| 33 | + */ |
|
| 34 | + protected static function _decodeFromDER(Identifier $identifier, |
|
| 35 | + string $data, int &$offset): ElementBase |
|
| 36 | + { |
|
| 37 | + $idx = $offset; |
|
| 38 | + if (!$identifier->isPrimitive()) { |
|
| 39 | + throw new DecodeException('DER encoded string must be primitive.'); |
|
| 40 | + } |
|
| 41 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 42 | + $str = $length ? substr($data, $idx, $length) : ''; |
|
| 43 | + // substr should never return false, since length is |
|
| 44 | + // checked by Length::expectFromDER. |
|
| 45 | + assert(is_string($str), new DecodeException('substr')); |
|
| 46 | + $offset = $idx + $length; |
|
| 47 | + try { |
|
| 48 | + return new static($str); |
|
| 49 | + } catch (\InvalidArgumentException $e) { |
|
| 50 | + throw new DecodeException($e->getMessage(), 0, $e); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type; |
| 6 | 6 | |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface TimeType extends StringType |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Get the date and time. |
|
| 14 | - * |
|
| 15 | - * @return \DateTimeImmutable |
|
| 16 | - */ |
|
| 17 | - public function dateTime(): \DateTimeImmutable; |
|
| 12 | + /** |
|
| 13 | + * Get the date and time. |
|
| 14 | + * |
|
| 15 | + * @return \DateTimeImmutable |
|
| 16 | + */ |
|
| 17 | + public function dateTime(): \DateTimeImmutable; |
|
| 18 | 18 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -16,43 +16,43 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class ExplicitlyTaggedType extends TaggedTypeWrap implements ExplicitTagging |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Constructor. |
|
| 21 | - * |
|
| 22 | - * @param int $tag Tag number |
|
| 23 | - * @param Element $element Wrapped element |
|
| 24 | - * @param int $class Type class |
|
| 25 | - */ |
|
| 26 | - public function __construct(int $tag, Element $element, |
|
| 27 | - int $class = Identifier::CLASS_CONTEXT_SPECIFIC) |
|
| 28 | - { |
|
| 29 | - $this->_typeTag = $tag; |
|
| 30 | - $this->_element = $element; |
|
| 31 | - $this->_class = $class; |
|
| 32 | - } |
|
| 19 | + /** |
|
| 20 | + * Constructor. |
|
| 21 | + * |
|
| 22 | + * @param int $tag Tag number |
|
| 23 | + * @param Element $element Wrapped element |
|
| 24 | + * @param int $class Type class |
|
| 25 | + */ |
|
| 26 | + public function __construct(int $tag, Element $element, |
|
| 27 | + int $class = Identifier::CLASS_CONTEXT_SPECIFIC) |
|
| 28 | + { |
|
| 29 | + $this->_typeTag = $tag; |
|
| 30 | + $this->_element = $element; |
|
| 31 | + $this->_class = $class; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - */ |
|
| 37 | - public function isConstructed(): bool |
|
| 38 | - { |
|
| 39 | - return true; |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + */ |
|
| 37 | + public function isConstructed(): bool |
|
| 38 | + { |
|
| 39 | + return true; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * {@inheritdoc} |
|
| 44 | - */ |
|
| 45 | - public function explicit(): UnspecifiedType |
|
| 46 | - { |
|
| 47 | - return $this->_element->asUnspecified(); |
|
| 48 | - } |
|
| 42 | + /** |
|
| 43 | + * {@inheritdoc} |
|
| 44 | + */ |
|
| 45 | + public function explicit(): UnspecifiedType |
|
| 46 | + { |
|
| 47 | + return $this->_element->asUnspecified(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * {@inheritdoc} |
|
| 52 | - */ |
|
| 53 | - protected function _encodedContentDER(): string |
|
| 54 | - { |
|
| 55 | - // get the full encoding of the wrapped element |
|
| 56 | - return $this->_element->toDER(); |
|
| 57 | - } |
|
| 50 | + /** |
|
| 51 | + * {@inheritdoc} |
|
| 52 | + */ |
|
| 53 | + protected function _encodedContentDER(): string |
|
| 54 | + { |
|
| 55 | + // get the full encoding of the wrapped element |
|
| 56 | + return $this->_element->toDER(); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -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 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 UnspecifiedType |
|
| 25 | + */ |
|
| 26 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType; |
|
| 27 | 27 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -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 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -23,135 +23,135 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class DERTaggedType extends TaggedType implements ExplicitTagging, ImplicitTagging |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Identifier. |
|
| 28 | - * |
|
| 29 | - * @var Identifier |
|
| 30 | - */ |
|
| 31 | - private $_identifier; |
|
| 26 | + /** |
|
| 27 | + * Identifier. |
|
| 28 | + * |
|
| 29 | + * @var Identifier |
|
| 30 | + */ |
|
| 31 | + private $_identifier; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * DER data. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $_data; |
|
| 33 | + /** |
|
| 34 | + * DER data. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $_data; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Offset to next byte after identifier. |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - private $_offset; |
|
| 40 | + /** |
|
| 41 | + * Offset to next byte after identifier. |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + private $_offset; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Offset to content. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - private $_valueOffset; |
|
| 47 | + /** |
|
| 48 | + * Offset to content. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + private $_valueOffset; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Length of the content. |
|
| 56 | - * |
|
| 57 | - * @var int |
|
| 58 | - */ |
|
| 59 | - private $_valueLength; |
|
| 54 | + /** |
|
| 55 | + * Length of the content. |
|
| 56 | + * |
|
| 57 | + * @var int |
|
| 58 | + */ |
|
| 59 | + private $_valueLength; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Constructor. |
|
| 63 | - * |
|
| 64 | - * @param Identifier $identifier Pre-parsed identifier |
|
| 65 | - * @param string $data DER data |
|
| 66 | - * @param int $offset Offset to next byte after identifier |
|
| 67 | - * @param int $value_offset Offset to content |
|
| 68 | - * @param int $value_length Content length |
|
| 69 | - */ |
|
| 70 | - public function __construct(Identifier $identifier, string $data, |
|
| 71 | - int $offset, int $value_offset, int $value_length, |
|
| 72 | - bool $indefinite_length) |
|
| 73 | - { |
|
| 74 | - $this->_identifier = $identifier; |
|
| 75 | - $this->_data = $data; |
|
| 76 | - $this->_offset = $offset; |
|
| 77 | - $this->_valueOffset = $value_offset; |
|
| 78 | - $this->_valueLength = $value_length; |
|
| 79 | - $this->_indefiniteLength = $indefinite_length; |
|
| 80 | - $this->_typeTag = $identifier->intTag(); |
|
| 81 | - } |
|
| 61 | + /** |
|
| 62 | + * Constructor. |
|
| 63 | + * |
|
| 64 | + * @param Identifier $identifier Pre-parsed identifier |
|
| 65 | + * @param string $data DER data |
|
| 66 | + * @param int $offset Offset to next byte after identifier |
|
| 67 | + * @param int $value_offset Offset to content |
|
| 68 | + * @param int $value_length Content length |
|
| 69 | + */ |
|
| 70 | + public function __construct(Identifier $identifier, string $data, |
|
| 71 | + int $offset, int $value_offset, int $value_length, |
|
| 72 | + bool $indefinite_length) |
|
| 73 | + { |
|
| 74 | + $this->_identifier = $identifier; |
|
| 75 | + $this->_data = $data; |
|
| 76 | + $this->_offset = $offset; |
|
| 77 | + $this->_valueOffset = $value_offset; |
|
| 78 | + $this->_valueLength = $value_length; |
|
| 79 | + $this->_indefiniteLength = $indefinite_length; |
|
| 80 | + $this->_typeTag = $identifier->intTag(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * {@inheritdoc} |
|
| 85 | - */ |
|
| 86 | - public function typeClass(): int |
|
| 87 | - { |
|
| 88 | - return $this->_identifier->typeClass(); |
|
| 89 | - } |
|
| 83 | + /** |
|
| 84 | + * {@inheritdoc} |
|
| 85 | + */ |
|
| 86 | + public function typeClass(): int |
|
| 87 | + { |
|
| 88 | + return $this->_identifier->typeClass(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * {@inheritdoc} |
|
| 93 | - */ |
|
| 94 | - public function isConstructed(): bool |
|
| 95 | - { |
|
| 96 | - return $this->_identifier->isConstructed(); |
|
| 97 | - } |
|
| 91 | + /** |
|
| 92 | + * {@inheritdoc} |
|
| 93 | + */ |
|
| 94 | + public function isConstructed(): bool |
|
| 95 | + { |
|
| 96 | + return $this->_identifier->isConstructed(); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * {@inheritdoc} |
|
| 101 | - */ |
|
| 102 | - public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 103 | - { |
|
| 104 | - $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
| 105 | - $cls = self::_determineImplClass($identifier); |
|
| 106 | - $idx = $this->_offset; |
|
| 107 | - /** @var \Sop\ASN1\Feature\ElementBase $element */ |
|
| 108 | - $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
| 109 | - return $element->asUnspecified(); |
|
| 110 | - } |
|
| 99 | + /** |
|
| 100 | + * {@inheritdoc} |
|
| 101 | + */ |
|
| 102 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 103 | + { |
|
| 104 | + $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
| 105 | + $cls = self::_determineImplClass($identifier); |
|
| 106 | + $idx = $this->_offset; |
|
| 107 | + /** @var \Sop\ASN1\Feature\ElementBase $element */ |
|
| 108 | + $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
| 109 | + return $element->asUnspecified(); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * {@inheritdoc} |
|
| 114 | - */ |
|
| 115 | - public function explicit(): UnspecifiedType |
|
| 116 | - { |
|
| 117 | - $idx = $this->_valueOffset; |
|
| 118 | - return Element::fromDER($this->_data, $idx)->asUnspecified(); |
|
| 119 | - } |
|
| 112 | + /** |
|
| 113 | + * {@inheritdoc} |
|
| 114 | + */ |
|
| 115 | + public function explicit(): UnspecifiedType |
|
| 116 | + { |
|
| 117 | + $idx = $this->_valueOffset; |
|
| 118 | + return Element::fromDER($this->_data, $idx)->asUnspecified(); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * {@inheritdoc} |
|
| 123 | - */ |
|
| 124 | - protected static function _decodeFromDER(Identifier $identifier, |
|
| 125 | - string $data, int &$offset): ElementBase |
|
| 126 | - { |
|
| 127 | - $idx = $offset; |
|
| 128 | - $length = Length::expectFromDER($data, $idx); |
|
| 129 | - // offset to inner value |
|
| 130 | - $value_offset = $idx; |
|
| 131 | - if ($length->isIndefinite()) { |
|
| 132 | - if ($identifier->isPrimitive()) { |
|
| 133 | - throw new DecodeException( |
|
| 134 | - 'Primitive type with indefinite length is not supported.'); |
|
| 135 | - } |
|
| 136 | - while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC)); |
|
| 137 | - // EOC consists of two octets. |
|
| 138 | - $value_length = $idx - $value_offset - 2; |
|
| 139 | - } else { |
|
| 140 | - $value_length = $length->intLength(); |
|
| 141 | - $idx += $value_length; |
|
| 142 | - } |
|
| 143 | - // late static binding since ApplicationType and PrivateType extend this class |
|
| 144 | - $type = new static($identifier, $data, $offset, $value_offset, |
|
| 145 | - $value_length, $length->isIndefinite()); |
|
| 146 | - $offset = $idx; |
|
| 147 | - return $type; |
|
| 148 | - } |
|
| 121 | + /** |
|
| 122 | + * {@inheritdoc} |
|
| 123 | + */ |
|
| 124 | + protected static function _decodeFromDER(Identifier $identifier, |
|
| 125 | + string $data, int &$offset): ElementBase |
|
| 126 | + { |
|
| 127 | + $idx = $offset; |
|
| 128 | + $length = Length::expectFromDER($data, $idx); |
|
| 129 | + // offset to inner value |
|
| 130 | + $value_offset = $idx; |
|
| 131 | + if ($length->isIndefinite()) { |
|
| 132 | + if ($identifier->isPrimitive()) { |
|
| 133 | + throw new DecodeException( |
|
| 134 | + 'Primitive type with indefinite length is not supported.'); |
|
| 135 | + } |
|
| 136 | + while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC)); |
|
| 137 | + // EOC consists of two octets. |
|
| 138 | + $value_length = $idx - $value_offset - 2; |
|
| 139 | + } else { |
|
| 140 | + $value_length = $length->intLength(); |
|
| 141 | + $idx += $value_length; |
|
| 142 | + } |
|
| 143 | + // late static binding since ApplicationType and PrivateType extend this class |
|
| 144 | + $type = new static($identifier, $data, $offset, $value_offset, |
|
| 145 | + $value_length, $length->isIndefinite()); |
|
| 146 | + $offset = $idx; |
|
| 147 | + return $type; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * {@inheritdoc} |
|
| 152 | - */ |
|
| 153 | - protected function _encodedContentDER(): string |
|
| 154 | - { |
|
| 155 | - return substr($this->_data, $this->_valueOffset, $this->_valueLength); |
|
| 156 | - } |
|
| 150 | + /** |
|
| 151 | + * {@inheritdoc} |
|
| 152 | + */ |
|
| 153 | + protected function _encodedContentDER(): string |
|
| 154 | + { |
|
| 155 | + return substr($this->_data, $this->_valueOffset, $this->_valueLength); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\ASN1\Type\Tagged; |
| 6 | 6 | |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | interface ExplicitTagging extends ElementBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Get explicitly tagged wrapped element. |
|
| 17 | - * |
|
| 18 | - * @return UnspecifiedType |
|
| 19 | - */ |
|
| 20 | - public function explicit(): UnspecifiedType; |
|
| 15 | + /** |
|
| 16 | + * Get explicitly tagged wrapped element. |
|
| 17 | + * |
|
| 18 | + * @return UnspecifiedType |
|
| 19 | + */ |
|
| 20 | + public function explicit(): UnspecifiedType; |
|
| 21 | 21 | } |