PolicyMapping::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace X509\Certificate\Extension\PolicyMappings;
6
7
use ASN1\Type\Constructed\Sequence;
8
use 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
 * @link 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 $_issuerDomainPolicy
22
     */
23
    protected $_issuerDomainPolicy;
24
    
25
    /**
26
     * OID of the subject policy.
27
     *
28
     * @var string $_subjectDomainPolicy
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
     * @return self
49
     */
50 2
    public static function fromASN1(Sequence $seq): self
51
    {
52 2
        $issuer_policy = $seq->at(0)
53 2
            ->asObjectIdentifier()
54 2
            ->oid();
55 2
        $subject_policy = $seq->at(1)
56 2
            ->asObjectIdentifier()
57 2
            ->oid();
58 2
        return new self($issuer_policy, $subject_policy);
59
    }
60
    
61
    /**
62
     * Get issuer domain policy.
63
     *
64
     * @return string OID in dotted format
65
     */
66 10
    public function issuerDomainPolicy(): string
67
    {
68 10
        return $this->_issuerDomainPolicy;
69
    }
70
    
71
    /**
72
     * Get subject domain policy.
73
     *
74
     * @return string OID in dotted format
75
     */
76 9
    public function subjectDomainPolicy(): string
77
    {
78 9
        return $this->_subjectDomainPolicy;
79
    }
80
    
81
    /**
82
     * Generate ASN.1 structure.
83
     *
84
     * @return Sequence
85
     */
86 6
    public function toASN1(): Sequence
87
    {
88 6
        return new Sequence(new ObjectIdentifier($this->_issuerDomainPolicy),
89 6
            new ObjectIdentifier($this->_subjectDomainPolicy));
90
    }
91
}
92