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.
Completed
Push — master ( 59f4b4...e271c1 )
by Joni
03:51
created

JWKParameter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 77
dl 0
loc 128
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNameAndValue() 0 7 2
A __construct() 0 4 1
A fromJSONValue() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWK\Parameter;
6
7
use Sop\JWX\Parameter\Parameter;
8
9
/**
10
 * Represents a single JWK parameter.
11
 *
12
 * @see https://tools.ietf.org/html/rfc7517#section-4
13
 * @see http://www.iana.org/assignments/jose/jose.xhtml#web-key-parameters
14
 */
15
class JWKParameter extends Parameter
16
{
17
    // registered parameter names
18
    const PARAM_KEY_TYPE = 'kty';
19
    const PARAM_PUBLIC_KEY_USE = 'use';
20
    const PARAM_KEY_OPERATIONS = 'key_ops';
21
    const PARAM_ALGORITHM = 'alg';
22
    const PARAM_KEY_ID = 'kid';
23
    const PARAM_X509_URL = 'x5u';
24
    const PARAM_X509_CERTIFICATE_CHAIN = 'x5c';
25
    const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = 'x5t';
26
    const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = 'x5t#S256';
27
    const PARAM_CURVE = 'crv';
28
    const PARAM_X_COORDINATE = 'x';
29
    const PARAM_Y_COORDINATE = 'y';
30
    const PARAM_ECC_PRIVATE_KEY = 'd';
31
    const PARAM_MODULUS = 'n';
32
    const PARAM_EXPONENT = 'e';
33
    const PARAM_PRIVATE_EXPONENT = 'd';
34
    const PARAM_FIRST_PRIME_FACTOR = 'p';
35
    const PARAM_SECOND_PRIME_FACTOR = 'q';
36
    const PARAM_FIRST_FACTOR_CRT_EXPONENT = 'dp';
37
    const PARAM_SECOND_FACTOR_CRT_EXPONENT = 'dq';
38
    const PARAM_FIRST_CRT_COEFFICIENT = 'qi';
39
    const PARAM_OTHER_PRIMES_INFO = 'oth';
40
    const PARAM_KEY_VALUE = 'k';
41
42
    // shorthand aliases for parameter names
43
    const P_KTY = self::PARAM_KEY_TYPE;
44
    const P_USE = self::PARAM_PUBLIC_KEY_USE;
45
    const P_KEY_OPS = self::PARAM_KEY_OPERATIONS;
46
    const P_ALG = self::PARAM_ALGORITHM;
47
    const P_KID = self::PARAM_KEY_ID;
48
    const P_X5U = self::PARAM_X509_URL;
49
    const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN;
50
    const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT;
51
    const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT;
52
    const P_CRV = self::PARAM_CURVE;
53
    const P_X = self::PARAM_X_COORDINATE;
54
    const P_Y = self::PARAM_Y_COORDINATE;
55
    const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY;
56
    const P_N = self::PARAM_MODULUS;
57
    const P_E = self::PARAM_EXPONENT;
58
    const P_RSA_D = self::PARAM_PRIVATE_EXPONENT;
59
    const P_P = self::PARAM_FIRST_PRIME_FACTOR;
60
    const P_Q = self::PARAM_SECOND_PRIME_FACTOR;
61
    const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT;
62
    const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT;
63
    const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT;
64
    const P_OTH = self::PARAM_OTHER_PRIMES_INFO;
65
    const P_K = self::PARAM_KEY_VALUE;
66
67
    /**
68
     * Mapping from registered JWK parameter name to class name.
69
     *
70
     * Note that ECC private key and RSA private key cannot be mapped since
71
     * they share the same parameter name 'd'.
72
     *
73
     * @internal
74
     *
75
     * @var array
76
     */
77
    const MAP_NAME_TO_CLASS = [
78
        self::P_KTY => KeyTypeParameter::class,
79
        self::P_USE => PublicKeyUseParameter::class,
80
        self::P_KEY_OPS => KeyOperationsParameter::class,
81
        self::P_ALG => AlgorithmParameter::class,
82
        self::P_KID => KeyIDParameter::class,
83
        self::P_X5U => X509URLParameter::class,
84
        self::P_X5C => X509CertificateChainParameter::class,
85
        self::P_X5T => X509CertificateSHA1ThumbprintParameter::class,
86
        self::P_X5TS256 => X509CertificateSHA256ThumbprintParameter::class,
87
        self::P_CRV => CurveParameter::class,
88
        self::P_X => XCoordinateParameter::class,
89
        self::P_Y => YCoordinateParameter::class,
90
        self::P_N => ModulusParameter::class,
91
        self::P_E => ExponentParameter::class,
92
        self::P_P => FirstPrimeFactorParameter::class,
93
        self::P_Q => SecondPrimeFactorParameter::class,
94
        self::P_DP => FirstFactorCRTExponentParameter::class,
95
        self::P_DQ => SecondFactorCRTExponentParameter::class,
96
        self::P_QI => FirstCRTCoefficientParameter::class,
97
        self::P_OTH => OtherPrimesInfoParameter::class,
98
        self::P_K => KeyValueParameter::class,
99
    ];
100
101
    /**
102
     * Constructor.
103
     *
104
     * @param string $name  Parameter name
105
     * @param mixed  $value Parameter value
106
     */
107 150
    public function __construct(string $name, $value)
108
    {
109 150
        $this->_name = $name;
110 150
        $this->_value = $value;
111 150
    }
112
113
    /**
114
     * Initialize from a name and a value.
115
     *
116
     * Returns a parameter specific object if one is implemented.
117
     *
118
     * @param string $name  Parameter name
119
     * @param mixed  $value Parameter value
120
     *
121
     * @return self
122
     */
123 54
    public static function fromNameAndValue(string $name, $value): self
124
    {
125 54
        if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) {
126 52
            $cls = self::MAP_NAME_TO_CLASS[$name];
127 52
            return $cls::fromJSONValue($value);
128
        }
129 12
        return new self($name, $value);
130
    }
131
132
    /**
133
     * Initialize from a JSON value.
134
     *
135
     * @param mixed $value
136
     *
137
     * @return JWKParameter
138
     */
139 1
    public static function fromJSONValue($value): Parameter
140
    {
141 1
        throw new \BadMethodCallException(
142 1
            __FUNCTION__ . ' must be implemented in a derived class.');
143
    }
144
}
145