1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Sop\X509\Certificate\Extension\PolicyMappings; |
6
|
|
|
|
7
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
8
|
|
|
use Sop\ASN1\Type\Primitive\ObjectIdentifier; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Implements ASN.1 type containing policy mapping values to be used |
12
|
|
|
* in 'Policy Mappings' certificate extension. |
13
|
|
|
* |
14
|
|
|
* @see https://tools.ietf.org/html/rfc5280#section-4.2.1.5 |
15
|
|
|
*/ |
16
|
|
|
class PolicyMapping |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* OID of the issuer policy. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $_issuerDomainPolicy; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* OID of the subject policy. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $_subjectDomainPolicy; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* @param string $issuer_policy OID of the issuer policy |
36
|
|
|
* @param string $subject_policy OID of the subject policy |
37
|
|
|
*/ |
38
|
6 |
|
public function __construct(string $issuer_policy, string $subject_policy) |
39
|
|
|
{ |
40
|
6 |
|
$this->_issuerDomainPolicy = $issuer_policy; |
41
|
6 |
|
$this->_subjectDomainPolicy = $subject_policy; |
42
|
6 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Initialize from ASN.1. |
46
|
|
|
* |
47
|
|
|
* @param Sequence $seq |
48
|
|
|
* |
49
|
|
|
* @return self |
50
|
|
|
*/ |
51
|
2 |
|
public static function fromASN1(Sequence $seq): self |
52
|
|
|
{ |
53
|
2 |
|
$issuer_policy = $seq->at(0)->asObjectIdentifier()->oid(); |
54
|
2 |
|
$subject_policy = $seq->at(1)->asObjectIdentifier()->oid(); |
55
|
2 |
|
return new self($issuer_policy, $subject_policy); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get issuer domain policy. |
60
|
|
|
* |
61
|
|
|
* @return string OID in dotted format |
62
|
|
|
*/ |
63
|
10 |
|
public function issuerDomainPolicy(): string |
64
|
|
|
{ |
65
|
10 |
|
return $this->_issuerDomainPolicy; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get subject domain policy. |
70
|
|
|
* |
71
|
|
|
* @return string OID in dotted format |
72
|
|
|
*/ |
73
|
9 |
|
public function subjectDomainPolicy(): string |
74
|
|
|
{ |
75
|
9 |
|
return $this->_subjectDomainPolicy; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Generate ASN.1 structure. |
80
|
|
|
* |
81
|
|
|
* @return Sequence |
82
|
|
|
*/ |
83
|
6 |
|
public function toASN1(): Sequence |
84
|
|
|
{ |
85
|
6 |
|
return new Sequence(new ObjectIdentifier($this->_issuerDomainPolicy), |
86
|
6 |
|
new ObjectIdentifier($this->_subjectDomainPolicy)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|