EncryptionContext: fixed a phpstan level 7 error (openssl_digest() might return false for god knows what reason)

This commit is contained in:
Dylan K. Taylor 2020-06-18 11:50:43 +01:00
parent edc3156bea
commit 95114dcc1e
2 changed files with 6 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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