mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
Drop the use of OpenSSL as a fallback and use paragonie/random_compat
Fixes issue #80 for the 3.x series
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# ramsey/uuid Changelog
|
||||
|
||||
## 3.3.0
|
||||
|
||||
_Released: TBD_
|
||||
|
||||
* Drop the use of OpenSSL as a fallback and use [paragonie/random_compat][] to support RandomBytesGenerator in versions of PHP earlier than 7.0. This addresses and fixes the [collision issue][].
|
||||
|
||||
## 3.2.0
|
||||
|
||||
_Released: 2016-02-17_
|
||||
|
||||
@@ -16,9 +16,10 @@ namespace Ramsey\Uuid\Generator;
|
||||
|
||||
/**
|
||||
* RandomBytesGenerator provides functionality to generate strings of random
|
||||
* binary data using `random_bytes()` function in PHP 7+
|
||||
* binary data using `random_bytes()` function in PHP 7+ or paragonie/random_compat
|
||||
*
|
||||
* @link http://php.net/random_bytes
|
||||
* @link https://github.com/paragonie/random_compat
|
||||
*/
|
||||
class RandomBytesGenerator implements RandomGeneratorInterface
|
||||
{
|
||||
|
||||
@@ -19,42 +19,6 @@ namespace Ramsey\Uuid\Generator;
|
||||
*/
|
||||
class RandomGeneratorFactory
|
||||
{
|
||||
/**
|
||||
* For testing, `openssl_random_pseudo_bytes()` override; if `true`, treat as
|
||||
* if `openssl_random_pseudo_bytes()` is not available
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $forceNoOpensslRandomPseudoBytes = false;
|
||||
|
||||
/**
|
||||
* For testing, `random_bytes()` override; if `true`, treat as if `random_bytes()`
|
||||
* is not available.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $forceNoRandomBytes = false;
|
||||
|
||||
/**
|
||||
* Returns `true` if the system has `openssl_random_pseudo_bytes()`
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function hasOpensslRandomPseudoBytes()
|
||||
{
|
||||
return (function_exists('openssl_random_pseudo_bytes') && !self::$forceNoOpensslRandomPseudoBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the system has `random_bytes()`
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function hasRandomBytes()
|
||||
{
|
||||
return (function_exists('random_bytes') && !self::$forceNoRandomBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a default random generator, based on the current environment
|
||||
*
|
||||
@@ -62,14 +26,6 @@ class RandomGeneratorFactory
|
||||
*/
|
||||
public static function getGenerator()
|
||||
{
|
||||
if (self::hasRandomBytes()) {
|
||||
return new RandomBytesGenerator();
|
||||
}
|
||||
|
||||
if (self::hasOpensslRandomPseudoBytes()) {
|
||||
return new OpenSslGenerator();
|
||||
}
|
||||
|
||||
return new MtRandGenerator();
|
||||
return new RandomBytesGenerator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,10 @@ use Ramsey\Uuid\Generator\RandomGeneratorFactory;
|
||||
|
||||
class RandomGeneratorFactoryTest extends TestCase
|
||||
{
|
||||
public function testFactoryReturnsNonOpenSslGeneratorWithForceNoOpenSsl()
|
||||
public function testFactoryReturnsRandomBytesGenerator()
|
||||
{
|
||||
RandomGeneratorFactory::$forceNoRandomBytes = true;
|
||||
RandomGeneratorFactory::$forceNoOpensslRandomPseudoBytes = true;
|
||||
|
||||
$generator = RandomGeneratorFactory::getGenerator();
|
||||
|
||||
$this->assertNotInstanceOf('\Ramsey\Uuid\Generator\OpenSslGenerator', $generator);
|
||||
}
|
||||
|
||||
public function testFactoryReturnsOpenSslGeneratorIfAvailable()
|
||||
{
|
||||
RandomGeneratorFactory::$forceNoOpensslRandomPseudoBytes = false;
|
||||
|
||||
$generator = RandomGeneratorFactory::getGenerator();
|
||||
|
||||
$this->assertInstanceOf('\Ramsey\Uuid\Generator\OpenSslGenerator', $generator);
|
||||
$this->assertInstanceOf('Ramsey\\Uuid\\Generator\\RandomBytesGenerator', $generator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ class UuidTest extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
Uuid::setFactory(new UuidFactory());
|
||||
|
||||
RandomGeneratorFactory::$forceNoOpensslRandomPseudoBytes = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -805,17 +803,6 @@ class UuidTest extends TestCase
|
||||
$this->assertEquals(4, $uuid->getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testUuid4WithoutRandomBytes()
|
||||
{
|
||||
RandomGeneratorFactory::$forceNoOpensslRandomPseudoBytes = true;
|
||||
$uuid = Uuid::uuid4();
|
||||
$this->assertInstanceOf('Ramsey\Uuid\Uuid', $uuid);
|
||||
$this->assertEquals(2, $uuid->getVariant());
|
||||
$this->assertEquals(4, $uuid->getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that generated UUID's using COMB are sequential
|
||||
* @return string
|
||||
|
||||
Reference in New Issue
Block a user