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