cryptal  latest
Cryptography Abstraction Layer
Hash.php
1 <?php
2 
4 
7 
8 class Hash extends AbstractHash
9 {
10  private $func;
11  private $data;
12 
13  public function __construct(HashEnum $algorithm)
14  {
15  $supported = array(
16  'md5' => HashEnum::HASH_MD5(),
17  'sha1' => HashEnum::HASH_SHA1(),
18  );
19 
20  $func = array_search($algorithm, $supported);
21  if (false === $func) {
22  throw new \InvalidArgumentException('Unsupported algorithm');
23  }
24 
25  $this->func = $func;
26  $this->data = '';
27  }
28 
29  protected function internalUpdate($data)
30  {
31  $this->data .= $data;
32  }
33 
34  protected function internalFinalize()
35  {
36  return call_user_func($this->func, $this->data, true);
37  }
38 }
__construct(HashEnum $algorithm)
Definition: Hash.php:13