SubjectKeyIdentifierExtension::__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;
6
7
use ASN1\Type\UnspecifiedType;
8
use ASN1\Type\Primitive\OctetString;
9
10
/**
11
 * Implements 'Subject Key Identifier' certificate extension.
12
 *
13
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.2
14
 */
15
class SubjectKeyIdentifierExtension extends Extension
16
{
17
    /**
18
     * Key identifier.
19
     *
20
     * @var string $_keyIdentifier
21
     */
22
    protected $_keyIdentifier;
23
    
24
    /**
25
     * Constructor.
26
     *
27
     * @param bool $critical
28
     * @param string $keyIdentifier
29
     */
30 18
    public function __construct(bool $critical, string $keyIdentifier)
31
    {
32 18
        parent::__construct(self::OID_SUBJECT_KEY_IDENTIFIER, $critical);
33 18
        $this->_keyIdentifier = $keyIdentifier;
34 18
    }
35
    
36
    /**
37
     *
38
     * {@inheritdoc}
39
     * @return self
40
     */
41 16
    protected static function _fromDER(string $data, bool $critical): self
42
    {
43 16
        return new self($critical,
44 16
            UnspecifiedType::fromDER($data)->asOctetString()->string());
45
    }
46
    
47
    /**
48
     * Get key identifier.
49
     *
50
     * @return string
51
     */
52 14
    public function keyIdentifier(): string
53
    {
54 14
        return $this->_keyIdentifier;
55
    }
56
    
57
    /**
58
     *
59
     * {@inheritdoc}
60
     * @return OctetString
61
     */
62 22
    protected function _valueASN1(): OctetString
63
    {
64 22
        return new OctetString($this->_keyIdentifier);
65
    }
66
}
67