This repository has been archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Roave/sha-encoder
SHA encoder
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\Signature\Encoder; | ||
|
||
final class Sha1SumEncoder implements EncoderInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function encode(string $codeWithoutSignature): string | ||
{ | ||
return sha1($codeWithoutSignature); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function verify(string $codeWithoutSignature, string $signature): bool | ||
{ | ||
return hash_equals($this->encode($codeWithoutSignature), $signature); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\SignatureTest\Encoder; | ||
|
||
use Roave\Signature\Encoder\Sha1SumEncoder; | ||
|
||
/** | ||
* @covers \Roave\Signature\Encoder\Sha1SumEncoder | ||
*/ | ||
final class Sha1SumEncoderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testEncode() | ||
{ | ||
$value = uniqid('values', true); | ||
self::assertSame(sha1($value), (new Sha1SumEncoder())->encode($value)); | ||
} | ||
|
||
public function testVerify() | ||
{ | ||
$value = uniqid('values', true); | ||
self::assertTrue((new Sha1SumEncoder())->verify($value, sha1($value))); | ||
} | ||
} |