Skip to content

Commit

Permalink
Add PHP 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
renekorss committed Feb 3, 2023
1 parent 2870d00 commit 2751827
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Protocol/IPizza.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function __construct(
$this->requestUrl = $requestUrl;

// Detect which service to use
if (strlen($sellerName) > 0 && strlen($sellerAccount) > 0) {
if (is_string($sellerName) && strlen($sellerName) > 0 && is_string($sellerAccount) && strlen($sellerAccount) > 0) {
$this->serviceId = Services::PAYMENT_REQUEST_1011;
return;
}
Expand Down Expand Up @@ -443,7 +443,11 @@ public function getSignature(array $data, string $encoding = 'UTF-8') : string
}

openssl_sign($mac, $signature, $privateKey, $this->algorithm);
openssl_free_key($privateKey);

// Only needed if < PHP 8
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
openssl_free_key($privateKey);
}

$result = base64_encode($signature);

Expand Down Expand Up @@ -512,7 +516,11 @@ protected function validateSignature(array $response, string $encoding = 'UTF-8'
}

$this->result = openssl_verify($data, base64_decode($response[static::FIELD_MAC]), $publicKey, $this->algorithm);
openssl_free_key($publicKey);

// Only needed if < PHP 8
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
openssl_free_key($publicKey);
}

return $this->result === 1;
}
Expand Down

0 comments on commit 2751827

Please sign in to comment.