[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/webauthn-lib/src/TokenBinding/ -> TokenBinding.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  /*
   6   * The MIT License (MIT)
   7   *
   8   * Copyright (c) 2014-2019 Spomky-Labs
   9   *
  10   * This software may be modified and distributed under the terms
  11   * of the MIT license.  See the LICENSE file for details.
  12   */
  13  
  14  namespace Webauthn\TokenBinding;
  15  
  16  use Assert\Assertion;
  17  use Base64Url\Base64Url;
  18  
  19  class TokenBinding
  20  {
  21      public const TOKEN_BINDING_STATUS_PRESENT = 'present';
  22      public const TOKEN_BINDING_STATUS_SUPPORTED = 'supported';
  23      public const TOKEN_BINDING_STATUS_NOT_SUPPORTED = 'not-supported';
  24  
  25      /**
  26       * @var string
  27       */
  28      private $status;
  29  
  30      /**
  31       * @var string|null
  32       */
  33      private $id;
  34  
  35      public function __construct(string $status, ?string $id)
  36      {
  37          Assertion::false(self::TOKEN_BINDING_STATUS_PRESENT === $status && null === $id, 'The member "id" is required when status is "present"');
  38          $this->status = $status;
  39          $this->id = $id;
  40      }
  41  
  42      public static function createFormArray(array $json): self
  43      {
  44          Assertion::keyExists($json, 'status', 'The member "status" is required');
  45          $status = $json['status'];
  46          Assertion::inArray(
  47              $status,
  48              self::getSupportedStatus(),
  49              sprintf('The member "status" is invalid. Supported values are: %s', implode(', ', self::getSupportedStatus()))
  50          );
  51          $id = \array_key_exists('id', $json) ? Base64Url::decode($json['id']) : null;
  52  
  53          return new self($status, $id);
  54      }
  55  
  56      public function getStatus(): string
  57      {
  58          return $this->status;
  59      }
  60  
  61      public function getId(): ?string
  62      {
  63          return $this->id;
  64      }
  65  
  66      /**
  67       * @return string[]
  68       */
  69      private static function getSupportedStatus(): array
  70      {
  71          return [
  72              self::TOKEN_BINDING_STATUS_PRESENT,
  73              self::TOKEN_BINDING_STATUS_SUPPORTED,
  74              self::TOKEN_BINDING_STATUS_NOT_SUPPORTED,
  75          ];
  76      }
  77  }


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