Example #1
0
 /**
  * @param Hash $expectedHash
  * @param File $file
  *
  * @return bool
  * @throws InvalidHashException
  */
 public function verify(Hash $expectedHash, File $file)
 {
     $hashClass = get_class($expectedHash);
     switch ($hashClass) {
         case Sha1Hash::class:
             $actual = $file->getSha1Hash();
             break;
         case Sha256Hash::class:
             $actual = $file->getSha256Hash();
             break;
         default:
             throw new InvalidHashException(sprintf('%s is not supported', $hashClass));
     }
     return $actual->equals($expectedHash);
 }
Example #2
0
 /**
  * @dataProvider sha1HashProvider
  *
  * @param string $content
  * @param string $expectedHash
  */
 public function testGeneratesExpectedSha1Hash($content, $expectedHash)
 {
     $expectedHash = new Sha1Hash($expectedHash);
     $file = new File(new Filename('foo.phar'), $content);
     $this->assertEquals($expectedHash, $file->getSha1Hash());
 }