1 | <?php |
||
14 | class CurveParameter extends JWKParameter |
||
15 | { |
||
16 | use StringParameterValue; |
||
17 | |||
18 | /** |
||
19 | * P-256 Curve. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | const CURVE_P256 = 'P-256'; |
||
24 | |||
25 | /** |
||
26 | * P-384 Curve. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | const CURVE_P384 = 'P-384'; |
||
31 | |||
32 | /** |
||
33 | * P-521 Curve. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | const CURVE_P521 = 'P-521'; |
||
38 | |||
39 | /** |
||
40 | * Mapping from curve OID to curve name. |
||
41 | * |
||
42 | * @internal |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | const MAP_OID_TO_CURVE = [ |
||
47 | '1.2.840.10045.3.1.7' => self::CURVE_P256, |
||
48 | '1.3.132.0.34' => self::CURVE_P384, |
||
49 | '1.3.132.0.35' => self::CURVE_P521, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Mapping from curve name to bit size. |
||
54 | * |
||
55 | * @internal |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | const MAP_CURVE_TO_SIZE = [ |
||
60 | self::CURVE_P256 => 256, |
||
61 | self::CURVE_P384 => 384, |
||
62 | self::CURVE_P521 => 521, |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * Constructor. |
||
67 | * |
||
68 | * @param string $curve Curve name |
||
69 | */ |
||
70 | 17 | public function __construct(string $curve) |
|
71 | { |
||
72 | 17 | parent::__construct(self::PARAM_CURVE, $curve); |
|
1 ignored issue
–
show
|
|||
73 | 17 | } |
|
74 | |||
75 | /** |
||
76 | * Initialize from curve OID. |
||
77 | * |
||
78 | * @param string $oid Object identifier in dotted format |
||
79 | * |
||
80 | * @throws \UnexpectedValueException If the curve is not supported |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | 7 | public static function fromOID(string $oid): self |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * Get key size in bits for the curve. |
||
95 | * |
||
96 | * @throws \UnexpectedValueException |
||
97 | * |
||
98 | * @return int |
||
99 | */ |
||
100 | 11 | public function keySizeBits(): int |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Get the curve OID by curve name. |
||
111 | * |
||
112 | * @param string $name Curve parameter name |
||
113 | * |
||
114 | * @throws \UnexpectedValueException If the curve is not supported |
||
115 | * |
||
116 | * @return string OID in dotted format |
||
117 | */ |
||
118 | 12 | public static function nameToOID(string $name): string |
|
128 | } |
||
129 | } |
||
130 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.