@@ -79,9 +79,9 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
79
79
throw new InvalidArgumentException ('Invalid key parameter "crv" ' );
80
80
}
81
81
switch ($ crv ) {
82
- case 'P-256 ' :
83
- case 'P-384 ' :
84
- case 'P-521 ' :
82
+ case 'P-256 ' :
83
+ case 'P-384 ' :
84
+ case 'P-521 ' :
85
85
$ curve = $ this ->getCurve ($ crv );
86
86
if (function_exists ('openssl_pkey_derive ' )) {
87
87
try {
@@ -120,7 +120,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
120
120
121
121
return $ this ->convertDecToBin (EcDH::computeSharedKey ($ curve , $ pub_key , $ priv_key ));
122
122
123
- case 'X25519 ' :
123
+ case 'X25519 ' :
124
124
$ x = $ public_key ->get ('x ' );
125
125
if (! is_string ($ x )) {
126
126
throw new InvalidArgumentException ('Invalid key parameter "x" ' );
@@ -134,7 +134,7 @@ protected function calculateAgreementKey(JWK $private_key, JWK $public_key): str
134
134
135
135
return sodium_crypto_scalarmult ($ sKey , $ recipientPublickey );
136
136
137
- default :
137
+ default :
138
138
throw new InvalidArgumentException (sprintf ('The curve "%s" is not supported ' , $ crv ));
139
139
}
140
140
}
@@ -156,20 +156,20 @@ protected function getKeysFromPublicKey(
156
156
throw new InvalidArgumentException ('Invalid key parameter "crv" ' );
157
157
}
158
158
switch ($ crv ) {
159
- case 'P-256 ' :
160
- case 'P-384 ' :
161
- case 'P-521 ' :
159
+ case 'P-256 ' :
160
+ case 'P-384 ' :
161
+ case 'P-521 ' :
162
162
$ private_key = $ senderKey ?? ECKey::createECKey ($ crv );
163
163
164
164
break ;
165
165
166
- case 'X25519 ' :
166
+ case 'X25519 ' :
167
167
$ this ->checkSodiumExtensionIsAvailable ();
168
168
$ private_key = $ senderKey ?? $ this ->createOKPKey ('X25519 ' );
169
169
170
170
break ;
171
171
172
- default :
172
+ default :
173
173
throw new InvalidArgumentException (sprintf ('The curve "%s" is not supported ' , $ crv ));
174
174
}
175
175
$ epk = $ private_key ->toPublic ()
@@ -228,19 +228,19 @@ private function checkKey(JWK $key, bool $is_private): void
228
228
throw new InvalidArgumentException ('Invalid key parameter "crv" ' );
229
229
}
230
230
switch ($ crv ) {
231
- case 'P-256 ' :
232
- case 'P-384 ' :
233
- case 'P-521 ' :
231
+ case 'P-256 ' :
232
+ case 'P-384 ' :
233
+ case 'P-521 ' :
234
234
if (! $ key ->has ('y ' )) {
235
235
throw new InvalidArgumentException ('The key parameter "y" is missing. ' );
236
236
}
237
237
238
238
break ;
239
239
240
- case 'X25519 ' :
240
+ case 'X25519 ' :
241
241
break ;
242
242
243
- default :
243
+ default :
244
244
throw new InvalidArgumentException (sprintf ('The curve "%s" is not supported ' , $ crv ));
245
245
}
246
246
if ($ is_private === true && ! $ key ->has ('d ' )) {
@@ -295,14 +295,14 @@ private function createOKPKey(string $curve): JWK
295
295
$ this ->checkSodiumExtensionIsAvailable ();
296
296
297
297
switch ($ curve ) {
298
- case 'X25519 ' :
298
+ case 'X25519 ' :
299
299
$ keyPair = sodium_crypto_box_keypair ();
300
300
$ d = sodium_crypto_box_secretkey ($ keyPair );
301
301
$ x = sodium_crypto_box_publickey ($ keyPair );
302
302
303
303
break ;
304
304
305
- case 'Ed25519 ' :
305
+ case 'Ed25519 ' :
306
306
$ keyPair = sodium_crypto_sign_keypair ();
307
307
$ secret = sodium_crypto_sign_secretkey ($ keyPair );
308
308
$ secretLength = mb_strlen ($ secret , '8bit ' );
@@ -311,7 +311,7 @@ private function createOKPKey(string $curve): JWK
311
311
312
312
break ;
313
313
314
- default :
314
+ default :
315
315
throw new InvalidArgumentException (sprintf ('Unsupported "%s" curve ' , $ curve ));
316
316
}
317
317
0 commit comments