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 ( 584c7d...11b52a )
by Joni
04:10
created

JWKParameter::fromJSONValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace JWX\JWK\Parameter;
4
5
use JWX\Parameter\Parameter;
6
7
8
/**
9
 * Represents a single JWK parameter.
10
 *
11
 * @link https://tools.ietf.org/html/rfc7517#section-4
12
 * @link http://www.iana.org/assignments/jose/jose.xhtml#web-key-parameters
13
 */
14
class JWKParameter extends Parameter
15
{
16
	// registered parameter names
17
	const PARAM_KEY_TYPE = "kty";
18
	const PARAM_PUBLIC_KEY_USE = "use";
19
	const PARAM_KEY_OPERATIONS = "key_ops";
20
	const PARAM_ALGORITHM = "alg";
21
	const PARAM_KEY_ID = "kid";
22
	const PARAM_X509_URL = "x5u";
23
	const PARAM_X509_CERTIFICATE_CHAIN = "x5c";
24
	const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = "x5t";
25
	const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = "x5t#S256";
26
	const PARAM_CURVE = "crv";
27
	const PARAM_X_COORDINATE = "x";
28
	const PARAM_Y_COORDINATE = "y";
29
	const PARAM_ECC_PRIVATE_KEY = "d";
30
	const PARAM_MODULUS = "n";
31
	const PARAM_EXPONENT = "e";
32
	const PARAM_PRIVATE_EXPONENT = "d";
33
	const PARAM_FIRST_PRIME_FACTOR = "p";
34
	const PARAM_SECOND_PRIME_FACTOR = "q";
35
	const PARAM_FIRST_FACTOR_CRT_EXPONENT = "dp";
36
	const PARAM_SECOND_FACTOR_CRT_EXPONENT = "dq";
37
	const PARAM_FIRST_CRT_COEFFICIENT = "qi";
38
	const PARAM_OTHER_PRIMES_INFO = "oth";
39
	const PARAM_KEY_VALUE = "k";
40
	
41
	// shorthand aliases for parameter names
42
	const P_KTY = self::PARAM_KEY_TYPE;
43
	const P_USE = self::PARAM_PUBLIC_KEY_USE;
44
	const P_KEY_OPS = self::PARAM_KEY_OPERATIONS;
45
	const P_ALG = self::PARAM_ALGORITHM;
46
	const P_KID = self::PARAM_KEY_ID;
47
	const P_X5U = self::PARAM_X509_URL;
48
	const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN;
49
	const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT;
50
	const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT;
51
	const P_CRV = self::PARAM_CURVE;
52
	const P_X = self::PARAM_X_COORDINATE;
53
	const P_Y = self::PARAM_Y_COORDINATE;
54
	const P_ECC_D = self::PARAM_ECC_PRIVATE_KEY;
55
	const P_N = self::PARAM_MODULUS;
56
	const P_E = self::PARAM_EXPONENT;
57
	const P_RSA_D = self::PARAM_PRIVATE_EXPONENT;
58
	const P_P = self::PARAM_FIRST_PRIME_FACTOR;
59
	const P_Q = self::PARAM_SECOND_PRIME_FACTOR;
60
	const P_DP = self::PARAM_FIRST_FACTOR_CRT_EXPONENT;
61
	const P_DQ = self::PARAM_SECOND_FACTOR_CRT_EXPONENT;
62
	const P_QI = self::PARAM_FIRST_CRT_COEFFICIENT;
63
	const P_OTH = self::PARAM_OTHER_PRIMES_INFO;
64
	const P_K = self::PARAM_KEY_VALUE;
65
	
66
	/**
67
	 * Mapping from registered JWK parameter name to class name.
68
	 *
69
	 * Note that ECC private key and RSA private key cannot be mapped since
70
	 * they share the same parameter name 'd'.
71
	 *
72
	 * @internal
73
	 *
74
	 * @var array
75
	 */
76
	const MAP_NAME_TO_CLASS = array(
77
		/* @formatter:off */
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_CRV => CurveParameter::class,
84
		self::P_X => XCoordinateParameter::class,
85
		self::P_Y => YCoordinateParameter::class,
86
		self::P_N => ModulusParameter::class,
87
		self::P_E => ExponentParameter::class,
88
		self::P_P => FirstPrimeFactorParameter::class,
89
		self::P_Q => SecondPrimeFactorParameter::class,
90
		self::P_DP => FirstFactorCRTExponentParameter::class,
91
		self::P_DQ => SecondFactorCRTExponentParameter::class,
92
		self::P_QI => FirstCRTCoefficientParameter::class,
93
		self::P_OTH => OtherPrimesInfoParameter::class,
94
		self::P_K => KeyValueParameter::class
95
		/* @formatter:on */
96
	);
97
	
98
	/**
99
	 * Constructor.
100
	 *
101
	 * @param string $name Parameter name
102
	 * @param mixed $value Parameter value
103
	 */
104 124
	public function __construct($name, $value) {
105 124
		$this->_name = $name;
106 124
		$this->_value = $value;
107 124
	}
108
	
109
	/**
110
	 * Initialize from a name and a value.
111
	 *
112
	 * Returns a parameter specific object if one is implemented.
113
	 *
114
	 * @param string $name Parameter name
115
	 * @param mixed $value Parameter value
116
	 * @return self
117
	 */
118 32 View Code Duplication
	public static function fromNameAndValue($name, $value) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119 32
		if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) {
120 30
			$cls = self::MAP_NAME_TO_CLASS[$name];
121 30
			return $cls::fromJSONValue($value);
122
		}
123 12
		return new self($name, $value);
124
	}
125
	
126
	/**
127
	 * Initialize a concrete JWK parameter instance from a JSON value.
128
	 *
129
	 * @param mixed $value
130
	 * @return self
131
	 */
132 30
	public static function fromJSONValue($value) {
133 30
		return new static($value);
0 ignored issues
show
Bug introduced by
The call to JWKParameter::__construct() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
134
	}
135
}
136