1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Sop\X509\Certificate\Extension\CertificatePolicy; |
6
|
|
|
|
7
|
|
|
use Sop\ASN1\Element; |
8
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
9
|
|
|
use Sop\ASN1\Type\UnspecifiedType; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Implements <i>UserNotice</i> ASN.1 type used by |
13
|
|
|
* 'Certificate Policies' certificate extension. |
14
|
|
|
* |
15
|
|
|
* @see https://tools.ietf.org/html/rfc5280#section-4.2.1.4 |
16
|
|
|
*/ |
17
|
|
|
class UserNoticeQualifier extends PolicyQualifierInfo |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Explicit notice text. |
21
|
|
|
* |
22
|
|
|
* @var null|DisplayText |
23
|
|
|
*/ |
24
|
|
|
protected $_text; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Notice reference. |
28
|
|
|
* |
29
|
|
|
* @var null|NoticeReference |
30
|
|
|
*/ |
31
|
|
|
protected $_ref; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor. |
35
|
|
|
* |
36
|
|
|
* @param null|DisplayText $text |
37
|
|
|
* @param null|NoticeReference $ref |
38
|
|
|
*/ |
39
|
16 |
|
public function __construct(?DisplayText $text = null, |
40
|
|
|
?NoticeReference $ref = null) |
41
|
|
|
{ |
42
|
16 |
|
$this->_oid = self::OID_UNOTICE; |
43
|
16 |
|
$this->_text = $text; |
44
|
16 |
|
$this->_ref = $ref; |
45
|
16 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
* |
50
|
|
|
* @return self |
51
|
|
|
*/ |
52
|
11 |
|
public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
53
|
|
|
{ |
54
|
11 |
|
$seq = $el->asSequence(); |
55
|
11 |
|
$ref = null; |
56
|
11 |
|
$text = null; |
57
|
11 |
|
$idx = 0; |
58
|
11 |
|
if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
59
|
10 |
|
$ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
60
|
|
|
} |
61
|
11 |
|
if ($seq->has($idx, Element::TYPE_STRING)) { |
62
|
11 |
|
$text = DisplayText::fromASN1($seq->at($idx)->asString()); |
63
|
|
|
} |
64
|
11 |
|
return new self($text, $ref); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Whether explicit text is present. |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
5 |
|
public function hasExplicitText(): bool |
73
|
|
|
{ |
74
|
5 |
|
return isset($this->_text); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get explicit text. |
79
|
|
|
* |
80
|
|
|
* @throws \LogicException If not set |
81
|
|
|
* |
82
|
|
|
* @return DisplayText |
83
|
|
|
*/ |
84
|
5 |
|
public function explicitText(): DisplayText |
85
|
|
|
{ |
86
|
5 |
|
if (!$this->hasExplicitText()) { |
87
|
1 |
|
throw new \LogicException('explicitText not set.'); |
88
|
|
|
} |
89
|
4 |
|
return $this->_text; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Whether notice reference is present. |
94
|
|
|
* |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
4 |
|
public function hasNoticeRef(): bool |
98
|
|
|
{ |
99
|
4 |
|
return isset($this->_ref); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get notice reference. |
104
|
|
|
* |
105
|
|
|
* @throws \LogicException If not set |
106
|
|
|
* |
107
|
|
|
* @return NoticeReference |
108
|
|
|
*/ |
109
|
4 |
|
public function noticeRef(): NoticeReference |
110
|
|
|
{ |
111
|
4 |
|
if (!$this->hasNoticeRef()) { |
112
|
1 |
|
throw new \LogicException('noticeRef not set.'); |
113
|
|
|
} |
114
|
3 |
|
return $this->_ref; |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
18 |
|
protected function _qualifierASN1(): Element |
121
|
|
|
{ |
122
|
18 |
|
$elements = []; |
123
|
18 |
|
if (isset($this->_ref)) { |
124
|
16 |
|
$elements[] = $this->_ref->toASN1(); |
|
|
|
|
125
|
|
|
} |
126
|
18 |
|
if (isset($this->_text)) { |
127
|
18 |
|
$elements[] = $this->_text->toASN1(); |
|
|
|
|
128
|
|
|
} |
129
|
18 |
|
return new Sequence(...$elements); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|