mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-30 02:28:31 +00:00
Merge branch '3.0'
This commit is contained in:
commit
57ad98e8bb
27
appveyor.yml
27
appveyor.yml
@ -1,27 +0,0 @@
|
||||
build: false
|
||||
shallow_clone: false
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
clone_folder: C:\projects\phpseclib
|
||||
|
||||
install:
|
||||
- cinst -y OpenSSL.Light
|
||||
- SET PATH=C:\Program Files\OpenSSL;%PATH%
|
||||
- sc config wuauserv start= auto
|
||||
- net start wuauserv
|
||||
- cinst -y php --version 5.6.30
|
||||
- cd c:\tools\php56
|
||||
- copy php.ini-production php.ini
|
||||
- echo date.timezone="UTC" >> php.ini
|
||||
- echo extension_dir=ext >> php.ini
|
||||
- echo extension=php_openssl.dll >> php.ini
|
||||
- echo extension=php_gmp.dll >> php.ini
|
||||
- cd C:\projects\phpseclib
|
||||
- SET PATH=C:\tools\php56;%PATH%
|
||||
- php.exe -r "readfile('http://getcomposer.org/installer');" | php.exe
|
||||
- php.exe composer.phar install --prefer-source --no-interaction
|
||||
|
||||
test_script:
|
||||
- cd C:\projects\phpseclib
|
||||
- vendor\bin\phpunit.bat tests/Windows32Test.php
|
@ -40,7 +40,7 @@ use phpseclib3\Math\BigInteger\Engines\Engine;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BigInteger
|
||||
class BigInteger implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Main Engine
|
||||
@ -438,6 +438,20 @@ class BigInteger
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON Serialize
|
||||
*
|
||||
* Will be called, automatically, when json_encode() is called on a BigInteger object.
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$result = ['hex' => $this->toHex(true)];
|
||||
if ($this->precision > 0) {
|
||||
$result['precision'] = $this->getPrecision();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs modular exponentiation.
|
||||
*
|
||||
|
@ -663,7 +663,7 @@ class BCMath extends Engine
|
||||
public function testBit($x)
|
||||
{
|
||||
return bccomp(
|
||||
bcmod($this->value, bcpow('2', $x + 1, 0), 0),
|
||||
bcmod($this->value, bcpow('2', $x + 1, 0)),
|
||||
bcpow('2', $x, 0),
|
||||
0
|
||||
) >= 0;
|
||||
|
@ -28,7 +28,7 @@ use phpseclib3\Math\BigInteger;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class Engine
|
||||
abstract class Engine implements \JsonSerializable
|
||||
{
|
||||
/* final protected */ const PRIMES = [
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
|
||||
@ -371,6 +371,20 @@ abstract class Engine
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON Serialize
|
||||
*
|
||||
* Will be called, automatically, when json_encode() is called on a BigInteger object.
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$result = ['hex' => $this->toHex(true)];
|
||||
if ($this->precision > 0) {
|
||||
$result['precision'] = $this->precision;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a BigInteger to a base-10 number.
|
||||
*
|
||||
|
@ -771,6 +771,8 @@ abstract class PHP extends Engine
|
||||
for ($i = 0; $i < $length; ++$i) {
|
||||
$value[$i] = $value[$i] & $result->bitmask->value[$i];
|
||||
}
|
||||
|
||||
$value = static::trim($value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -283,6 +283,7 @@ abstract class EvalBarrett extends Base
|
||||
$sum = $' . $result . '[$i] + $_' . $y . '[$i] + $carry;
|
||||
$carry = $sum >= ' . self::float2string($class::BASE_FULL) . ';
|
||||
$' . $result . '[$i] = $carry ? $sum - ' . self::float2string($class::BASE_FULL) . ' : $sum;
|
||||
++$i;
|
||||
}
|
||||
if ($carry) {
|
||||
for (; $' . $result . '[$i] == ' . $class::MAX_DIGIT . '; ++$i) {
|
||||
|
@ -21,6 +21,25 @@ namespace phpseclib3\Math\Common\FiniteField;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
abstract class Integer
|
||||
abstract class Integer implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* JSON Serialize
|
||||
*
|
||||
* Will be called, automatically, when json_encode() is called on a BigInteger object.
|
||||
*
|
||||
* PHP Serialize isn't supported because unserializing would require the factory be
|
||||
* serialized as well and that just sounds like too much
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return ['hex' => $this->toHex(true)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an Integer to a hex string (eg. base-16).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function toHex();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user