Skip to content

Commit d5a40b7

Browse files
committed
fix phpstan errors
1 parent ea7dda7 commit d5a40b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/JWT.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ public static function sign(
255255
// The last non-empty line is used as the key.
256256
$lines = array_filter(explode("\n", $key));
257257
$key = base64_decode((string) end($lines));
258+
if (strlen($key) === 0) {
259+
throw new DomainException('Key cannot be empty string');
260+
}
258261
return sodium_crypto_sign_detached($msg, $key);
259262
} catch (Exception $e) {
260263
throw new DomainException($e->getMessage(), 0, $e);
@@ -312,6 +315,12 @@ private static function verify(
312315
// The last non-empty line is used as the key.
313316
$lines = array_filter(explode("\n", $keyMaterial));
314317
$key = base64_decode((string) end($lines));
318+
if (strlen($key) === 0) {
319+
throw new DomainException('Key cannot be empty string');
320+
}
321+
if (strlen($signature) === 0) {
322+
throw new DomainException('Signature cannot be empty string');
323+
}
315324
return sodium_crypto_sign_verify_detached($signature, $msg, $key);
316325
} catch (Exception $e) {
317326
throw new DomainException($e->getMessage(), 0, $e);

0 commit comments

Comments
 (0)