mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-04 12:58:28 +00:00
BigInteger: optimize getLength()
This commit is contained in:
parent
c114503b5d
commit
a922309855
@ -619,7 +619,7 @@ abstract class Engine implements \JsonSerializable
|
||||
*/
|
||||
public function getLengthInBytes()
|
||||
{
|
||||
return strlen($this->toBytes());
|
||||
return (int) ceil($this->getLength() / 8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1341,4 +1341,17 @@ abstract class PHP extends Engine
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of a BigInteger in bits
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
$max = count($this->value) - 1;
|
||||
return $max != -1 ?
|
||||
$max * static::BASE + intval(ceil(log($this->value[$max] + 1, 2))) :
|
||||
0;
|
||||
}
|
||||
}
|
||||
|
@ -455,9 +455,8 @@ class ASN1Test extends PhpseclibTestCase
|
||||
{
|
||||
$cert = file_get_contents(dirname(__FILE__) . '/ASN1/mal-cert-02.der');
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$decoded = $asn1->decodeBER($cert);
|
||||
$this->assertFalse($decoded[0]);
|
||||
$decoded = ASN1::decodeBER($cert);
|
||||
$this->assertNull($decoded);
|
||||
|
||||
//$x509 = new X509();
|
||||
//$x509->loadX509($cert);
|
||||
|
Loading…
x
Reference in New Issue
Block a user