GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Pull Request — master (#1)
by thomas
05:34
created

RoleAttributeValue   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 10
dl 0
loc 153
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromString() 0 4 1
A fromASN1() 0 16 2
A hasRoleAuthority() 0 4 1
A roleAuthority() 0 7 2
A roleName() 0 4 1
A toASN1() 0 10 2
A stringValue() 0 4 1
A equalityMatchingRule() 0 4 1
A rfc2253String() 0 4 1
A _transcodedString() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace X509\AttributeCertificate\Attribute;
6
7
use ASN1\Element;
8
use ASN1\Type\UnspecifiedType;
9
use ASN1\Type\Constructed\Sequence;
10
use ASN1\Type\Tagged\ExplicitlyTaggedType;
11
use ASN1\Type\Tagged\ImplicitlyTaggedType;
12
use X501\ASN1\AttributeType;
13
use X501\ASN1\AttributeValue\AttributeValue;
14
use X501\MatchingRule\BinaryMatch;
15
use X509\GeneralName\GeneralName;
16
use X509\GeneralName\GeneralNames;
17
use X509\GeneralName\UniformResourceIdentifier;
18
19
/**
20
 * Implements value for 'Role' attribute.
21
 *
22
 * @link https://tools.ietf.org/html/rfc5755#section-4.4.5
23
 */
24
class RoleAttributeValue extends AttributeValue
25
{
26
    /**
27
     * Issuing authority.
28
     *
29
     * @var GeneralNames $_roleAuthority
30
     */
31
    protected $_roleAuthority;
32
    
33
    /**
34
     * Role name.
35
     *
36
     * @var GeneralName $_roleName
37
     */
38
    protected $_roleName;
39
    
40
    /**
41
     * Constructor.
42
     *
43
     * @param GeneralName $name Role name
44
     * @param GeneralNames|null $authority Issuing authority
45
     */
46
    public function __construct(GeneralName $name, GeneralNames $authority = null)
47
    {
48
        $this->_roleAuthority = $authority;
49
        $this->_roleName = $name;
50
        $this->_oid = AttributeType::OID_ROLE;
51
    }
52
    
53
    /**
54
     * Initialize from a role string.
55
     *
56
     * @param string $role_name Role name in URI format
57
     * @param GeneralNames|null $authority Issuing authority
58
     * @return self
59
     */
60
    public static function fromString(string $role_name, GeneralNames $authority = null)
61
    {
62
        return new self(new UniformResourceIdentifier($role_name), $authority);
63
    }
64
    
65
    /**
66
     *
67
     * @param UnspecifiedType $el
68
     * @return self
69
     */
70
    public static function fromASN1(UnspecifiedType $el)
71
    {
72
        $seq = $el->asSequence();
73
        $authority = null;
74
        if ($seq->hasTagged(0)) {
75
            $authority = GeneralNames::fromASN1(
76
                $seq->getTagged(0)
77
                    ->asImplicit(Element::TYPE_SEQUENCE)
78
                    ->asSequence());
79
        }
80
        $name = GeneralName::fromASN1(
81
            $seq->getTagged(1)
82
                ->asExplicit()
83
                ->asTagged());
84
        return new self($name, $authority);
85
    }
86
    
87
    /**
88
     * Check whether issuing authority is present.
89
     *
90
     * @return bool
91
     */
92
    public function hasRoleAuthority(): bool
93
    {
94
        return isset($this->_roleAuthority);
95
    }
96
    
97
    /**
98
     * Get issuing authority.
99
     *
100
     * @throws \LogicException
101
     * @return GeneralNames
102
     */
103
    public function roleAuthority(): GeneralNames
104
    {
105
        if (!$this->hasRoleAuthority()) {
106
            throw new \LogicException("roleAuthority not set.");
107
        }
108
        return $this->_roleAuthority;
109
    }
110
    
111
    /**
112
     * Get role name.
113
     *
114
     * @return GeneralName
115
     */
116
    public function roleName(): GeneralName
117
    {
118
        return $this->_roleName;
119
    }
120
    
121
    /**
122
     *
123
     * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
124
     * @return Sequence
125
     */
126
    public function toASN1(): Sequence
127
    {
128
        $elements = array();
129
        if (isset($this->_roleAuthority)) {
130
            $elements[] = new ImplicitlyTaggedType(0,
131
                $this->_roleAuthority->toASN1());
132
        }
133
        $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1());
134
        return new Sequence(...$elements);
135
    }
136
    
137
    /**
138
     *
139
     * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
140
     * @return string
141
     */
142
    public function stringValue(): string
143
    {
144
        return "#" . bin2hex($this->toASN1()->toDER());
145
    }
146
    
147
    /**
148
     *
149
     * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
150
     * @return BinaryMatch
151
     */
152
    public function equalityMatchingRule(): BinaryMatch
153
    {
154
        return new BinaryMatch();
155
    }
156
    
157
    /**
158
     *
159
     * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
160
     * @return string
161
     */
162
    public function rfc2253String(): string
163
    {
164
        return $this->stringValue();
165
    }
166
    
167
    /**
168
     *
169
     * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
170
     * @return string
171
     */
172
    protected function _transcodedString(): string
173
    {
174
        return $this->stringValue();
175
    }
176
}
177