Skip to content

Commit 7362d91

Browse files
authored
fix: buffer (#5)
1 parent 3ee684c commit 7362d91

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Secure.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ private function _crypt($encrypt, $cipherAlgorithm, $cipherChaining, $key, $iv,
441441
private function _hash($algorithm, ...$buffers)
442442
{
443443
$algorithm = strtolower($algorithm);
444-
445-
$buffers = [...$buffers];
444+
$buffers = array_merge([], ...$buffers);
446445

447446
if (! in_array($algorithm, hash_algos(), true)) {
448447
throw new Exception("Hash algorithm '{$algorithm}' not supported!"); // @codeCoverageIgnore
@@ -506,10 +505,11 @@ private function _convertPasswordToKey($password, $hashAlgorithm, $saltValue, $s
506505
$key = $this->_hash($hashAlgorithm, $key, $blockKey);
507506

508507
// Truncate or pad as needed to get to length of keyBits
509-
$keyBytes = $keyBits / 8;
510-
if (count($key) < $keyBytes) {
508+
$keyBytes = $keyBits / 8;
509+
$keyCounter = count($key);
510+
if ($keyCounter < $keyBytes) {
511511
$key = array_pad($key, $keyBytes, 0x36);
512-
} elseif (count($key) > $keyBytes) {
512+
} elseif ($keyCounter > $keyBytes) {
513513
$key = array_slice($key, 0, $keyBytes);
514514
}
515515

0 commit comments

Comments
 (0)