Skip to content

Commit 6f726de

Browse files
authored
refactor: _hash method to handle unsupported algorithms
1 parent d5e092b commit 6f726de

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/Secure.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,12 @@ private function _crypt($encrypt, $cipherAlgorithm, $cipherChaining, $key, $iv,
468468
*/
469469
private function _hash($algorithm, ...$buffers)
470470
{
471-
$buffers = [...[], ...$buffers];
472-
473-
if (! in_array($algorithm, hash_algos(), true)) {
474-
throw new Exception("Hash algorithm '{$algorithm}' not supported!"); // @codeCoverageIgnore
471+
try {
472+
$ctx = hash_init($algorithm);
473+
} catch (\ValueError $e) {
474+
throw new \Exception("Hash algorithm '{$algorithm}' not supported!");
475475
}
476476

477-
$ctx = hash_init($algorithm);
478-
479477
hash_update($ctx, pack('C*', ...$buffers));
480478

481479
return (array) unpack('C*', hash_final($ctx, true));

0 commit comments

Comments
 (0)