1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace X509\Certificate\Extension\CertificatePolicy; |
4
|
|
|
|
5
|
|
|
use ASN1\Element; |
6
|
|
|
use ASN1\Type\Constructed\Sequence; |
7
|
|
|
use ASN1\Type\Primitive\ObjectIdentifier; |
8
|
|
|
use ASN1\Type\UnspecifiedType; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base class for <i>PolicyQualifierInfo</i> ASN.1 types used by |
13
|
|
|
* 'Certificate Policies' certificate extension. |
14
|
|
|
* |
15
|
|
|
* @link https://tools.ietf.org/html/rfc5280#section-4.2.1.4 |
16
|
|
|
*/ |
17
|
|
|
abstract class PolicyQualifierInfo |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* OID for the CPS Pointer qualifier. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
const OID_CPS = "1.3.6.1.5.5.7.2.1"; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* OID for the user notice qualifier. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const OID_UNOTICE = "1.3.6.1.5.5.7.2.2"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Qualifier identifier. |
35
|
|
|
* |
36
|
|
|
* @var string $_oid |
37
|
|
|
*/ |
38
|
|
|
protected $_oid; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Generate ASN.1 for the 'qualifier' field. |
42
|
|
|
* |
43
|
|
|
* @return Element |
44
|
|
|
*/ |
45
|
|
|
abstract protected function _qualifierASN1(); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Initialize from qualifier ASN.1 element. |
49
|
|
|
* |
50
|
|
|
* @param UnspecifiedType $el |
51
|
|
|
* @return self |
52
|
|
|
*/ |
53
|
1 |
|
public static function fromQualifierASN1(UnspecifiedType $el) { |
54
|
|
|
throw new \BadMethodCallException( |
55
|
|
|
__FUNCTION__ . " must be implemented in the derived class."); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Initialize from ASN.1. |
60
|
|
|
* |
61
|
|
|
* @param Sequence $seq |
62
|
|
|
* @throws \UnexpectedValueException |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
10 |
|
public static function fromASN1(Sequence $seq) { |
66
|
10 |
|
$oid = $seq->at(0) |
67
|
10 |
|
->asObjectIdentifier() |
68
|
10 |
|
->oid(); |
69
|
|
|
switch ($oid) { |
70
|
10 |
|
case self::OID_CPS: |
71
|
8 |
|
return CPSQualifier::fromQualifierASN1($seq->at(1)); |
72
|
8 |
|
case self::OID_UNOTICE: |
73
|
7 |
|
return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
74
|
|
|
} |
75
|
1 |
|
throw new \UnexpectedValueException("Qualifier $oid not supported."); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get qualifier identifier. |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
12 |
|
public function oid() { |
84
|
12 |
|
return $this->_oid; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Generate ASN.1 structure. |
89
|
|
|
* |
90
|
|
|
* @return Sequence |
91
|
|
|
*/ |
92
|
6 |
|
public function toASN1() { |
93
|
6 |
|
return new Sequence(new ObjectIdentifier($this->_oid), |
94
|
6 |
|
$this->_qualifierASN1()); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|