Skip to content

Commit

Permalink
refactor: remove repetitive count in foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevsr committed Aug 21, 2024
1 parent cf9b1ce commit 9f996b3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Secure.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private function _hash($algorithm, ...$buffers)
{
$algorithm = strtolower($algorithm);

$buffers = array_merge([], ...$buffers);
$buffers = [...$buffers];

if (! in_array($algorithm, hash_algos(), true)) {
throw new Exception("Hash algorithm '{$algorithm}' not supported!");
Expand Down Expand Up @@ -544,11 +544,12 @@ private function _cryptPackage(
$inputCount = 0;

foreach ($in as $i => $inputChunk) {
$lengthInputChunk = count($inputChunk);
// Grab the next chunk
$inputCount += count($inputChunk);
$remainder = count($inputChunk) % $blockSize;
$inputCount += $lengthInputChunk;
$remainder = $lengthInputChunk % $blockSize;
if ($remainder !== 0) {
$inputChunk = array_pad($inputChunk, count($inputChunk) + (16 - $remainder), 0);
$inputChunk = array_pad($inputChunk, $lengthInputChunk + (16 - $remainder), 0);
}
// Create the initialization vector
$iv = $this->_createIV($hashAlgorithm, $saltValue, $blockSize, $i);
Expand Down

0 comments on commit 9f996b3

Please sign in to comment.