diff --git a/CHANGELOG.md b/CHANGELOG.md index 94adf55..3e27111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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_ diff --git a/src/Generator/RandomBytesGenerator.php b/src/Generator/RandomBytesGenerator.php index 55e647a..1e8392a 100644 --- a/src/Generator/RandomBytesGenerator.php +++ b/src/Generator/RandomBytesGenerator.php @@ -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 { diff --git a/src/Generator/RandomGeneratorFactory.php b/src/Generator/RandomGeneratorFactory.php index be6adaf..3911062 100644 --- a/src/Generator/RandomGeneratorFactory.php +++ b/src/Generator/RandomGeneratorFactory.php @@ -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(); } } diff --git a/tests/src/Generator/RandomGeneratorFactoryTest.php b/tests/src/Generator/RandomGeneratorFactoryTest.php index 0d92660..6293165 100644 --- a/tests/src/Generator/RandomGeneratorFactoryTest.php +++ b/tests/src/Generator/RandomGeneratorFactoryTest.php @@ -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); } } diff --git a/tests/src/UuidTest.php b/tests/src/UuidTest.php index 6927034..94a63d3 100644 --- a/tests/src/UuidTest.php +++ b/tests/src/UuidTest.php @@ -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