| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; |
| 8 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer; |
| 9 |
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
final class NoticeReference |
| 17 |
{ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
private readonly array $numbers; |
| 24 |
|
| 25 |
private function __construct( |
| 26 |
private readonly DisplayText $organization, |
| 27 |
int ...$numbers |
| 28 |
) { |
| 29 |
$this->numbers = $numbers; |
| 30 |
} |
| 31 |
|
| 32 |
public static function create(DisplayText $organization, int ...$numbers): self |
| 33 |
{ |
| 34 |
return new self($organization, ...$numbers); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static function fromASN1(Sequence $seq): self |
| 41 |
{ |
| 42 |
$org = DisplayText::fromASN1($seq->at(0)->asString()); |
| 43 |
$numbers = array_map( |
| 44 |
static fn (UnspecifiedType $el) => $el->asInteger() |
| 45 |
->intNumber(), |
| 46 |
$seq->at(1) |
| 47 |
->asSequence() |
| 48 |
->elements() |
| 49 |
); |
| 50 |
return self::create($org, ...$numbers); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function organization(): DisplayText |
| 57 |
{ |
| 58 |
return $this->organization; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function numbers(): array |
| 67 |
{ |
| 68 |
return $this->numbers; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public function toASN1(): Sequence |
| 75 |
{ |
| 76 |
$org = $this->organization->toASN1(); |
| 77 |
$nums = array_map(Integer::create(...), $this->numbers); |
| 78 |
return Sequence::create($org, Sequence::create(...$nums)); |
| 79 |
} |
| 80 |
} |