[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/lcobucci/jwt/src/Signer/ -> BaseSigner.php (source)

   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  
   8  namespace Lcobucci\JWT\Signer;
   9  
  10  use Lcobucci\JWT\Signature;
  11  use Lcobucci\JWT\Signer;
  12  use function trigger_error;
  13  use const E_USER_DEPRECATED;
  14  
  15  /**
  16   * Base class for signers
  17   *
  18   * @deprecated This class will be removed on v4
  19   *
  20   * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
  21   * @since 0.1.0
  22   */
  23  abstract class BaseSigner implements Signer
  24  {
  25      /**
  26       * {@inheritdoc}
  27       */
  28      public function modifyHeader(array &$headers)
  29      {
  30          $headers['alg'] = $this->getAlgorithmId();
  31      }
  32  
  33      /**
  34       * {@inheritdoc}
  35       */
  36      public function sign($payload, $key)
  37      {
  38          return new Signature($this->createHash($payload, $this->getKey($key)));
  39      }
  40  
  41      /**
  42       * {@inheritdoc}
  43       */
  44      public function verify($expected, $payload, $key)
  45      {
  46          return $this->doVerify($expected, $payload, $this->getKey($key));
  47      }
  48  
  49      /**
  50       * @param Key|string $key
  51       *
  52       * @return Key
  53       */
  54      private function getKey($key)
  55      {
  56          if (is_string($key)) {
  57              trigger_error('Implicit conversion of keys from strings is deprecated. Please use InMemory or LocalFileReference classes.', E_USER_DEPRECATED);
  58  
  59              $key = new Key($key);
  60          }
  61  
  62          return $key;
  63      }
  64  
  65      /**
  66       * Creates a hash with the given data
  67       *
  68       * @internal
  69       *
  70       * @param string $payload
  71       * @param Key $key
  72       *
  73       * @return string
  74       */
  75      abstract public function createHash($payload, Key $key);
  76  
  77      /**
  78       * Performs the signature verification
  79       *
  80       * @internal
  81       *
  82       * @param string $expected
  83       * @param string $payload
  84       * @param Key $key
  85       *
  86       * @return boolean
  87       */
  88      abstract public function doVerify($expected, $payload, Key $key);
  89  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer