Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/Certificate/Extension/SubjectInformationAccessExtension.php

raw symbols SCIP
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 * Implements 'Subject Information Access' extension.
19 *
20 * @see https://tools.ietf.org/html/rfc5280#section-4.2.2.2
21 */
22 final class SubjectInformationAccessExtension extends Extension implements Countable, IteratorAggregate
23 {
24 /**
25 * Access descriptions.
26 *
27 * @var SubjectAccessDescription[]
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 * Get the access descriptions.
44 *
45 * @return SubjectAccessDescription[]
46 */
47 public function accessDescriptions(): array
48 {
49 return $this->accessDescriptions;
50 }
51
52 /**
53 * Get the number of access descriptions.
54 *
55 * @see \Countable::count()
56 */
57 public function count(): int
58 {
59 return count($this->accessDescriptions);
60 }
61
62 /**
63 * Get iterator for access descriptions.
64 *
65 * @return ArrayIterator List of SubjectAccessDescription objects
66 * @see \IteratorAggregate::getIterator()
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 }