diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 210a9034..00000000 --- a/appveyor.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 9365d5cf..adf50838 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -40,7 +40,7 @@ use phpseclib3\Math\BigInteger\Engines\Engine; * @author Jim Wigginton * @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. * diff --git a/phpseclib/Math/BigInteger/Engines/BCMath.php b/phpseclib/Math/BigInteger/Engines/BCMath.php index cc3ff79e..db30a87f 100644 --- a/phpseclib/Math/BigInteger/Engines/BCMath.php +++ b/phpseclib/Math/BigInteger/Engines/BCMath.php @@ -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; diff --git a/phpseclib/Math/BigInteger/Engines/Engine.php b/phpseclib/Math/BigInteger/Engines/Engine.php index 6c152202..fe6bff80 100644 --- a/phpseclib/Math/BigInteger/Engines/Engine.php +++ b/phpseclib/Math/BigInteger/Engines/Engine.php @@ -28,7 +28,7 @@ use phpseclib3\Math\BigInteger; * @author Jim Wigginton * @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. * diff --git a/phpseclib/Math/BigInteger/Engines/PHP.php b/phpseclib/Math/BigInteger/Engines/PHP.php index 3844a928..b363083d 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP.php +++ b/phpseclib/Math/BigInteger/Engines/PHP.php @@ -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; diff --git a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php index e5712b0e..5360aebc 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php +++ b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php @@ -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) { diff --git a/phpseclib/Math/Common/FiniteField/Integer.php b/phpseclib/Math/Common/FiniteField/Integer.php index ab968e26..120026e7 100644 --- a/phpseclib/Math/Common/FiniteField/Integer.php +++ b/phpseclib/Math/Common/FiniteField/Integer.php @@ -21,6 +21,25 @@ namespace phpseclib3\Math\Common\FiniteField; * @author Jim Wigginton * @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(); }