1 | <?php |
||
14 | */ |
||
15 | abstract class Target |
||
16 | { |
||
17 | const TYPE_NAME = 0; |
||
18 | const TYPE_GROUP = 1; |
||
19 | const TYPE_CERT = 2; |
||
20 | |||
21 | /** |
||
22 | * Type tag. |
||
23 | * |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $_type; |
||
27 | |||
28 | /** |
||
29 | * Generate ASN.1 element. |
||
30 | * |
||
31 | * @return Element |
||
32 | */ |
||
33 | abstract public function toASN1(): Element; |
||
34 | |||
35 | /** |
||
36 | * Get string value of the target. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | abstract public function string(): string; |
||
41 | |||
42 | /** |
||
43 | * Initialize concrete object from the chosen ASN.1 element. |
||
44 | * |
||
45 | * @param TaggedType $el |
||
46 | * |
||
47 | * @return self |
||
48 | */ |
||
49 | 1 | public static function fromChosenASN1(TaggedType $el): Target |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Parse from ASN.1. |
||
57 | * |
||
58 | * @param TaggedType $el |
||
59 | * |
||
60 | * @throws \UnexpectedValueException |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | 8 | public static function fromASN1(TaggedType $el): self |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get type tag. |
||
80 | * |
||
81 | * @return int |
||
82 | */ |
||
83 | 8 | public function type(): int |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Check whether target is equal to another. |
||
90 | * |
||
91 | * @param Target $other |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | 8 | public function equals(Target $other): bool |
|
96 | { |
||
97 | 8 | if ($this->_type !== $other->_type) { |
|
98 | 1 | return false; |
|
99 | } |
||
100 | 7 | if ($this->toASN1()->toDER() !== $other->toASN1()->toDER()) { |
|
101 | 4 | return false; |
|
102 | } |
||
106 |