|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace X509\Certificate\Extension\CertificatePolicy; |
|
6
|
|
|
|
|
7
|
|
|
use ASN1\Type\UnspecifiedType; |
|
8
|
|
|
use ASN1\Type\Constructed\Sequence; |
|
9
|
|
|
use ASN1\Type\Primitive\Integer; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Implements <i>NoticeReference</i> ASN.1 type used by |
|
13
|
|
|
* 'Certificate Policies' certificate extension. |
|
14
|
|
|
* |
|
15
|
|
|
* @link https://tools.ietf.org/html/rfc5280#section-4.2.1.4 |
|
16
|
|
|
*/ |
|
17
|
|
|
class NoticeReference |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Organization. |
|
21
|
|
|
* |
|
22
|
|
|
* @var DisplayText $_organization |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $_organization; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Notification reference numbers. |
|
28
|
|
|
* |
|
29
|
|
|
* @var int[] $_numbers |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $_numbers; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param DisplayText $organization |
|
37
|
|
|
* @param int ...$numbers |
|
38
|
|
|
*/ |
|
39
|
14 |
|
public function __construct(DisplayText $organization, int ...$numbers) |
|
40
|
|
|
{ |
|
41
|
14 |
|
$this->_organization = $organization; |
|
42
|
14 |
|
$this->_numbers = $numbers; |
|
43
|
14 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Initialize from ASN.1. |
|
47
|
|
|
* |
|
48
|
|
|
* @param Sequence $seq |
|
49
|
|
|
* @return self |
|
50
|
|
|
*/ |
|
51
|
11 |
|
public static function fromASN1(Sequence $seq): self |
|
52
|
|
|
{ |
|
53
|
11 |
|
$org = DisplayText::fromASN1($seq->at(0)->asString()); |
|
54
|
11 |
|
$numbers = array_map( |
|
55
|
11 |
|
function (UnspecifiedType $el) { |
|
56
|
11 |
|
return $el->asInteger()->intNumber(); |
|
57
|
11 |
|
}, |
|
58
|
11 |
|
$seq->at(1) |
|
59
|
11 |
|
->asSequence() |
|
60
|
11 |
|
->elements()); |
|
61
|
11 |
|
return new self($org, ...$numbers); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get reference organization. |
|
66
|
|
|
* |
|
67
|
|
|
* @return DisplayText |
|
68
|
|
|
*/ |
|
69
|
3 |
|
public function organization(): DisplayText |
|
70
|
|
|
{ |
|
71
|
3 |
|
return $this->_organization; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get reference numbers. |
|
76
|
|
|
* |
|
77
|
|
|
* @return int[] |
|
78
|
|
|
*/ |
|
79
|
3 |
|
public function numbers(): array |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->_numbers; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Generate ASN.1 structure. |
|
86
|
|
|
* |
|
87
|
|
|
* @return Sequence |
|
88
|
|
|
*/ |
|
89
|
17 |
|
public function toASN1(): Sequence |
|
90
|
|
|
{ |
|
91
|
17 |
|
$org = $this->_organization->toASN1(); |
|
92
|
17 |
|
$nums = array_map( |
|
93
|
17 |
|
function ($number) { |
|
94
|
17 |
|
return new Integer($number); |
|
95
|
17 |
|
}, $this->_numbers); |
|
96
|
17 |
|
return new Sequence($org, new Sequence(...$nums)); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|