[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  
   3  if (class_exists('ParagonIE_Sodium_Core32_Curve25519_Fe', false)) {
   4      return;
   5  }
   6  
   7  /**
   8   * Class ParagonIE_Sodium_Core32_Curve25519_Fe
   9   *
  10   * This represents a Field Element
  11   */
  12  class ParagonIE_Sodium_Core32_Curve25519_Fe implements ArrayAccess
  13  {
  14      /**
  15       * @var array<int, ParagonIE_Sodium_Core32_Int32>
  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, ParagonIE_Sodium_Core32_Int32> $array
  28       * @param bool $save_indexes
  29       * @return self
  30       * @throws SodiumException
  31       * @throws TypeError
  32       */
  33      public static function fromArray($array, $save_indexes = null)
  34      {
  35          $count = count($array);
  36          if ($save_indexes) {
  37              $keys = array_keys($array);
  38          } else {
  39              $keys = range(0, $count - 1);
  40          }
  41          $array = array_values($array);
  42  
  43          $obj = new ParagonIE_Sodium_Core32_Curve25519_Fe();
  44          if ($save_indexes) {
  45              for ($i = 0; $i < $count; ++$i) {
  46                  $array[$i]->overflow = 0;
  47                  $obj->offsetSet($keys[$i], $array[$i]);
  48              }
  49          } else {
  50              for ($i = 0; $i < $count; ++$i) {
  51                  $array[$i]->overflow = 0;
  52                  $obj->offsetSet($i, $array[$i]);
  53              }
  54          }
  55          return $obj;
  56      }
  57  
  58      /**
  59       * @internal You should not use this directly from another application
  60       *
  61       * @param array<int, int> $array
  62       * @param bool $save_indexes
  63       * @return self
  64       * @throws SodiumException
  65       * @throws TypeError
  66       */
  67      public static function fromIntArray($array, $save_indexes = null)
  68      {
  69          $count = count($array);
  70          if ($save_indexes) {
  71              $keys = array_keys($array);
  72          } else {
  73              $keys = range(0, $count - 1);
  74          }
  75          $array = array_values($array);
  76          $set = array();
  77          /** @var int $i */
  78          /** @var int $v */
  79          foreach ($array as $i => $v) {
  80              $set[$i] = ParagonIE_Sodium_Core32_Int32::fromInt($v);
  81          }
  82  
  83          $obj = new ParagonIE_Sodium_Core32_Curve25519_Fe();
  84          if ($save_indexes) {
  85              for ($i = 0; $i < $count; ++$i) {
  86                  $set[$i]->overflow = 0;
  87                  $obj->offsetSet($keys[$i], $set[$i]);
  88              }
  89          } else {
  90              for ($i = 0; $i < $count; ++$i) {
  91                  $set[$i]->overflow = 0;
  92                  $obj->offsetSet($i, $set[$i]);
  93              }
  94          }
  95          return $obj;
  96      }
  97  
  98      /**
  99       * @internal You should not use this directly from another application
 100       *
 101       * @param mixed $offset
 102       * @param mixed $value
 103       * @return void
 104       * @throws SodiumException
 105       * @throws TypeError
 106       */
 107      #[ReturnTypeWillChange]
 108      public function offsetSet($offset, $value)
 109      {
 110          if (!($value instanceof ParagonIE_Sodium_Core32_Int32)) {
 111              throw new InvalidArgumentException('Expected an instance of ParagonIE_Sodium_Core32_Int32');
 112          }
 113          if (is_null($offset)) {
 114              $this->container[] = $value;
 115          } else {
 116              ParagonIE_Sodium_Core32_Util::declareScalarType($offset, 'int', 1);
 117              $this->container[(int) $offset] = $value;
 118          }
 119      }
 120  
 121      /**
 122       * @internal You should not use this directly from another application
 123       *
 124       * @param mixed $offset
 125       * @return bool
 126       * @psalm-suppress MixedArrayOffset
 127       */
 128      #[ReturnTypeWillChange]
 129      public function offsetExists($offset)
 130      {
 131          return isset($this->container[$offset]);
 132      }
 133  
 134      /**
 135       * @internal You should not use this directly from another application
 136       *
 137       * @param mixed $offset
 138       * @return void
 139       * @psalm-suppress MixedArrayOffset
 140       */
 141      #[ReturnTypeWillChange]
 142      public function offsetUnset($offset)
 143      {
 144          unset($this->container[$offset]);
 145      }
 146  
 147      /**
 148       * @internal You should not use this directly from another application
 149       *
 150       * @param mixed $offset
 151       * @return ParagonIE_Sodium_Core32_Int32
 152       * @psalm-suppress MixedArrayOffset
 153       */
 154      #[ReturnTypeWillChange]
 155      public function offsetGet($offset)
 156      {
 157          if (!isset($this->container[$offset])) {
 158              $this->container[(int) $offset] = new ParagonIE_Sodium_Core32_Int32();
 159          }
 160          /** @var ParagonIE_Sodium_Core32_Int32 $get */
 161          $get = $this->container[$offset];
 162          return $get;
 163      }
 164  
 165      /**
 166       * @internal You should not use this directly from another application
 167       *
 168       * @return array
 169       */
 170      public function __debugInfo()
 171      {
 172          if (empty($this->container)) {
 173              return array();
 174          }
 175          $c = array(
 176              (int) ($this->container[0]->toInt()),
 177              (int) ($this->container[1]->toInt()),
 178              (int) ($this->container[2]->toInt()),
 179              (int) ($this->container[3]->toInt()),
 180              (int) ($this->container[4]->toInt()),
 181              (int) ($this->container[5]->toInt()),
 182              (int) ($this->container[6]->toInt()),
 183              (int) ($this->container[7]->toInt()),
 184              (int) ($this->container[8]->toInt()),
 185              (int) ($this->container[9]->toInt())
 186          );
 187          return array(implode(', ', $c));
 188      }
 189  }


Generated : Sat Nov 27 08:20:02 2021 Cross-referenced by PHPXref