[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/sodium_compat/src/Core/Curve25519/ -> Fe.php (source)

   1  <?php
   2  
   3  if (class_exists('ParagonIE_Sodium_Core_Curve25519_Fe', false)) {
   4      return;
   5  }
   6  
   7  /**
   8   * Class ParagonIE_Sodium_Core_Curve25519_Fe
   9   *
  10   * This represents a Field Element
  11   */
  12  class ParagonIE_Sodium_Core_Curve25519_Fe implements ArrayAccess
  13  {
  14      /**
  15       * @var array<int, int>
  16       */
  17      protected $container = array();
  18  
  19      /**
  20       * @var int
  21       */
  22      protected $size = 10;
  23  
  24      /**
  25       * @internal You should not use this directly from another application
  26       *
  27       * @param array<int, int> $array
  28       * @param bool $save_indexes
  29       * @return self
  30       */
  31      public static function fromArray($array, $save_indexes = null)
  32      {
  33          $count = count($array);
  34          if ($save_indexes) {
  35              $keys = array_keys($array);
  36          } else {
  37              $keys = range(0, $count - 1);
  38          }
  39          $array = array_values($array);
  40          /** @var array<int, int> $keys */
  41  
  42          $obj = new ParagonIE_Sodium_Core_Curve25519_Fe();
  43          if ($save_indexes) {
  44              for ($i = 0; $i < $count; ++$i) {
  45                  $obj->offsetSet($keys[$i], $array[$i]);
  46              }
  47          } else {
  48              for ($i = 0; $i < $count; ++$i) {
  49                  $obj->offsetSet($i, $array[$i]);
  50              }
  51          }
  52          return $obj;
  53      }
  54  
  55      /**
  56       * @internal You should not use this directly from another application
  57       *
  58       * @param int|null $offset
  59       * @param int $value
  60       * @return void
  61       * @psalm-suppress MixedArrayOffset
  62       */
  63      #[ReturnTypeWillChange]
  64      public function offsetSet($offset, $value)
  65      {
  66          if (!is_int($value)) {
  67              throw new InvalidArgumentException('Expected an integer');
  68          }
  69          if (is_null($offset)) {
  70              $this->container[] = $value;
  71          } else {
  72              $this->container[$offset] = $value;
  73          }
  74      }
  75  
  76      /**
  77       * @internal You should not use this directly from another application
  78       *
  79       * @param int $offset
  80       * @return bool
  81       * @psalm-suppress MixedArrayOffset
  82       */
  83      #[ReturnTypeWillChange]
  84      public function offsetExists($offset)
  85      {
  86          return isset($this->container[$offset]);
  87      }
  88  
  89      /**
  90       * @internal You should not use this directly from another application
  91       *
  92       * @param int $offset
  93       * @return void
  94       * @psalm-suppress MixedArrayOffset
  95       */
  96      #[ReturnTypeWillChange]
  97      public function offsetUnset($offset)
  98      {
  99          unset($this->container[$offset]);
 100      }
 101  
 102      /**
 103       * @internal You should not use this directly from another application
 104       *
 105       * @param int $offset
 106       * @return int
 107       * @psalm-suppress MixedArrayOffset
 108       */
 109      #[ReturnTypeWillChange]
 110      public function offsetGet($offset)
 111      {
 112          if (!isset($this->container[$offset])) {
 113              $this->container[$offset] = 0;
 114          }
 115          return (int) ($this->container[$offset]);
 116      }
 117  
 118      /**
 119       * @internal You should not use this directly from another application
 120       *
 121       * @return array
 122       */
 123      public function __debugInfo()
 124      {
 125          return array(implode(', ', $this->container));
 126      }
 127  }


Generated: Sun Dec 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1