[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/webauthn-lib/src/ -> PublicKeyCredentialParameters.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;
  15  
  16  use Assert\Assertion;
  17  use JsonSerializable;
  18  
  19  class PublicKeyCredentialParameters implements JsonSerializable
  20  {
  21      /**
  22       * @var string
  23       */
  24      private $type;
  25  
  26      /**
  27       * @var int
  28       */
  29      private $alg;
  30  
  31      public function __construct(string $type, int $alg)
  32      {
  33          $this->type = $type;
  34          $this->alg = $alg;
  35      }
  36  
  37      public function getType(): string
  38      {
  39          return $this->type;
  40      }
  41  
  42      public function getAlg(): int
  43      {
  44          return $this->alg;
  45      }
  46  
  47      public static function createFromString(string $data): self
  48      {
  49          $data = json_decode($data, true);
  50          Assertion::eq(JSON_ERROR_NONE, json_last_error(), 'Invalid data');
  51          Assertion::isArray($data, 'Invalid data');
  52  
  53          return self::createFromArray($data);
  54      }
  55  
  56      public static function createFromArray(array $json): self
  57      {
  58          Assertion::keyExists($json, 'type', 'Invalid input. "type" is missing.');
  59          Assertion::string($json['type'], 'Invalid input. "type" is not a string.');
  60          Assertion::keyExists($json, 'alg', 'Invalid input. "alg" is missing.');
  61          Assertion::integer($json['alg'], 'Invalid input. "alg" is not an integer.');
  62  
  63          return new self(
  64              $json['type'],
  65              $json['alg']
  66          );
  67      }
  68  
  69      public function jsonSerialize(): array
  70      {
  71          return [
  72              'type' => $this->type,
  73              'alg' => $this->alg,
  74          ];
  75      }
  76  }


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