ExtensionRequestValue::fromASN1()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace X509\CertificationRequest\Attribute;
6
7
use ASN1\Type\UnspecifiedType;
8
use ASN1\Type\Constructed\Sequence;
9
use X501\ASN1\AttributeValue\AttributeValue;
10
use X501\MatchingRule\BinaryMatch;
11
use X509\Certificate\Extensions;
12
13
/**
14
 * Implements value for 'Extension request' attribute.
15
 *
16
 * @link https://tools.ietf.org/html/rfc2985#page-17
17
 */
18
class ExtensionRequestValue extends AttributeValue
19
{
20
    const OID = "1.2.840.113549.1.9.14";
21
    
22
    /**
23
     * Extensions.
24
     *
25
     * @var Extensions $_extensions
26
     */
27
    protected $_extensions;
28
    
29
    /**
30
     * Constructor.
31
     *
32
     * @param Extensions $extensions
33
     */
34 11
    public function __construct(Extensions $extensions)
35
    {
36 11
        $this->_extensions = $extensions;
37 11
        $this->_oid = self::OID;
38 11
    }
39
    
40
    /**
41
     *
42
     * @see \X501\ASN1\AttributeValue\AttributeValue::fromASN1()
43
     * @param UnspecifiedType $el
44
     * @return self
45
     */
46 6
    public static function fromASN1(UnspecifiedType $el): self
47
    {
48 6
        return new self(Extensions::fromASN1($el->asSequence()));
49
    }
50
    
51
    /**
52
     * Get requested extensions.
53
     *
54
     * @return Extensions
55
     */
56 4
    public function extensions(): Extensions
57
    {
58 4
        return $this->_extensions;
59
    }
60
    
61
    /**
62
     *
63
     * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
64
     * @return Sequence
65
     */
66 10
    public function toASN1(): Sequence
67
    {
68 10
        return $this->_extensions->toASN1();
69
    }
70
    
71
    /**
72
     *
73
     * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
74
     * @return string
75
     */
76 3
    public function stringValue(): string
77
    {
78 3
        return "#" . bin2hex($this->toASN1()->toDER());
79
    }
80
    
81
    /**
82
     *
83
     * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
84
     * @return BinaryMatch
85
     */
86 1
    public function equalityMatchingRule(): BinaryMatch
87
    {
88 1
        return new BinaryMatch();
89
    }
90
    
91
    /**
92
     *
93
     * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
94
     * @return string
95
     */
96 1
    public function rfc2253String(): string
97
    {
98 1
        return $this->stringValue();
99
    }
100
    
101
    /**
102
     *
103
     * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
104
     * @return string
105
     */
106 1
    protected function _transcodedString(): string
107
    {
108 1
        return $this->stringValue();
109
    }
110
}
111