| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension; |
| 6 |
|
| 7 |
use BadMethodCallException; |
| 8 |
use SpomkyLabs\Pki\ASN1\Element; |
| 9 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\NullType; |
| 10 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
final class UnknownExtension extends Extension |
| 16 |
{ |
| 17 |
private function __construct( |
| 18 |
string $oid, |
| 19 |
bool $critical, |
| 20 |
private readonly Element $element, |
| 21 |
private readonly string $data |
| 22 |
) { |
| 23 |
parent::__construct($oid, $critical); |
| 24 |
} |
| 25 |
|
| 26 |
public static function create(string $oid, bool $critical, Element $element): self |
| 27 |
{ |
| 28 |
return new self($oid, $critical, $element, $element->toDER()); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public static function fromRawString(string $oid, bool $critical, string $data): self |
| 35 |
{ |
| 36 |
return new self($oid, $critical, NullType::create(), $data); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function extensionValue(): string |
| 43 |
{ |
| 44 |
return $this->data; |
| 45 |
} |
| 46 |
|
| 47 |
protected function extnValue(): OctetString |
| 48 |
{ |
| 49 |
return OctetString::create($this->data); |
| 50 |
} |
| 51 |
|
| 52 |
protected function valueASN1(): Element |
| 53 |
{ |
| 54 |
return $this->element; |
| 55 |
} |
| 56 |
|
| 57 |
protected static function fromDER(string $data, bool $critical): static |
| 58 |
{ |
| 59 |
throw new BadMethodCallException(__FUNCTION__ . ' must be implemented in derived class.'); |
| 60 |
} |
| 61 |
} |