Signature.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS
  4. *
  5. * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
  6. */
  7. namespace Lcobucci\JWT;
  8. use Lcobucci\JWT\Signer\Key;
  9. /**
  10. * This class represents a token signature
  11. *
  12. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  13. * @since 0.1.0
  14. */
  15. class Signature
  16. {
  17. /**
  18. * The resultant hash
  19. *
  20. * @var string
  21. */
  22. protected $hash;
  23. /**
  24. * Initializes the object
  25. *
  26. * @param string $hash
  27. */
  28. public function __construct($hash)
  29. {
  30. $this->hash = $hash;
  31. }
  32. /**
  33. * Verifies if the current hash matches with with the result of the creation of
  34. * a new signature with given data
  35. *
  36. * @param Signer $signer
  37. * @param string $payload
  38. * @param Key|string $key
  39. *
  40. * @return boolean
  41. */
  42. public function verify(Signer $signer, $payload, $key)
  43. {
  44. return $signer->verify($this->hash, $payload, $key);
  45. }
  46. /**
  47. * Returns the current hash as a string representation of the signature
  48. *
  49. * @return string
  50. */
  51. public function __toString()
  52. {
  53. return $this->hash;
  54. }
  55. }