Debian Codegraph @

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

raw symbols SCIP
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 * Implements *NoticeReference* ASN.1 type used by 'Certificate Policies' certificate extension.
13 *
14 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.4
15 */
16 final class NoticeReference
17 {
18 /**
19 * Notification reference numbers.
20 *
21 * @var int[]
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 * Initialize from ASN.1.
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 * Get reference organization.
55 */
56 public function organization(): DisplayText
57 {
58 return $this->organization;
59 }
60
61 /**
62 * Get reference numbers.
63 *
64 * @return int[]
65 */
66 public function numbers(): array
67 {
68 return $this->numbers;
69 }
70
71 /**
72 * Generate ASN.1 structure.
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 }