IssuerAlternativeNameExtension::_fromDER()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
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;
6
7
use ASN1\Type\UnspecifiedType;
8
use ASN1\Type\Constructed\Sequence;
9
use X509\GeneralName\GeneralNames;
10
11
/**
12
 * Implements 'Issuer Alternative Name' certificate extension.
13
 *
14
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.7
15
 */
16
class IssuerAlternativeNameExtension extends Extension
17
{
18
    /**
19
     * Names.
20
     *
21
     * @var GeneralNames
22
     */
23
    protected $_names;
24
    
25
    /**
26
     * Constructor.
27
     *
28
     * @param bool $critical
29
     * @param GeneralNames $names
30
     */
31 10
    public function __construct(bool $critical, GeneralNames $names)
32
    {
33 10
        parent::__construct(self::OID_ISSUER_ALT_NAME, $critical);
34 10
        $this->_names = $names;
35 10
    }
36
    
37
    /**
38
     *
39
     * {@inheritdoc}
40
     * @return self
41
     */
42 9
    protected static function _fromDER(string $data, bool $critical)
43
    {
44 9
        return new self($critical,
45 9
            GeneralNames::fromASN1(
46 9
                UnspecifiedType::fromDER($data)->asSequence()));
47
    }
48
    
49
    /**
50
     * Get names.
51
     *
52
     * @return GeneralNames
53
     */
54 2
    public function names(): GeneralNames
55
    {
56 2
        return $this->_names;
57
    }
58
    
59
    /**
60
     *
61
     * {@inheritdoc}
62
     * @return Sequence
63
     */
64 15
    protected function _valueASN1(): Sequence
65
    {
66 15
        return $this->_names->toASN1();
67
    }
68
}
69