| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension; |
| 6 |
|
| 7 |
use ArrayIterator; |
| 8 |
use function count; |
| 9 |
use Countable; |
| 10 |
use IteratorAggregate; |
| 11 |
use SpomkyLabs\Pki\ASN1\Element; |
| 12 |
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; |
| 13 |
use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; |
| 14 |
use SpomkyLabs\Pki\X509\Certificate\Extension\AccessDescription\AccessDescription; |
| 15 |
use SpomkyLabs\Pki\X509\Certificate\Extension\AccessDescription\SubjectAccessDescription; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
final class SubjectInformationAccessExtension extends Extension implements Countable, IteratorAggregate |
| 23 |
{ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
private readonly array $accessDescriptions; |
| 30 |
|
| 31 |
private function __construct(bool $critical, SubjectAccessDescription ...$accessDescriptions) |
| 32 |
{ |
| 33 |
parent::__construct(self::OID_SUBJECT_INFORMATION_ACCESS, $critical); |
| 34 |
$this->accessDescriptions = $accessDescriptions; |
| 35 |
} |
| 36 |
|
| 37 |
public static function create(bool $critical, SubjectAccessDescription ...$accessDescriptions): self |
| 38 |
{ |
| 39 |
return new self($critical, ...$accessDescriptions); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function accessDescriptions(): array |
| 48 |
{ |
| 49 |
return $this->accessDescriptions; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public function count(): int |
| 58 |
{ |
| 59 |
return count($this->accessDescriptions); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function getIterator(): ArrayIterator |
| 69 |
{ |
| 70 |
return new ArrayIterator($this->accessDescriptions); |
| 71 |
} |
| 72 |
|
| 73 |
protected static function fromDER(string $data, bool $critical): static |
| 74 |
{ |
| 75 |
$access = array_map( |
| 76 |
static fn (UnspecifiedType $el) => SubjectAccessDescription::fromASN1($el->asSequence()), |
| 77 |
UnspecifiedType::fromDER($data)->asSequence()->elements() |
| 78 |
); |
| 79 |
return self::create($critical, ...$access); |
| 80 |
} |
| 81 |
|
| 82 |
protected function valueASN1(): Element |
| 83 |
{ |
| 84 |
$elements = array_map(static fn (AccessDescription $access) => $access->toASN1(), $this->accessDescriptions); |
| 85 |
return Sequence::create(...$elements); |
| 86 |
} |
| 87 |
} |