[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/cose-lib/src/Key/ -> Key.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 Cose\Key;
  15  
  16  use Assert\Assertion;
  17  
  18  class Key
  19  {
  20      public const TYPE = 1;
  21      public const TYPE_OKP = 1;
  22      public const TYPE_EC2 = 2;
  23      public const TYPE_RSA = 3;
  24      public const TYPE_OCT = 4;
  25      public const KID = 2;
  26      public const ALG = 3;
  27      public const KEY_OPS = 4;
  28      public const BASE_IV = 5;
  29  
  30      /**
  31       * @var array
  32       */
  33      private $data;
  34  
  35      public function __construct(array $data)
  36      {
  37          Assertion::keyExists($data, self::TYPE, 'Invalid key: the type is not defined');
  38          $this->data = $data;
  39      }
  40  
  41      public static function createFromData(array $data): self
  42      {
  43          Assertion::keyExists($data, self::TYPE, 'Invalid key: the type is not defined');
  44          switch ($data[self::TYPE]) {
  45              case 1:
  46                  return new OkpKey($data);
  47              case 2:
  48                  return new Ec2Key($data);
  49              case 3:
  50                  return new RsaKey($data);
  51              case 4:
  52                  return new SymmetricKey($data);
  53              default:
  54                  return new self($data);
  55          }
  56      }
  57  
  58      /**
  59       * @return int|string
  60       */
  61      public function type()
  62      {
  63          return $this->data[self::TYPE];
  64      }
  65  
  66      public function alg(): int
  67      {
  68          return (int) $this->get(self::ALG);
  69      }
  70  
  71      public function getData(): array
  72      {
  73          return $this->data;
  74      }
  75  
  76      public function has(int $key): bool
  77      {
  78          return \array_key_exists($key, $this->data);
  79      }
  80  
  81      /**
  82       * @return mixed
  83       */
  84      public function get(int $key)
  85      {
  86          Assertion::keyExists($this->data, $key, sprintf('The key has no data at index %d', $key));
  87  
  88          return $this->data[$key];
  89      }
  90  }


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