mirror of
https://github.com/danog/tgseclib.git
synced 2025-01-21 21:41:14 +01:00
BigInteger: updates per Joey3000
This commit is contained in:
parent
d86c61de78
commit
f7efbcbc8e
@ -525,13 +525,13 @@ class RSA
|
||||
$finalMax = $max;
|
||||
extract(self::_generateMinMax($temp));
|
||||
|
||||
$n = self::$one->copy();
|
||||
$n = clone self::$one;
|
||||
if (!empty($partial)) {
|
||||
extract(unserialize($partial));
|
||||
} else {
|
||||
$exponents = $coefficients = $primes = array();
|
||||
$lcm = array(
|
||||
'top' => self::$one->copy(),
|
||||
'top' => clone self::$one,
|
||||
'bottom' => false
|
||||
);
|
||||
}
|
||||
@ -716,13 +716,13 @@ class RSA
|
||||
}
|
||||
|
||||
if (is_object($key->modulus)) {
|
||||
$this->modulus = $key->modulus->copy();
|
||||
$this->modulus = clone $key->modulus;
|
||||
}
|
||||
if (is_object($key->exponent)) {
|
||||
$this->exponent = $key->exponent->copy();
|
||||
$this->exponent = clone $key->exponent;
|
||||
}
|
||||
if (is_object($key->publicExponent)) {
|
||||
$this->publicExponent = $key->publicExponent->copy();
|
||||
$this->publicExponent = clone $key->publicExponent;
|
||||
}
|
||||
|
||||
$this->primes = array();
|
||||
@ -730,13 +730,13 @@ class RSA
|
||||
$this->coefficients = array();
|
||||
|
||||
foreach ($this->primes as $prime) {
|
||||
$this->primes[] = $prime->copy();
|
||||
$this->primes[] = clone $prime;
|
||||
}
|
||||
foreach ($this->exponents as $exponent) {
|
||||
$this->exponents[] = $exponent->copy();
|
||||
$this->exponents[] = clone $exponent;
|
||||
}
|
||||
foreach ($this->coefficients as $coefficient) {
|
||||
$this->coefficients[] = $coefficient->copy();
|
||||
$this->coefficients[] = clone $coefficient;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -711,28 +711,6 @@ class BigInteger
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an object
|
||||
*
|
||||
* PHP5 passes objects by reference while PHP4 passes by value. As such, we need a function to guarantee
|
||||
* that all objects are passed by value, when appropriate. More information can be found here:
|
||||
*
|
||||
* {@link http://php.net/language.oop5.basic#51624}
|
||||
*
|
||||
* @access public
|
||||
* @see self::__clone()
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function copy()
|
||||
{
|
||||
$temp = new static();
|
||||
$temp->value = $this->value;
|
||||
$temp->is_negative = $this->is_negative;
|
||||
$temp->precision = $this->precision;
|
||||
$temp->bitmask = $this->bitmask;
|
||||
return $temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* __toString() magic method
|
||||
*
|
||||
@ -747,22 +725,6 @@ class BigInteger
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* __clone() magic method
|
||||
*
|
||||
* @access public
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function __clone()
|
||||
{
|
||||
$temp = new static();
|
||||
$temp->value = $this->value;
|
||||
$temp->is_negative = $this->is_negative;
|
||||
$temp->precision = $this->precision;
|
||||
$temp->bitmask = $this->bitmask;
|
||||
return $temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* __sleep() magic method
|
||||
*
|
||||
@ -1443,8 +1405,8 @@ class BigInteger
|
||||
$zero = new static();
|
||||
}
|
||||
|
||||
$x = $this->copy();
|
||||
$y = $y->copy();
|
||||
$x = clone $this;
|
||||
$y = clone $y;
|
||||
|
||||
$x_sign = $x->is_negative;
|
||||
$y_sign = $y->is_negative;
|
||||
|
@ -352,13 +352,16 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
|
||||
public function testPrecision()
|
||||
{
|
||||
$a = $this->getInstance(50);
|
||||
$a = $this->getInstance(51);
|
||||
$this->assertSame($a->getPrecision(), -1);
|
||||
$b = $a;
|
||||
$c = clone $a;
|
||||
$b->setPrecision(4);
|
||||
$this->assertSame($a->getPrecision(), 4);
|
||||
$this->assertSame($b->getPrecision(), 4);
|
||||
$b->setPrecision(1);
|
||||
$this->assertSame($a->getPrecision(), 1);
|
||||
$this->assertSame("$a", '1');
|
||||
$this->assertSame($b->getPrecision(), 1);
|
||||
$this->assertSame("$b", '1');
|
||||
$this->assertSame($c->getPrecision(), -1);
|
||||
$this->assertSame("$c", '51');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user