mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 02:07:09 +00:00
Merge branch 'master' into immutable-keys
This commit is contained in:
commit
337b41f865
@ -268,9 +268,10 @@ abstract class ASN1
|
||||
$tag = 0;
|
||||
// process septets (since the eighth bit is ignored, it's not an octet)
|
||||
do {
|
||||
$loop = ord($encoded[0]) >> 7;
|
||||
$temp = ord($encoded[$encoded_pos++]);
|
||||
$loop = $temp >> 7;
|
||||
$tag <<= 7;
|
||||
$tag |= ord($encoded[$encoded_pos++]) & 0x7F;
|
||||
$tag |= $temp & 0x7F;
|
||||
$start++;
|
||||
} while ($loop);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ abstract class Engine implements \Serializable
|
||||
// (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
|
||||
// [^-0-9].*: find any non-numeric characters and then any characters that follow that
|
||||
$this->value = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
|
||||
if (!strlen($this->value)) {
|
||||
if (!strlen($this->value) || $this->value == '-') {
|
||||
$this->value = '0';
|
||||
}
|
||||
static::initialize($base);
|
||||
|
@ -296,7 +296,14 @@ class GMP extends Engine
|
||||
*/
|
||||
public function compare(GMP $y)
|
||||
{
|
||||
return gmp_cmp($this->value, $y->value);
|
||||
$r = gmp_cmp($this->value, $y->value);
|
||||
if ($r < -1) {
|
||||
$r = -1;
|
||||
}
|
||||
if ($r > 1) {
|
||||
$r = 1;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -856,5 +856,23 @@ wkwhE/JaQAEHq2PHnEmvwyBiJcHSdLXkcLzYlg19Ho0BPqVKdulx8GAk
|
||||
|
||||
$r = $x509->loadX509($result);
|
||||
$this->assertArrayHasKey('tbsCertificate', $r);
|
||||
|
||||
public function testLongTagOnBadCert()
|
||||
{
|
||||
// the problem with this cert is that it'd cause an infinite loop
|
||||
$x509 = new X509();
|
||||
$r = @$x509->loadX509('-----BEGIN CERTIFICATE-----
|
||||
MIIBjDCCATGgAwIBAgIJAJSiNCIEEiyyMAoGCCqGSM49BAMCMA0xCzAJBgNVBAMM
|
||||
AkNBMB4XDTE5MDUwOTAzMTUzMFoXDTE5MDYwODAzMTUzMFowDTELMAkGA1UEAwwC
|
||||
Q0FNRmt3RXdZSEtvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUU4K0R0TDM0Syt0
|
||||
RzZGR3o2QXJ2QzlySnlmN1Y5N09wY3ZWeG1IbjRXQStXc0E2L0dxLzZ1cUFBdG5Y
|
||||
RDZOQUxsRVVSVFZCcmlvNjB4L0xZN1ZoTmx0UT09o1kwVzAgBgNVHQ4BAf8EFgQU
|
||||
25GbjmtucxjEGkWrB2R6AB6/yrkwIgYDVR0jAQH/BBgwFoAU25GbjmtucxjEGkWr
|
||||
B2R6AB6/yrkwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNJADBGAiEA6ZB6
|
||||
+KlUM1ZXFrxtDxLWqp51myWDulWjnK6cl7b5AVgCIQCRdthTn8JlN5bRSnJ6qiCk
|
||||
A9bhRA0cVk7bAEU2c44CYg==
|
||||
-----END CERTIFICATE-----');
|
||||
|
||||
$this->assertFalse($r);
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +178,9 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
// c < d
|
||||
$this->assertLessThan(0, $c->compare($d));
|
||||
$this->assertGreaterThan(0, $d->compare($c));
|
||||
|
||||
$this->assertSame(-1, $this->getInstance(-999)->compare($this->getInstance(370)));
|
||||
$this->assertSame(1, $this->getInstance(999)->compare($this->getInstance(-700)));
|
||||
}
|
||||
|
||||
public function testBitwiseAND()
|
||||
@ -457,4 +460,13 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
$temp = $this->getInstance(48);
|
||||
$this->assertSame($temp->toHex(true), '30');
|
||||
}
|
||||
|
||||
public function testZeroBase10()
|
||||
{
|
||||
$temp = $this->getInstance('00');
|
||||
$this->assertSame($temp->toString(), '0');
|
||||
|
||||
$temp = $this->getInstance('-0');
|
||||
$this->assertSame($temp->toString(), '0');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user