| 1 | <?php |
||
| 14 | abstract class Target |
||
| 15 | { |
||
| 16 | const TYPE_NAME = 0; |
||
| 17 | const TYPE_GROUP = 1; |
||
| 18 | const TYPE_CERT = 2; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Type tag. |
||
| 22 | * |
||
| 23 | * @var int $_type |
||
| 24 | */ |
||
| 25 | protected $_type; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Generate ASN.1 element. |
||
| 29 | * |
||
| 30 | * @return Element |
||
| 31 | */ |
||
| 32 | abstract public function toASN1(); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Get string value of the target. |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | abstract public function string(); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Initialize concrete object from the chocen ASN.1 element. |
||
| 43 | * |
||
| 44 | * @param TaggedType $el |
||
| 45 | * @return self |
||
| 46 | */ |
||
| 47 | 1 | public static function fromChosenASN1(TaggedType $el) { |
|
| 48 | 1 | throw new \BadMethodCallException( |
|
| 49 | 1 | __FUNCTION__ . " must be implemented in the derived class."); |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Parse from ASN.1. |
||
| 54 | * |
||
| 55 | * @param TaggedType $el |
||
| 56 | * @throws \UnexpectedValueException |
||
| 57 | * @return self |
||
| 58 | */ |
||
| 59 | 8 | public static function fromASN1(TaggedType $el) { |
|
| 60 | 8 | switch ($el->tag()) { |
|
| 61 | 8 | case self::TYPE_NAME: |
|
| 62 | 5 | return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 63 | 5 | case self::TYPE_GROUP: |
|
| 64 | 3 | return TargetGroup::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 65 | 2 | case self::TYPE_CERT: |
|
| 66 | 1 | throw new \RuntimeException("targetCert not supported."); |
|
| 67 | 1 | } |
|
| 68 | 1 | throw new \UnexpectedValueException( |
|
| 69 | 1 | "Target type " . $el->tag() . " not supported."); |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get type tag. |
||
| 74 | * |
||
| 75 | * @return int |
||
| 76 | */ |
||
| 77 | 4 | public function type() { |
|
| 80 | } |
||
| 81 |