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.

ExtendedKeyUsageExtension   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 50
dl 0
loc 126
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 8 3
A purposes() 0 3 1
A count() 0 3 1
A getIterator() 0 3 1
A _fromDER() 0 7 1
A _valueASN1() 0 7 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\Primitive\ObjectIdentifier;
10
use Sop\ASN1\Type\UnspecifiedType;
11
12
/**
13
 * Implements 'Extended Key Usage' certificate extension.
14
 *
15
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.12
16
 */
17
class ExtendedKeyUsageExtension extends Extension implements \Countable, \IteratorAggregate
18
{
19
    const OID_SERVER_AUTH = '1.3.6.1.5.5.7.3.1';
20
    const OID_CLIENT_AUTH = '1.3.6.1.5.5.7.3.2';
21
    const OID_CODE_SIGNING = '1.3.6.1.5.5.7.3.3';
22
    const OID_EMAIL_PROTECTION = '1.3.6.1.5.5.7.3.4';
23
    const OID_IPSEC_END_SYSTEM = '1.3.6.1.5.5.7.3.5';
24
    const OID_IPSEC_TUNNEL = '1.3.6.1.5.5.7.3.6';
25
    const OID_IPSEC_USER = '1.3.6.1.5.5.7.3.7';
26
    const OID_TIME_STAMPING = '1.3.6.1.5.5.7.3.8';
27
    const OID_OCSP_SIGNING = '1.3.6.1.5.5.7.3.9';
28
    const OID_DVCS = '1.3.6.1.5.5.7.3.10';
29
    const OID_SBGP_CERT_AA_SERVER_AUTH = '1.3.6.1.5.5.7.3.11';
30
    const OID_SCVP_RESPONDER = '1.3.6.1.5.5.7.3.12';
31
    const OID_EAP_OVER_PPP = '1.3.6.1.5.5.7.3.13';
32
    const OID_EAP_OVER_LAN = '1.3.6.1.5.5.7.3.14';
33
    const OID_SCVP_SERVER = '1.3.6.1.5.5.7.3.15';
34
    const OID_SCVP_CLIENT = '1.3.6.1.5.5.7.3.16';
35
    const OID_IPSEC_IKE = '1.3.6.1.5.5.7.3.17';
36
    const OID_CAPWAP_AC = '1.3.6.1.5.5.7.3.18';
37
    const OID_CAPWAP_WTP = '1.3.6.1.5.5.7.3.19';
38
    const OID_SIP_DOMAIN = '1.3.6.1.5.5.7.3.20';
39
    const OID_SECURE_SHELL_CLIENT = '1.3.6.1.5.5.7.3.21';
40
    const OID_SECURE_SHELL_SERVER = '1.3.6.1.5.5.7.3.22';
41
    const OID_SEND_ROUTER = '1.3.6.1.5.5.7.3.23';
42
    const OID_SEND_PROXY = '1.3.6.1.5.5.7.3.24';
43
    const OID_SEND_OWNER = '1.3.6.1.5.5.7.3.25';
44
    const OID_SEND_PROXIED_OWNER = '1.3.6.1.5.5.7.3.26';
45
    const OID_CMC_CA = '1.3.6.1.5.5.7.3.27';
46
    const OID_CMC_RA = '1.3.6.1.5.5.7.3.28';
47
    const OID_CMC_ARCHIVE = '1.3.6.1.5.5.7.3.29';
48
49
    /**
50
     * Purpose OID's.
51
     *
52
     * @var string[]
53
     */
54
    protected $_purposes;
55
56
    /**
57
     * Constructor.
58
     *
59
     * @param bool   $critical
60
     * @param string ...$purposes
61
     */
62 10
    public function __construct(bool $critical, string ...$purposes)
63
    {
64 10
        parent::__construct(self::OID_EXT_KEY_USAGE, $critical);
65 10
        $this->_purposes = $purposes;
66 10
    }
67
68
    /**
69
     * Whether purposes are present.
70
     *
71
     * If multiple purposes are checked, all must be present.
72
     *
73
     * @param string ...$oids
74
     *
75
     * @return bool
76
     */
77 3
    public function has(string ...$oids): bool
78
    {
79 3
        foreach ($oids as $oid) {
80 3
            if (!in_array($oid, $this->_purposes)) {
81 3
                return false;
82
            }
83
        }
84 2
        return true;
85
    }
86
87
    /**
88
     * Get key usage purpose OID's.
89
     *
90
     * @return string[]
91
     */
92 1
    public function purposes(): array
93
    {
94 1
        return $this->_purposes;
95
    }
96
97
    /**
98
     * Get the number of purposes.
99
     *
100
     * @see \Countable::count()
101
     *
102
     * @return int
103
     */
104 1
    public function count(): int
105
    {
106 1
        return count($this->_purposes);
107
    }
108
109
    /**
110
     * Get iterator for usage purposes.
111
     *
112
     * @see \IteratorAggregate::getIterator()
113
     *
114
     * @return \ArrayIterator
115
     */
116 1
    public function getIterator(): \ArrayIterator
117
    {
118 1
        return new \ArrayIterator($this->_purposes);
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 9
    protected static function _fromDER(string $data, bool $critical): Extension
125
    {
126 9
        $purposes = array_map(
127
            function (UnspecifiedType $el) {
128 9
                return $el->asObjectIdentifier()->oid();
129 9
            }, UnspecifiedType::fromDER($data)->asSequence()->elements());
130 9
        return new self($critical, ...$purposes);
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136 15
    protected function _valueASN1(): Element
137
    {
138 15
        $elements = array_map(
139
            function ($oid) {
140 15
                return new ObjectIdentifier($oid);
141 15
            }, $this->_purposes);
142 15
        return new Sequence(...$elements);
143
    }
144
}
145