diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cbd955..5d0ee58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Rhumsaa\Uuid Changelog +## 2.9.0 + +_Released: 2016-03-22_ + + * Drop support for OpenSSL in favor of [paragonie/random_compat][]. This addresses and fixes the [collision issue][]. + ## 2.8.4 _Released: 2015-12-17_ @@ -176,3 +182,7 @@ _Released: 2012-08-06_ _Released: 2012-07-19_ * Initial release + + +[paragonie/random_compat]: https://github.com/paragonie/random_compat +[collision issue]: https://github.com/ramsey/uuid/issues/80 diff --git a/composer.json b/composer.json index ccd8f2c..628e467 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "source": "https://github.com/ramsey/uuid" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.3", + "paragonie/random_compat": "^1.0|^2.0" }, "require-dev": { "moontoast/math": "~1.1", diff --git a/src/Uuid.php b/src/Uuid.php index 1a5d806..7c8b814 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -111,12 +111,12 @@ final class Uuid public static $forceNoBigNumber = false; /** - * For testing, openssl_random_pseudo_bytes() override; if true, treat as - * if openssl_random_pseudo_bytes() is not available + * For testing, random_bytes() override; if true, treat as + * if random_bytes() is not available * * @var bool */ - public static $forceNoOpensslRandomPseudoBytes = false; + public static $forceNoRandomBytes = false; /** * For testing, sets time of day to a static, known value @@ -1185,13 +1185,13 @@ final class Uuid } /** - * Returns true if the system has openssl_random_pseudo_bytes() + * Returns true if the system has random_bytes() * * @return bool */ - protected static function hasOpensslRandomPseudoBytes() + protected static function hasRandomBytes() { - return (function_exists('openssl_random_pseudo_bytes') && !self::$forceNoOpensslRandomPseudoBytes); + return (function_exists('random_bytes') && !self::$forceNoRandomBytes); } /** @@ -1244,8 +1244,8 @@ final class Uuid */ private static function generateBytes($length) { - if (self::hasOpensslRandomPseudoBytes()) { - return openssl_random_pseudo_bytes($length); + if (self::hasRandomBytes()) { + return random_bytes($length); } $bytes = ''; diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 538d428..88ae2f0 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -8,7 +8,7 @@ class UuidTest extends TestCase Uuid::$timeOfDayTest = null; Uuid::$force32Bit = false; Uuid::$forceNoBigNumber = false; - Uuid::$forceNoOpensslRandomPseudoBytes = false; + Uuid::$forceNoRandomBytes = false; Uuid::$ignoreSystemNode = false; } @@ -826,9 +826,9 @@ class UuidTest extends TestCase * @covers Rhumsaa\Uuid\Uuid::generateBytes * @covers Rhumsaa\Uuid\Uuid::uuidFromHashedName */ - public function testUuid4WithoutOpensslRandomPseudoBytes() + public function testUuid4WithoutRandomBytes() { - Uuid::$forceNoOpensslRandomPseudoBytes = true; + Uuid::$forceNoRandomBytes = true; $uuid = Uuid::uuid4(); $this->assertInstanceOf('Rhumsaa\Uuid\Uuid', $uuid); $this->assertEquals(2, $uuid->getVariant()); @@ -1275,21 +1275,21 @@ class UuidTest extends TestCase } /** - * @covers Rhumsaa\Uuid\Uuid::hasOpensslRandomPseudoBytes + * @covers Rhumsaa\Uuid\Uuid::hasRandomBytes */ - public function testHasOpensslRandomPseudoBytes() + public function testHasRandomBytes() { - $hasOpensslRandomPseudoBytes = new \ReflectionMethod( - 'Rhumsaa\Uuid\Uuid', 'hasOpensslRandomPseudoBytes' + $hasRandomBytes = new \ReflectionMethod( + 'Rhumsaa\Uuid\Uuid', 'hasRandomBytes' ); - $hasOpensslRandomPseudoBytes->setAccessible(true); + $hasRandomBytes->setAccessible(true); $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertTrue($hasOpensslRandomPseudoBytes->invoke($uuid)); + $this->assertTrue($hasRandomBytes->invoke($uuid)); - Uuid::$forceNoOpensslRandomPseudoBytes = true; - $this->assertFalse($hasOpensslRandomPseudoBytes->invoke($uuid)); + Uuid::$forceNoRandomBytes = true; + $this->assertFalse($hasRandomBytes->invoke($uuid)); } /**