[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/webauthn-lib/src/ -> PublicKeyCredentialDescriptor.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 Base64Url\Base64Url;
  18  use JsonSerializable;
  19  
  20  class PublicKeyCredentialDescriptor implements JsonSerializable
  21  {
  22      public const CREDENTIAL_TYPE_PUBLIC_KEY = 'public-key';
  23  
  24      public const AUTHENTICATOR_TRANSPORT_USB = 'usb';
  25      public const AUTHENTICATOR_TRANSPORT_NFC = 'nfc';
  26      public const AUTHENTICATOR_TRANSPORT_BLE = 'ble';
  27      public const AUTHENTICATOR_TRANSPORT_INTERNAL = 'internal';
  28  
  29      /**
  30       * @var string
  31       */
  32      protected $type;
  33  
  34      /**
  35       * @var string
  36       */
  37      protected $id;
  38  
  39      /**
  40       * @var string[]
  41       */
  42      protected $transports;
  43  
  44      /**
  45       * @param string[] $transports
  46       */
  47      public function __construct(string $type, string $id, array $transports = [])
  48      {
  49          $this->type = $type;
  50          $this->id = $id;
  51          $this->transports = $transports;
  52      }
  53  
  54      public function getType(): string
  55      {
  56          return $this->type;
  57      }
  58  
  59      public function getId(): string
  60      {
  61          return $this->id;
  62      }
  63  
  64      /**
  65       * @return string[]
  66       */
  67      public function getTransports(): array
  68      {
  69          return $this->transports;
  70      }
  71  
  72      public static function createFromString(string $data): self
  73      {
  74          $data = json_decode($data, true);
  75          Assertion::eq(JSON_ERROR_NONE, json_last_error(), 'Invalid data');
  76          Assertion::isArray($data, 'Invalid data');
  77  
  78          return self::createFromArray($data);
  79      }
  80  
  81      public static function createFromArray(array $json): self
  82      {
  83          Assertion::keyExists($json, 'type', 'Invalid input. "type" is missing.');
  84          Assertion::keyExists($json, 'id', 'Invalid input. "id" is missing.');
  85  
  86          return new self(
  87              $json['type'],
  88              Base64Url::decode($json['id']),
  89              $json['transports'] ?? []
  90          );
  91      }
  92  
  93      public function jsonSerialize(): array
  94      {
  95          $json = [
  96              'type' => $this->type,
  97              'id' => Base64Url::encode($this->id),
  98          ];
  99          if (0 !== \count($this->transports)) {
 100              $json['transports'] = $this->transports;
 101          }
 102  
 103          return $json;
 104      }
 105  }


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