[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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      public function offsetSet($offset, $value)
  64      {
  65          if (!is_int($value)) {
  66              throw new InvalidArgumentException('Expected an integer');
  67          }
  68          if (is_null($offset)) {
  69              $this->container[] = $value;
  70          } else {
  71              $this->container[$offset] = $value;
  72          }
  73      }
  74  
  75      /**
  76       * @internal You should not use this directly from another application
  77       *
  78       * @param int $offset
  79       * @return bool
  80       * @psalm-suppress MixedArrayOffset
  81       */
  82      public function offsetExists($offset)
  83      {
  84          return isset($this->container[$offset]);
  85      }
  86  
  87      /**
  88       * @internal You should not use this directly from another application
  89       *
  90       * @param int $offset
  91       * @return void
  92       * @psalm-suppress MixedArrayOffset
  93       */
  94      public function offsetUnset($offset)
  95      {
  96          unset($this->container[$offset]);
  97      }
  98  
  99      /**
 100       * @internal You should not use this directly from another application
 101       *
 102       * @param int $offset
 103       * @return int
 104       * @psalm-suppress MixedArrayOffset
 105       */
 106      public function offsetGet($offset)
 107      {
 108          if (!isset($this->container[$offset])) {
 109              $this->container[$offset] = 0;
 110          }
 111          return (int) ($this->container[$offset]);
 112      }
 113  
 114      /**
 115       * @internal You should not use this directly from another application
 116       *
 117       * @return array
 118       */
 119      public function __debugInfo()
 120      {
 121          return array(implode(', ', $this->container));
 122      }
 123  }


Generated: Thu Oct 17 08:20:02 2019 Cross-referenced by PHPXref 0.7