From 95114dcc1e08b681efae260cb65652891b52c345 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 18 Jun 2020 11:50:43 +0100 Subject: [PATCH] EncryptionContext: fixed a phpstan level 7 error (openssl_digest() might return false for god knows what reason) --- src/network/mcpe/encryption/EncryptionContext.php | 7 ++++++- tests/phpstan/configs/l7-baseline.neon | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/network/mcpe/encryption/EncryptionContext.php b/src/network/mcpe/encryption/EncryptionContext.php index b6cd47107..8abae1919 100644 --- a/src/network/mcpe/encryption/EncryptionContext.php +++ b/src/network/mcpe/encryption/EncryptionContext.php @@ -27,6 +27,7 @@ use Crypto\Cipher; use pocketmine\utils\Binary; use function bin2hex; use function openssl_digest; +use function openssl_error_string; use function strlen; use function substr; @@ -86,6 +87,10 @@ class EncryptionContext{ } private function calculateChecksum(int $counter, string $payload) : string{ - return substr(openssl_digest(Binary::writeLLong($counter) . $payload . $this->key, self::CHECKSUM_ALGO, true), 0, 8); + $hash = openssl_digest(Binary::writeLLong($counter) . $payload . $this->key, self::CHECKSUM_ALGO, true); + if($hash === false){ + throw new \RuntimeException("Encryption error: " . openssl_error_string()); + } + return substr($hash, 0, 8); } } diff --git a/tests/phpstan/configs/l7-baseline.neon b/tests/phpstan/configs/l7-baseline.neon index ec3ff969a..e09daf79b 100644 --- a/tests/phpstan/configs/l7-baseline.neon +++ b/tests/phpstan/configs/l7-baseline.neon @@ -645,11 +645,6 @@ parameters: count: 1 path: ../../../src/network/mcpe/encryption/EncryptionUtils.php - - - message: "#^Parameter \\#1 \\$str of function substr expects string, string\\|false given\\.$#" - count: 1 - path: ../../../src/network/mcpe/encryption/NetworkCipher.php - - message: "#^Parameter \\#1 \\$v of method pocketmine\\\\utils\\\\BinaryStream\\:\\:putBool\\(\\) expects bool, bool\\|float\\|int given\\.$#" count: 1