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
Push — master ( 405cf3...79c9ba )
by Joni
04:48
created

GeneralName::toASN1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\GeneralName;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\TaggedType;
9
use Sop\ASN1\Type\UnspecifiedType;
10
11
/**
12
 * Implements *GeneralName* CHOICE with implicit tagging.
13
 *
14
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.6
15
 */
16
abstract class GeneralName
17
{
18
    // GeneralName CHOICE tags
19
    const TAG_OTHER_NAME = 0;
20
    const TAG_RFC822_NAME = 1;
21
    const TAG_DNS_NAME = 2;
22
    const TAG_X400_ADDRESS = 3;
23
    const TAG_DIRECTORY_NAME = 4;
24
    const TAG_EDI_PARTY_NAME = 5;
25
    const TAG_URI = 6;
26
    const TAG_IP_ADDRESS = 7;
27
    const TAG_REGISTERED_ID = 8;
28
29
    /**
30
     * Chosen tag.
31
     *
32
     * @var int
33
     */
34
    protected $_tag;
35
36
    /**
37
     * Get general name as a string.
38
     *
39
     * @return string
40
     */
41
    public function __toString(): string
42
    {
43
        return $this->string();
44
    }
45
46
    /**
47
     * Get string value of the type.
48
     *
49
     * @return string
50
     */
51
    abstract public function string(): string;
52
53
    /**
54
     * Initialize concrete object from the chosen ASN.1 element.
55
     *
56 1
     * @param UnspecifiedType $el
57
     *
58 1
     * @return self
59 1
     */
60
    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
61
    {
62
        throw new \BadMethodCallException(
63
            __FUNCTION__ . ' must be implemented in the derived class.');
64
    }
65
66
    /**
67
     * Initialize from ASN.1.
68
     *
69 67
     * @param TaggedType $el
70
     *
71 67
     * @throws \UnexpectedValueException
72
     *
73 67
     * @return self
74 9
     */
75 9
    public static function fromASN1(TaggedType $el): self
76
    {
77 66
        switch ($el->tag()) {
78 9
            // otherName
79 9
            case self::TAG_OTHER_NAME:
80
                return OtherName::fromChosenASN1(
81 65
                    $el->asImplicit(Element::TYPE_SEQUENCE));
82 13
            // rfc822Name
83 13
            case self::TAG_RFC822_NAME:
84
                return RFC822Name::fromChosenASN1(
85 63
                    $el->asImplicit(Element::TYPE_IA5_STRING));
86 2
            // dNSName
87 2
            case self::TAG_DNS_NAME:
88
                return DNSName::fromChosenASN1(
89 61
                    $el->asImplicit(Element::TYPE_IA5_STRING));
90
            // x400Address
91
            case self::TAG_X400_ADDRESS:
92
                return X400Address::fromChosenASN1(
93 37
                    $el->asImplicit(Element::TYPE_SEQUENCE));
94
            // directoryName
95 43
            case self::TAG_DIRECTORY_NAME:
96 2
                // because Name is a CHOICE, albeit having only one option,
97 2
                // explicit tagging must be used
98
                // (see X.680 07/2002 30.6.c)
99 41
                return DirectoryName::fromChosenASN1($el->asExplicit());
100 34
            // ediPartyName
101 34
            case self::TAG_EDI_PARTY_NAME:
102
                return EDIPartyName::fromChosenASN1(
103 15
                    $el->asImplicit(Element::TYPE_SEQUENCE));
104 13
            // uniformResourceIdentifier
105 13
            case self::TAG_URI:
106
                return UniformResourceIdentifier::fromChosenASN1(
107 10
                    $el->asImplicit(Element::TYPE_IA5_STRING));
108 9
            // iPAddress
109 9
            case self::TAG_IP_ADDRESS:
110
                return IPAddress::fromChosenASN1(
111 1
                    $el->asImplicit(Element::TYPE_OCTET_STRING));
112 1
            // registeredID
113
            case self::TAG_REGISTERED_ID:
114
                return RegisteredID::fromChosenASN1(
115
                    $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
116
        }
117
        throw new \UnexpectedValueException(
118
            'GeneralName type ' . $el->tag() . ' not supported.');
119
    }
120 58
121
    /**
122 58
     * Get type tag.
123
     *
124
     * @return int
125
     */
126
    public function tag(): int
127
    {
128
        return $this->_tag;
129
    }
130 89
131
    /**
132 89
     * Generate ASN.1 element.
133
     *
134
     * @return Element
135
     */
136
    public function toASN1(): Element
137
    {
138
        return $this->_choiceASN1();
139
    }
140
141 3
    /**
142
     * Check whether GeneralName is equal to other.
143 3
     *
144 1
     * @param GeneralName $other GeneralName to compare to
145
     *
146 2
     * @return bool True if names are equal
147 1
     */
148
    public function equals(GeneralName $other): bool
149 1
    {
150
        if ($this->_tag !== $other->_tag) {
151
            return false;
152
        }
153
        if ($this->_choiceASN1()->toDER() !== $other->_choiceASN1()->toDER()) {
154
            return false;
155
        }
156
        return true;
157 8
    }
158
159 8
    /**
160
     * Get ASN.1 value in GeneralName CHOICE context.
161
     *
162
     * @return TaggedType
163
     */
164
    abstract protected function _choiceASN1(): TaggedType;
165
}
166