Skip to content

Commit

Permalink
Add Signature::create() method.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 17, 2020
1 parent 9f0e3a1 commit e7f5aa0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@ public function __construct(string $key, array $attributes)
}

/**
* Verify signature.
* Create signature.
*/
final public function verify(array $data, string $hash): bool
final public function create(array $data): string
{
$keys = [];

foreach ($this->attributes as $attribute) {
\array_push($keys, $attribute.($data[$attribute] ?? ''));
}

$compared = \hash_hmac('sha256', \implode('|', $keys), $this->key);
return \hash_hmac('sha256', \implode('|', $keys), $this->key);
}

return \hash_equals($compared, $hash);
/**
* Verify signature.
*/
final public function verify(array $data, string $hash): bool
{
return \hash_equals($this->create($data), $hash);
}
}

0 comments on commit e7f5aa0

Please sign in to comment.