| Total Complexity | 9 |
| Total Lines | 89 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
|
| 65 | { |
||
| 66 | 8 | switch ($el->tag()) { |
|
| 67 | 8 | case self::TYPE_NAME: |
|
| 68 | 5 | return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 69 | 5 | case self::TYPE_GROUP: |
|
| 70 | 3 | return TargetGroup::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 71 | 2 | case self::TYPE_CERT: |
|
| 72 | 1 | throw new \RuntimeException('targetCert not supported.'); |
|
| 73 | } |
||
| 74 | 1 | throw new \UnexpectedValueException( |
|
| 75 | 1 | 'Target type ' . $el->tag() . ' not supported.'); |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get type tag. |
||
| 80 | * |
||
| 81 | * @return int |
||
| 82 | */ |
||
| 83 | 8 | public function type(): int |
|
| 84 | { |
||
| 85 | 8 | return $this->_type; |
|
| 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 |
|
| 104 | } |
||
| 105 | } |
||
| 106 |