1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace X509\Certificate\Extension; |
4
|
|
|
|
5
|
|
|
use ASN1\Type\Constructed\Sequence; |
6
|
|
|
use ASN1\Type\UnspecifiedType; |
7
|
|
|
use X509\Certificate\Extension\DistributionPoint\DistributionPoint; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Implements 'CRL Distribution Points' certificate extension. |
12
|
|
|
* |
13
|
|
|
* @link https://tools.ietf.org/html/rfc5280#section-4.2.1.13 |
14
|
|
|
*/ |
15
|
|
|
class CRLDistributionPointsExtension extends Extension implements \Countable, |
|
|
|
|
16
|
|
|
\IteratorAggregate |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Distribution points. |
20
|
|
|
* |
21
|
|
|
* @var DistributionPoint[] $_distributionPoints |
22
|
|
|
*/ |
23
|
|
|
protected $_distributionPoints; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
* |
28
|
|
|
* @param bool $critical |
29
|
|
|
* @param DistributionPoint ...$distribution_points |
30
|
|
|
*/ |
31
|
7 |
|
public function __construct($critical, |
32
|
|
|
DistributionPoint ...$distribution_points) { |
33
|
7 |
|
parent::__construct(self::OID_CRL_DISTRIBUTION_POINTS, $critical); |
34
|
7 |
|
$this->_distributionPoints = $distribution_points; |
35
|
7 |
|
} |
36
|
|
|
|
37
|
7 |
View Code Duplication |
protected static function _fromDER($data, $critical) { |
|
|
|
|
38
|
7 |
|
$dps = array_map( |
39
|
|
|
function (UnspecifiedType $el) { |
40
|
6 |
|
return DistributionPoint::fromASN1($el->asSequence()); |
41
|
7 |
|
}, Sequence::fromDER($data)->elements()); |
42
|
7 |
|
if (!count($dps)) { |
43
|
1 |
|
throw new \UnexpectedValueException( |
44
|
|
|
"CRLDistributionPoints must have" . |
45
|
1 |
|
" at least one DistributionPoint."); |
46
|
|
|
} |
47
|
|
|
// late static bound, extended by Freshest CRL extension |
48
|
6 |
|
return new static($critical, ...$dps); |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
View Code Duplication |
protected function _valueASN1() { |
|
|
|
|
52
|
4 |
|
if (!count($this->_distributionPoints)) { |
53
|
1 |
|
throw new \LogicException("No distribution points."); |
54
|
|
|
} |
55
|
3 |
|
$elements = array_map( |
56
|
3 |
|
function (DistributionPoint $dp) { |
57
|
3 |
|
return $dp->toASN1(); |
58
|
3 |
|
}, $this->_distributionPoints); |
59
|
3 |
|
return new Sequence(...$elements); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get distribution points. |
64
|
|
|
* |
65
|
|
|
* @return DistributionPoint[] |
66
|
|
|
*/ |
67
|
1 |
|
public function distributionPoints() { |
68
|
1 |
|
return $this->_distributionPoints; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the number of distribution points. |
73
|
|
|
* |
74
|
|
|
* @see Countable::count() |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
1 |
|
public function count() { |
78
|
1 |
|
return count($this->_distributionPoints); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get iterator for distribution points. |
83
|
|
|
* |
84
|
|
|
* @see IteratorAggregate::getIterator() |
85
|
|
|
* @return \ArrayIterator |
86
|
|
|
*/ |
87
|
3 |
|
public function getIterator() { |
88
|
3 |
|
return new \ArrayIterator($this->_distributionPoints); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|