mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-09 23:28:33 +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()
|
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 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');
|
$cert = file_get_contents(dirname(__FILE__) . '/ASN1/mal-cert-02.der');
|
||||||
|
|
||||||
$asn1 = new ASN1();
|
$decoded = ASN1::decodeBER($cert);
|
||||||
$decoded = $asn1->decodeBER($cert);
|
$this->assertNull($decoded);
|
||||||
$this->assertFalse($decoded[0]);
|
|
||||||
|
|
||||||
//$x509 = new X509();
|
//$x509 = new X509();
|
||||||
//$x509->loadX509($cert);
|
//$x509->loadX509($cert);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user