|
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
|
2 |
|
*/ |
|
51
|
|
|
public static function fromASN1(Sequence $seq): self |
|
52
|
2 |
|
{ |
|
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
|
2 |
|
} |
|
57
|
2 |
|
|
|
58
|
2 |
|
/** |
|
59
|
|
|
* Get issuer domain policy. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string OID in dotted format |
|
62
|
|
|
*/ |
|
63
|
|
|
public function issuerDomainPolicy(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->_issuerDomainPolicy; |
|
66
|
10 |
|
} |
|
67
|
|
|
|
|
68
|
10 |
|
/** |
|
69
|
|
|
* Get subject domain policy. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string OID in dotted format |
|
72
|
|
|
*/ |
|
73
|
|
|
public function subjectDomainPolicy(): string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->_subjectDomainPolicy; |
|
76
|
9 |
|
} |
|
77
|
|
|
|
|
78
|
9 |
|
/** |
|
79
|
|
|
* Generate ASN.1 structure. |
|
80
|
|
|
* |
|
81
|
|
|
* @return Sequence |
|
82
|
|
|
*/ |
|
83
|
|
|
public function toASN1(): Sequence |
|
84
|
|
|
{ |
|
85
|
|
|
return new Sequence(new ObjectIdentifier($this->_issuerDomainPolicy), |
|
86
|
6 |
|
new ObjectIdentifier($this->_subjectDomainPolicy)); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|