Signature.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  9. * This class represents a token signature
  10. *
  11. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  12. * @since 0.1.0
  13. */
  14. class Signature
  15. {
  16. /**
  17. * The resultant hash
  18. *
  19. * @var string
  20. */
  21. protected $hash;
  22. /**
  23. * Initializes the object
  24. *
  25. * @param string $hash
  26. */
  27. public function __construct($hash)
  28. {
  29. $this->hash = $hash;
  30. }
  31. /**
  32. * Verifies if the current hash matches with with the result of the creation of
  33. * a new signature with given data
  34. *
  35. * @param Signer $signer
  36. * @param string $payload
  37. * @param string $key
  38. *
  39. * @return boolean
  40. */
  41. public function verify(Signer $signer, $payload, $key)
  42. {
  43. return $signer->verify($this->hash, $payload, $key);
  44. }
  45. /**
  46. * Returns the current hash as a string representation of the signature
  47. *
  48. * @return string
  49. */
  50. public function __toString()
  51. {
  52. return $this->hash;
  53. }
  54. }