diff --git a/config/verify.php b/config/verify.php index a759bbd..06add80 100644 --- a/config/verify.php +++ b/config/verify.php @@ -8,9 +8,9 @@ return [ 'validation' => [ - ValidateHash::class => '685b1e0749627c537af1bcdbb0ffa3683c2fbb5a', - ValidateSignature::class => '9518e1d258259cc0c95704a924b5ecdce8161bb2', - Verify::class => '2e5ddaf589b6f9ea30ffd4b3a30e0a48a3c7fb2d', + ValidateHash::class => 'c34da4a4523e54f303c23cd22eaf252f74ed7965', + ValidateSignature::class => 'a3d4081247b4f56c8aeb7c6b192415700e27acc0', + Verify::class => 'cda79b50522e9189aa928a5f471ebc20a049db76', VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed', VerifyServiceProvider::class => '927a8f3c811fc82cb8a0ac2667c06e7d292c3633', ], diff --git a/src/Validators/ValidateHash.php b/src/Validators/ValidateHash.php index c04ffda..1662b5d 100644 --- a/src/Validators/ValidateHash.php +++ b/src/Validators/ValidateHash.php @@ -7,7 +7,7 @@ use LycheeVerify\Contract\Validator; /** - * This is the valitaor for supporters. + * This is the validator for supporters. */ class ValidateHash implements Validator { diff --git a/src/Validators/ValidateSignature.php b/src/Validators/ValidateSignature.php index f565efb..cd9e60c 100644 --- a/src/Validators/ValidateSignature.php +++ b/src/Validators/ValidateSignature.php @@ -11,7 +11,7 @@ use function Safe\openssl_verify; /** - * This is the check for the premium users. + * This is the validator for the premium users. */ class ValidateSignature implements Validator { diff --git a/src/Verify.php b/src/Verify.php index d62b8a3..295285c 100755 --- a/src/Verify.php +++ b/src/Verify.php @@ -8,7 +8,7 @@ use LycheeVerify\Validators\ValidateHash; use LycheeVerify\Validators\ValidateSignature; use function Safe\json_encode; -use function Safe\sha1_file; +use function Safe\preg_replace; class Verify { @@ -123,7 +123,14 @@ public function validate(): bool foreach ($checks as $class => $value) { $file = (new \ReflectionClass($class))->getFileName(); - if ($file === false || !file_exists($file) || sha1_file($file) !== $value) { + if ($file === false || !file_exists($file)) { + return false; + } + // this necessary because stupid line endings in Windows. + /** @var string $content */ + $content = file_get_contents($file); // @phpstan-ignore-line + $content = preg_replace('~\R~u', "\n", $content); + if (sha1($content) !== $value) { return false; } } diff --git a/tests/Verify/VerifyTest.php b/tests/Verify/VerifyTest.php index 2f9003a..8b378a0 100644 --- a/tests/Verify/VerifyTest.php +++ b/tests/Verify/VerifyTest.php @@ -7,7 +7,7 @@ use LycheeVerify\Tests\Constants; use LycheeVerify\Tests\TestCase; use LycheeVerify\Verify; -use function Safe\sha1_file; +use function Safe\preg_replace; class VerifyTest extends TestCase { @@ -65,8 +65,12 @@ public function testVerifyValidate(): void if ($file === false || !file_exists($file)) { self::fail(sprintf('Validation failed for %s: file not found', $class)); } - if (sha1_file($file) !== $value) { - self::fail(sprintf("Validation failed for %s: expected '%s'", $class, sha1_file($file))); + // this necessary because stupid line endings in Windows. + /** @var string $content */ + $content = file_get_contents($file); // @phpstan-ignore-line + $content = preg_replace('~\R~u', "\n", $content); + if (sha1($content) !== $value) { + self::fail(sprintf("Validation failed for %s: expected '%s'", $class, sha1($content))); } }