1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace X509\Certificate\Extension; |
5
|
|
|
|
6
|
|
|
use ASN1\Type\UnspecifiedType; |
7
|
|
|
use ASN1\Type\Constructed\Sequence; |
8
|
|
|
use X509\Certificate\Extension\AccessDescription\AccessDescription; |
9
|
|
|
use X509\Certificate\Extension\AccessDescription\AuthorityAccessDescription; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Implements 'Authority Information Access' extension. |
13
|
|
|
* |
14
|
|
|
* @link https://tools.ietf.org/html/rfc5280#section-4.2.2.1 |
15
|
|
|
*/ |
16
|
|
|
class AuthorityInformationAccessExtension extends Extension implements |
17
|
|
|
\Countable, |
18
|
|
|
\IteratorAggregate |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Access descriptions. |
22
|
|
|
* |
23
|
|
|
* @var AuthorityAccessDescription[] |
24
|
|
|
*/ |
25
|
|
|
private $_accessDescriptions; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param bool $critical |
31
|
|
|
* @param AuthorityAccessDescription ...$access |
32
|
|
|
*/ |
33
|
10 |
|
public function __construct(bool $critical, |
34
|
|
|
AuthorityAccessDescription ...$access) |
35
|
|
|
{ |
36
|
10 |
|
parent::__construct(self::OID_AUTHORITY_INFORMATION_ACCESS, $critical); |
37
|
10 |
|
$this->_accessDescriptions = $access; |
38
|
10 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* @return self |
44
|
|
|
*/ |
45
|
9 |
|
protected static function _fromDER(string $data, bool $critical): self |
46
|
|
|
{ |
47
|
9 |
|
$access = array_map( |
48
|
9 |
|
function (UnspecifiedType $el) { |
49
|
9 |
|
return AuthorityAccessDescription::fromASN1($el->asSequence()); |
50
|
9 |
|
}, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
51
|
9 |
|
return new self($critical, ...$access); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the access descriptions. |
56
|
|
|
* |
57
|
|
|
* @return AuthorityAccessDescription[] |
58
|
|
|
*/ |
59
|
1 |
|
public function accessDescriptions(): array |
60
|
|
|
{ |
61
|
1 |
|
return $this->_accessDescriptions; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
* @return Sequence |
68
|
|
|
*/ |
69
|
15 |
|
protected function _valueASN1(): Sequence |
70
|
|
|
{ |
71
|
15 |
|
$elements = array_map( |
72
|
15 |
|
function (AccessDescription $access) { |
73
|
15 |
|
return $access->toASN1(); |
74
|
15 |
|
}, $this->_accessDescriptions); |
75
|
15 |
|
return new Sequence(...$elements); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get the number of access descriptions. |
80
|
|
|
* |
81
|
|
|
* @see \Countable::count() |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
1 |
|
public function count(): int |
85
|
|
|
{ |
86
|
1 |
|
return count($this->_accessDescriptions); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get iterator for access descriptions. |
91
|
|
|
* |
92
|
|
|
* @see \IteratorAggregate::getIterator() |
93
|
|
|
* @return \ArrayIterator List of AuthorityAccessDescription objects |
94
|
|
|
*/ |
95
|
1 |
|
public function getIterator(): \ArrayIterator |
96
|
|
|
{ |
97
|
1 |
|
return new \ArrayIterator($this->_accessDescriptions); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|