Skip to content

Commit

Permalink
Code formatting & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaail committed Sep 2, 2023
1 parent f9aad4e commit e23ff3e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/CmiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,19 @@ public function generateHash(): string
$hashval = '';

foreach ($optionskeys as $param) {
// Skip Store Key
if ('storekey' === $param) {
continue;
}

$lowerParam = strtolower($param);

// Skip some params
if (in_array($lowerParam, ['hash', 'encoding'])) {
if (in_array(strtolower($param), ['storekey', 'hash', 'encoding'], strict: true)) {
continue;
}

$paramValue = trim($cmiParams[$param]);
$escapedParamValue = str_replace(['\\', '|'], ['\\\\', '\|'], $paramValue);
$hashval .= $escapedParamValue . '|';
$paramValue = str_replace(['\\', '|'], ['\\\\', '\|'], trim($cmiParams[$param]));
$hashval .= $paramValue . '|';
}

$escapedStoreKey = str_replace(['\\', '|'], ['\\\\', '\|'], $cmiParams['storekey']);
$hashval .= $escapedStoreKey;

$calculatedHashValue = hash('sha512', $hashval);
$storeKeyValue = str_replace(['\\', '|'], ['\\\\', '\|'], $cmiParams['storekey']);
$hashval .= $storeKeyValue;

return base64_encode(pack('H*', $calculatedHashValue));
return base64_encode(pack('H*', hash('sha512', $hashval)));
}

/**
Expand Down

0 comments on commit e23ff3e

Please sign in to comment.