Skip to content

Commit

Permalink
fixed hmac verify
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Trofimov authored and lcobucci committed Jun 11, 2015
1 parent 1e709f2 commit 91df685
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Signer/Hmac.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function createHash($payload, $key)
*/
public function verify($expected, $payload, $key)
{
if (!is_string($expected)) {
return false;
}

$callback = function_exists('hash_equals') ? 'hash_equals' : [$this, 'hashEquals'];

return call_user_func($callback, $expected, $this->createHash($payload, $key));
Expand Down
10 changes: 10 additions & 0 deletions test/Signer/HmacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function verifyShouldReturnFalseWhenExpectedHashWasNotCreatedWithSameInfo
$this->assertFalse($this->signer->verify($expected, 'test', '1234'));
}

/**
* @test
*
* @covers Lcobucci\JWT\Signer\Hmac::verify
*/
public function verifyShouldReturnFalseWhenExpectedHashIsNotString()
{
$this->assertFalse($this->signer->verify(false, 'test', '1234'));
}

/**
* @test
*
Expand Down

0 comments on commit 91df685

Please sign in to comment.