| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Element; |
| 8 |
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; |
| 9 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier; |
| 10 |
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 11 |
use UnexpectedValueException; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
abstract class PolicyQualifierInfo |
| 19 |
{ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public const OID_CPS = '1.3.6.1.5.5.7.2.1'; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public const OID_UNOTICE = '1.3.6.1.5.5.7.2.2'; |
| 33 |
|
| 34 |
protected function __construct( |
| 35 |
protected string $oid |
| 36 |
) { |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
abstract public static function fromQualifierASN1(UnspecifiedType $el): self; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static function fromASN1(Sequence $seq): self |
| 48 |
{ |
| 49 |
$oid = $seq->at(0) |
| 50 |
->asObjectIdentifier() |
| 51 |
->oid(); |
| 52 |
return match ($oid) { |
| 53 |
self::OID_CPS => CPSQualifier::fromQualifierASN1($seq->at(1)), |
| 54 |
self::OID_UNOTICE => UserNoticeQualifier::fromQualifierASN1($seq->at(1)), |
| 55 |
default => throw new UnexpectedValueException("Qualifier {$oid} not supported."), |
| 56 |
}; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public function oid(): string |
| 63 |
{ |
| 64 |
return $this->oid; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public function toASN1(): Sequence |
| 71 |
{ |
| 72 |
return Sequence::create(ObjectIdentifier::create($this->oid), $this->qualifierASN1()); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
abstract protected function qualifierASN1(): Element; |
| 79 |
} |