1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Sop\X509\Certificate\Extension\AccessDescription; |
6
|
|
|
|
7
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
8
|
|
|
use Sop\ASN1\Type\Primitive\ObjectIdentifier; |
9
|
|
|
use Sop\X509\GeneralName\GeneralName; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base class implementing <i>AccessDescription</i> ASN.1 type for |
13
|
|
|
* 'Authority Information Access' and 'Subject Information Access' certificate |
14
|
|
|
* extensions. |
15
|
|
|
* |
16
|
|
|
* @see https://tools.ietf.org/html/rfc5280#section-4.2.2.1 |
17
|
|
|
*/ |
18
|
|
|
abstract class AccessDescription |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Access method OID. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $_accessMethod; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Access location. |
29
|
|
|
* |
30
|
|
|
* @var GeneralName |
31
|
|
|
*/ |
32
|
|
|
protected $_accessLocation; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
* |
37
|
|
|
* @param string $method Access method OID |
38
|
|
|
* @param GeneralName $location Access location |
39
|
|
|
*/ |
40
|
16 |
|
public function __construct(string $method, GeneralName $location) |
41
|
|
|
{ |
42
|
16 |
|
$this->_accessMethod = $method; |
43
|
16 |
|
$this->_accessLocation = $location; |
44
|
16 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initialize from ASN.1. |
48
|
|
|
* |
49
|
|
|
* @param Sequence $seq |
50
|
|
|
* |
51
|
|
|
* @return self |
52
|
|
|
*/ |
53
|
12 |
|
public static function fromASN1(Sequence $seq): self |
54
|
|
|
{ |
55
|
12 |
|
return new static($seq->at(0)->asObjectIdentifier()->oid(), |
56
|
12 |
|
GeneralName::fromASN1($seq->at(1)->asTagged())); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the access method OID. |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
2 |
|
public function accessMethod(): string |
65
|
|
|
{ |
66
|
2 |
|
return $this->_accessMethod; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the access location. |
71
|
|
|
* |
72
|
|
|
* @return GeneralName |
73
|
|
|
*/ |
74
|
2 |
|
public function accessLocation(): GeneralName |
75
|
|
|
{ |
76
|
2 |
|
return $this->_accessLocation; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generate ASN.1 structure. |
81
|
|
|
* |
82
|
|
|
* @return Sequence |
83
|
|
|
*/ |
84
|
18 |
|
public function toASN1(): Sequence |
85
|
|
|
{ |
86
|
18 |
|
return new Sequence(new ObjectIdentifier($this->_accessMethod), |
87
|
18 |
|
$this->_accessLocation->toASN1()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|