AccessDescription   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 72
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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