@@ -9,87 +9,87 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class TimeType extends Element |
11 | 11 | { |
12 | - /** |
|
13 | - * UTC timezone. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - const TZ_UTC = "UTC"; |
|
12 | + /** |
|
13 | + * UTC timezone. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + const TZ_UTC = "UTC"; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Date and time. |
|
21 | - * |
|
22 | - * @var \DateTimeImmutable $_dateTime |
|
23 | - */ |
|
24 | - protected $_dateTime; |
|
19 | + /** |
|
20 | + * Date and time. |
|
21 | + * |
|
22 | + * @var \DateTimeImmutable $_dateTime |
|
23 | + */ |
|
24 | + protected $_dateTime; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param \DateTimeImmutable $dt |
|
30 | - */ |
|
31 | - public function __construct(\DateTimeImmutable $dt) |
|
32 | - { |
|
33 | - $this->_dateTime = $dt; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param \DateTimeImmutable $dt |
|
30 | + */ |
|
31 | + public function __construct(\DateTimeImmutable $dt) |
|
32 | + { |
|
33 | + $this->_dateTime = $dt; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initialize from datetime string. |
|
38 | - * |
|
39 | - * @param string $time Time string |
|
40 | - * @param string|null $tz Timezone, if null use default. |
|
41 | - * @throws \RuntimeException |
|
42 | - * @return self |
|
43 | - */ |
|
44 | - public static function fromString($time, $tz = null) |
|
45 | - { |
|
46 | - try { |
|
47 | - if (!isset($tz)) { |
|
48 | - $tz = date_default_timezone_get(); |
|
49 | - } |
|
50 | - return new static( |
|
51 | - new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
52 | - } catch (\Exception $e) { |
|
53 | - throw new \RuntimeException( |
|
54 | - "Failed to create DateTime: " . |
|
55 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
56 | - } |
|
57 | - } |
|
36 | + /** |
|
37 | + * Initialize from datetime string. |
|
38 | + * |
|
39 | + * @param string $time Time string |
|
40 | + * @param string|null $tz Timezone, if null use default. |
|
41 | + * @throws \RuntimeException |
|
42 | + * @return self |
|
43 | + */ |
|
44 | + public static function fromString($time, $tz = null) |
|
45 | + { |
|
46 | + try { |
|
47 | + if (!isset($tz)) { |
|
48 | + $tz = date_default_timezone_get(); |
|
49 | + } |
|
50 | + return new static( |
|
51 | + new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
52 | + } catch (\Exception $e) { |
|
53 | + throw new \RuntimeException( |
|
54 | + "Failed to create DateTime: " . |
|
55 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Get the date and time. |
|
61 | - * |
|
62 | - * @return \DateTimeImmutable |
|
63 | - */ |
|
64 | - public function dateTime() |
|
65 | - { |
|
66 | - return $this->_dateTime; |
|
67 | - } |
|
59 | + /** |
|
60 | + * Get the date and time. |
|
61 | + * |
|
62 | + * @return \DateTimeImmutable |
|
63 | + */ |
|
64 | + public function dateTime() |
|
65 | + { |
|
66 | + return $this->_dateTime; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Create DateTimeZone object from string. |
|
71 | - * |
|
72 | - * @param string $tz |
|
73 | - * @throws \UnexpectedValueException If timezone is invalid |
|
74 | - * @return \DateTimeZone |
|
75 | - */ |
|
76 | - protected static function _createTimeZone($tz) |
|
77 | - { |
|
78 | - try { |
|
79 | - return new \DateTimeZone($tz); |
|
80 | - } catch (\Exception $e) { |
|
81 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
82 | - } |
|
83 | - } |
|
69 | + /** |
|
70 | + * Create DateTimeZone object from string. |
|
71 | + * |
|
72 | + * @param string $tz |
|
73 | + * @throws \UnexpectedValueException If timezone is invalid |
|
74 | + * @return \DateTimeZone |
|
75 | + */ |
|
76 | + protected static function _createTimeZone($tz) |
|
77 | + { |
|
78 | + try { |
|
79 | + return new \DateTimeZone($tz); |
|
80 | + } catch (\Exception $e) { |
|
81 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get last error caused by DateTimeImmutable. |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - protected static function _getLastDateTimeImmutableErrorsStr() |
|
91 | - { |
|
92 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
93 | - return implode(", ", $errors); |
|
94 | - } |
|
85 | + /** |
|
86 | + * Get last error caused by DateTimeImmutable. |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + protected static function _getLastDateTimeImmutableErrorsStr() |
|
91 | + { |
|
92 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
93 | + return implode(", ", $errors); |
|
94 | + } |
|
95 | 95 | } |
@@ -10,14 +10,14 @@ |
||
10 | 10 | */ |
11 | 11 | class Sequence extends Structure |
12 | 12 | { |
13 | - /** |
|
14 | - * Constructor |
|
15 | - * |
|
16 | - * @param Element ...$elements Any number of elements |
|
17 | - */ |
|
18 | - public function __construct(Element ...$elements) |
|
19 | - { |
|
20 | - $this->_typeTag = self::TYPE_SEQUENCE; |
|
21 | - parent::__construct(...$elements); |
|
22 | - } |
|
13 | + /** |
|
14 | + * Constructor |
|
15 | + * |
|
16 | + * @param Element ...$elements Any number of elements |
|
17 | + */ |
|
18 | + public function __construct(Element ...$elements) |
|
19 | + { |
|
20 | + $this->_typeTag = self::TYPE_SEQUENCE; |
|
21 | + parent::__construct(...$elements); |
|
22 | + } |
|
23 | 23 | } |
@@ -10,54 +10,54 @@ |
||
10 | 10 | */ |
11 | 11 | class Set extends Structure |
12 | 12 | { |
13 | - /** |
|
14 | - * Constructor |
|
15 | - * |
|
16 | - * @param Element ...$elements Any number of elements |
|
17 | - */ |
|
18 | - public function __construct(Element ...$elements) |
|
19 | - { |
|
20 | - $this->_typeTag = self::TYPE_SET; |
|
21 | - parent::__construct(...$elements); |
|
22 | - } |
|
13 | + /** |
|
14 | + * Constructor |
|
15 | + * |
|
16 | + * @param Element ...$elements Any number of elements |
|
17 | + */ |
|
18 | + public function __construct(Element ...$elements) |
|
19 | + { |
|
20 | + $this->_typeTag = self::TYPE_SET; |
|
21 | + parent::__construct(...$elements); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Sort by canonical ascending order. |
|
26 | - * Used for DER encoding of SET type. |
|
27 | - * |
|
28 | - * @return self |
|
29 | - */ |
|
30 | - public function sortedSet() |
|
31 | - { |
|
32 | - $obj = clone $this; |
|
33 | - usort($obj->_elements, |
|
34 | - function (Element $a, Element $b) { |
|
35 | - if ($a->typeClass() != $b->typeClass()) { |
|
36 | - return $a->typeClass() < $b->typeClass() ? -1 : 1; |
|
37 | - } |
|
38 | - if ($a->tag() == $b->tag()) { |
|
39 | - return 0; |
|
40 | - } |
|
41 | - return $a->tag() < $b->tag() ? -1 : 1; |
|
42 | - }); |
|
43 | - return $obj; |
|
44 | - } |
|
24 | + /** |
|
25 | + * Sort by canonical ascending order. |
|
26 | + * Used for DER encoding of SET type. |
|
27 | + * |
|
28 | + * @return self |
|
29 | + */ |
|
30 | + public function sortedSet() |
|
31 | + { |
|
32 | + $obj = clone $this; |
|
33 | + usort($obj->_elements, |
|
34 | + function (Element $a, Element $b) { |
|
35 | + if ($a->typeClass() != $b->typeClass()) { |
|
36 | + return $a->typeClass() < $b->typeClass() ? -1 : 1; |
|
37 | + } |
|
38 | + if ($a->tag() == $b->tag()) { |
|
39 | + return 0; |
|
40 | + } |
|
41 | + return $a->tag() < $b->tag() ? -1 : 1; |
|
42 | + }); |
|
43 | + return $obj; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Sort by encoding ascending order. |
|
48 | - * Used for DER encoding of SET OF type. |
|
49 | - * |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public function sortedSetOf() |
|
53 | - { |
|
54 | - $obj = clone $this; |
|
55 | - usort($obj->_elements, |
|
56 | - function (Element $a, Element $b) { |
|
57 | - $a_der = $a->toDER(); |
|
58 | - $b_der = $b->toDER(); |
|
59 | - return strcmp($a_der, $b_der); |
|
60 | - }); |
|
61 | - return $obj; |
|
62 | - } |
|
46 | + /** |
|
47 | + * Sort by encoding ascending order. |
|
48 | + * Used for DER encoding of SET OF type. |
|
49 | + * |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public function sortedSetOf() |
|
53 | + { |
|
54 | + $obj = clone $this; |
|
55 | + usort($obj->_elements, |
|
56 | + function (Element $a, Element $b) { |
|
57 | + $a_der = $a->toDER(); |
|
58 | + $b_der = $b->toDER(); |
|
59 | + return strcmp($a_der, $b_der); |
|
60 | + }); |
|
61 | + return $obj; |
|
62 | + } |
|
63 | 63 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | { |
32 | 32 | $obj = clone $this; |
33 | 33 | usort($obj->_elements, |
34 | - function (Element $a, Element $b) { |
|
34 | + function(Element $a, Element $b) { |
|
35 | 35 | if ($a->typeClass() != $b->typeClass()) { |
36 | 36 | return $a->typeClass() < $b->typeClass() ? -1 : 1; |
37 | 37 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | { |
54 | 54 | $obj = clone $this; |
55 | 55 | usort($obj->_elements, |
56 | - function (Element $a, Element $b) { |
|
56 | + function(Element $a, Element $b) { |
|
57 | 57 | $a_der = $a->toDER(); |
58 | 58 | $b_der = $b->toDER(); |
59 | 59 | return strcmp($a_der, $b_der); |
@@ -7,13 +7,13 @@ |
||
7 | 7 | */ |
8 | 8 | trait PrimitiveType |
9 | 9 | { |
10 | - /** |
|
11 | - * |
|
12 | - * @see \ASN1\Element::isConstructed() |
|
13 | - * @return boolean |
|
14 | - */ |
|
15 | - public function isConstructed() |
|
16 | - { |
|
17 | - return false; |
|
18 | - } |
|
10 | + /** |
|
11 | + * |
|
12 | + * @see \ASN1\Element::isConstructed() |
|
13 | + * @return boolean |
|
14 | + */ |
|
15 | + public function isConstructed() |
|
16 | + { |
|
17 | + return false; |
|
18 | + } |
|
19 | 19 | } |
@@ -12,50 +12,50 @@ |
||
12 | 12 | * is not changed. |
13 | 13 | */ |
14 | 14 | class ExplicitlyTaggedType extends ContextSpecificTaggedType implements |
15 | - ExplicitTagging |
|
15 | + ExplicitTagging |
|
16 | 16 | { |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param int $tag Tag number |
|
21 | - * @param Element $element Wrapped element |
|
22 | - */ |
|
23 | - public function __construct($tag, Element $element) |
|
24 | - { |
|
25 | - $this->_typeTag = $tag; |
|
26 | - $this->_element = $element; |
|
27 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param int $tag Tag number |
|
21 | + * @param Element $element Wrapped element |
|
22 | + */ |
|
23 | + public function __construct($tag, Element $element) |
|
24 | + { |
|
25 | + $this->_typeTag = $tag; |
|
26 | + $this->_element = $element; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * |
|
31 | - * @see \ASN1\Element::isConstructed() |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function isConstructed() |
|
35 | - { |
|
36 | - return true; |
|
37 | - } |
|
29 | + /** |
|
30 | + * |
|
31 | + * @see \ASN1\Element::isConstructed() |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function isConstructed() |
|
35 | + { |
|
36 | + return true; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * |
|
41 | - * @see \ASN1\Element::_encodedContentDER() |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - protected function _encodedContentDER() |
|
45 | - { |
|
46 | - return $this->_element->toDER(); |
|
47 | - } |
|
39 | + /** |
|
40 | + * |
|
41 | + * @see \ASN1\Element::_encodedContentDER() |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + protected function _encodedContentDER() |
|
45 | + { |
|
46 | + return $this->_element->toDER(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
52 | - * @return UnspecifiedType |
|
53 | - */ |
|
54 | - public function explicit($expectedTag = null) |
|
55 | - { |
|
56 | - if (isset($expectedTag)) { |
|
57 | - $this->_element->expectType($expectedTag); |
|
58 | - } |
|
59 | - return new UnspecifiedType($this->_element); |
|
60 | - } |
|
49 | + /** |
|
50 | + * |
|
51 | + * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
52 | + * @return UnspecifiedType |
|
53 | + */ |
|
54 | + public function explicit($expectedTag = null) |
|
55 | + { |
|
56 | + if (isset($expectedTag)) { |
|
57 | + $this->_element->expectType($expectedTag); |
|
58 | + } |
|
59 | + return new UnspecifiedType($this->_element); |
|
60 | + } |
|
61 | 61 | } |
@@ -10,20 +10,20 @@ |
||
10 | 10 | */ |
11 | 11 | abstract class ContextSpecificTaggedType extends TaggedType |
12 | 12 | { |
13 | - /** |
|
14 | - * Wrapped element. |
|
15 | - * |
|
16 | - * @var \ASN1\Element $_element |
|
17 | - */ |
|
18 | - protected $_element; |
|
13 | + /** |
|
14 | + * Wrapped element. |
|
15 | + * |
|
16 | + * @var \ASN1\Element $_element |
|
17 | + */ |
|
18 | + protected $_element; |
|
19 | 19 | |
20 | - /** |
|
21 | - * |
|
22 | - * @see \ASN1\Element::typeClass() |
|
23 | - * @return int |
|
24 | - */ |
|
25 | - public function typeClass() |
|
26 | - { |
|
27 | - return Identifier::CLASS_CONTEXT_SPECIFIC; |
|
28 | - } |
|
20 | + /** |
|
21 | + * |
|
22 | + * @see \ASN1\Element::typeClass() |
|
23 | + * @return int |
|
24 | + */ |
|
25 | + public function typeClass() |
|
26 | + { |
|
27 | + return Identifier::CLASS_CONTEXT_SPECIFIC; |
|
28 | + } |
|
29 | 29 | } |
@@ -14,55 +14,55 @@ |
||
14 | 14 | * decoding the data. |
15 | 15 | */ |
16 | 16 | class ImplicitlyTaggedType extends ContextSpecificTaggedType implements |
17 | - ImplicitTagging |
|
17 | + ImplicitTagging |
|
18 | 18 | { |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param int $tag |
|
23 | - * @param Element $element |
|
24 | - */ |
|
25 | - public function __construct($tag, Element $element) |
|
26 | - { |
|
27 | - $this->_typeTag = $tag; |
|
28 | - $this->_element = $element; |
|
29 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param int $tag |
|
23 | + * @param Element $element |
|
24 | + */ |
|
25 | + public function __construct($tag, Element $element) |
|
26 | + { |
|
27 | + $this->_typeTag = $tag; |
|
28 | + $this->_element = $element; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * |
|
33 | - * @see \ASN1\Element::isConstructed() |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isConstructed() |
|
37 | - { |
|
38 | - // depends on the underlying type |
|
39 | - return $this->_element->isConstructed(); |
|
40 | - } |
|
31 | + /** |
|
32 | + * |
|
33 | + * @see \ASN1\Element::isConstructed() |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isConstructed() |
|
37 | + { |
|
38 | + // depends on the underlying type |
|
39 | + return $this->_element->isConstructed(); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * |
|
44 | - * @see \ASN1\Element::_encodedContentDER() |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - protected function _encodedContentDER() |
|
48 | - { |
|
49 | - return $this->_element->_encodedContentDER(); |
|
50 | - } |
|
42 | + /** |
|
43 | + * |
|
44 | + * @see \ASN1\Element::_encodedContentDER() |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + protected function _encodedContentDER() |
|
48 | + { |
|
49 | + return $this->_element->_encodedContentDER(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * |
|
54 | - * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
55 | - * @return UnspecifiedType |
|
56 | - */ |
|
57 | - public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) |
|
58 | - { |
|
59 | - $this->_element->expectType($tag); |
|
60 | - if ($this->_element->typeClass() != $class) { |
|
61 | - throw new \UnexpectedValueException( |
|
62 | - sprintf("Type class %s expected, got %s.", |
|
63 | - Identifier::classToName($class), |
|
64 | - Identifier::classToName($this->_element->typeClass()))); |
|
65 | - } |
|
66 | - return new UnspecifiedType($this->_element); |
|
67 | - } |
|
52 | + /** |
|
53 | + * |
|
54 | + * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
55 | + * @return UnspecifiedType |
|
56 | + */ |
|
57 | + public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) |
|
58 | + { |
|
59 | + $this->_element->expectType($tag); |
|
60 | + if ($this->_element->typeClass() != $class) { |
|
61 | + throw new \UnexpectedValueException( |
|
62 | + sprintf("Type class %s expected, got %s.", |
|
63 | + Identifier::classToName($class), |
|
64 | + Identifier::classToName($this->_element->typeClass()))); |
|
65 | + } |
|
66 | + return new UnspecifiedType($this->_element); |
|
67 | + } |
|
68 | 68 | } |
@@ -9,15 +9,15 @@ |
||
9 | 9 | */ |
10 | 10 | interface ExplicitTagging extends ElementBase |
11 | 11 | { |
12 | - /** |
|
13 | - * Get explicitly tagged wrapped element. |
|
14 | - * |
|
15 | - * NOTE! Expectation checking is deprecated and shall be done |
|
16 | - * with UnspecifiedType. |
|
17 | - * |
|
18 | - * @param int|null $expectedTag Expected tag of the underlying type |
|
19 | - * @throws \UnexpectedValueException If expectation fails |
|
20 | - * @return \ASN1\Type\UnspecifiedType |
|
21 | - */ |
|
22 | - public function explicit($expectedTag = null); |
|
12 | + /** |
|
13 | + * Get explicitly tagged wrapped element. |
|
14 | + * |
|
15 | + * NOTE! Expectation checking is deprecated and shall be done |
|
16 | + * with UnspecifiedType. |
|
17 | + * |
|
18 | + * @param int|null $expectedTag Expected tag of the underlying type |
|
19 | + * @throws \UnexpectedValueException If expectation fails |
|
20 | + * @return \ASN1\Type\UnspecifiedType |
|
21 | + */ |
|
22 | + public function explicit($expectedTag = null); |
|
23 | 23 | } |
@@ -18,104 +18,104 @@ |
||
18 | 18 | * May be encoded back to complete DER encoding. |
19 | 19 | */ |
20 | 20 | class DERTaggedType extends TaggedType implements |
21 | - ExplicitTagging, |
|
22 | - ImplicitTagging |
|
21 | + ExplicitTagging, |
|
22 | + ImplicitTagging |
|
23 | 23 | { |
24 | - /** |
|
25 | - * Identifier. |
|
26 | - * |
|
27 | - * @var Identifier |
|
28 | - */ |
|
29 | - private $_identifier; |
|
24 | + /** |
|
25 | + * Identifier. |
|
26 | + * |
|
27 | + * @var Identifier |
|
28 | + */ |
|
29 | + private $_identifier; |
|
30 | 30 | |
31 | - /** |
|
32 | - * DER data. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $_data; |
|
31 | + /** |
|
32 | + * DER data. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $_data; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Offset to data. |
|
40 | - * |
|
41 | - * @var int |
|
42 | - */ |
|
43 | - private $_offset; |
|
38 | + /** |
|
39 | + * Offset to data. |
|
40 | + * |
|
41 | + * @var int |
|
42 | + */ |
|
43 | + private $_offset; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param Identifier $identifier |
|
49 | - * @param string $data |
|
50 | - * @param int $offset Offset to next byte after identifier |
|
51 | - */ |
|
52 | - public function __construct(Identifier $identifier, $data, $offset) |
|
53 | - { |
|
54 | - $this->_identifier = $identifier; |
|
55 | - $this->_data = $data; |
|
56 | - $this->_offset = $offset; |
|
57 | - $this->_typeTag = intval($identifier->tag()); |
|
58 | - } |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param Identifier $identifier |
|
49 | + * @param string $data |
|
50 | + * @param int $offset Offset to next byte after identifier |
|
51 | + */ |
|
52 | + public function __construct(Identifier $identifier, $data, $offset) |
|
53 | + { |
|
54 | + $this->_identifier = $identifier; |
|
55 | + $this->_data = $data; |
|
56 | + $this->_offset = $offset; |
|
57 | + $this->_typeTag = intval($identifier->tag()); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * |
|
62 | - * @see \ASN1\Element::typeClass() |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function typeClass() |
|
66 | - { |
|
67 | - return $this->_identifier->typeClass(); |
|
68 | - } |
|
60 | + /** |
|
61 | + * |
|
62 | + * @see \ASN1\Element::typeClass() |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function typeClass() |
|
66 | + { |
|
67 | + return $this->_identifier->typeClass(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * |
|
72 | - * @see \ASN1\Element::isConstructed() |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function isConstructed() |
|
76 | - { |
|
77 | - return $this->_identifier->isConstructed(); |
|
78 | - } |
|
70 | + /** |
|
71 | + * |
|
72 | + * @see \ASN1\Element::isConstructed() |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function isConstructed() |
|
76 | + { |
|
77 | + return $this->_identifier->isConstructed(); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * |
|
82 | - * @see \ASN1\Element::_encodedContentDER() |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - protected function _encodedContentDER() |
|
86 | - { |
|
87 | - $idx = $this->_offset; |
|
88 | - $length = Length::expectFromDER($this->_data, $idx); |
|
89 | - return substr($this->_data, $idx, $length->length()); |
|
90 | - } |
|
80 | + /** |
|
81 | + * |
|
82 | + * @see \ASN1\Element::_encodedContentDER() |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + protected function _encodedContentDER() |
|
86 | + { |
|
87 | + $idx = $this->_offset; |
|
88 | + $length = Length::expectFromDER($this->_data, $idx); |
|
89 | + return substr($this->_data, $idx, $length->length()); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * |
|
94 | - * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
95 | - * @return UnspecifiedType |
|
96 | - */ |
|
97 | - public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) |
|
98 | - { |
|
99 | - $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
100 | - $cls = self::_determineImplClass($identifier); |
|
101 | - $idx = $this->_offset; |
|
102 | - $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
103 | - return new UnspecifiedType($element); |
|
104 | - } |
|
92 | + /** |
|
93 | + * |
|
94 | + * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
95 | + * @return UnspecifiedType |
|
96 | + */ |
|
97 | + public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) |
|
98 | + { |
|
99 | + $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
100 | + $cls = self::_determineImplClass($identifier); |
|
101 | + $idx = $this->_offset; |
|
102 | + $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
103 | + return new UnspecifiedType($element); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * |
|
108 | - * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
109 | - * @return UnspecifiedType |
|
110 | - */ |
|
111 | - public function explicit($expectedTag = null) |
|
112 | - { |
|
113 | - $idx = $this->_offset; |
|
114 | - Length::expectFromDER($this->_data, $idx); |
|
115 | - $element = Element::fromDER($this->_data, $idx); |
|
116 | - if (isset($expectedTag)) { |
|
117 | - $element->expectType($expectedTag); |
|
118 | - } |
|
119 | - return new UnspecifiedType($element); |
|
120 | - } |
|
106 | + /** |
|
107 | + * |
|
108 | + * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
109 | + * @return UnspecifiedType |
|
110 | + */ |
|
111 | + public function explicit($expectedTag = null) |
|
112 | + { |
|
113 | + $idx = $this->_offset; |
|
114 | + Length::expectFromDER($this->_data, $idx); |
|
115 | + $element = Element::fromDER($this->_data, $idx); |
|
116 | + if (isset($expectedTag)) { |
|
117 | + $element->expectType($expectedTag); |
|
118 | + } |
|
119 | + return new UnspecifiedType($element); |
|
120 | + } |
|
121 | 121 | } |