Skip to content

Commit b2ef4dd

Browse files
committed
Merge pull request #100 from ramsey/2.x/random_compat
Drop OpenSSL support and use paragonie/random_compat
2 parents 8d94d71 + b64eb30 commit b2ef4dd

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Rhumsaa\Uuid Changelog
22

3+
## 2.9.0
4+
5+
_Released: 2016-03-22_
6+
7+
* Drop support for OpenSSL in favor of [paragonie/random_compat][]. This addresses and fixes the [collision issue][].
8+
39
## 2.8.4
410

511
_Released: 2015-12-17_
@@ -176,3 +182,7 @@ _Released: 2012-08-06_
176182
_Released: 2012-07-19_
177183

178184
* Initial release
185+
186+
187+
[paragonie/random_compat]: https://github.com/paragonie/random_compat
188+
[collision issue]: https://github.com/ramsey/uuid/issues/80

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"source": "https://github.com/ramsey/uuid"
2121
},
2222
"require": {
23-
"php": ">=5.3.3"
23+
"php": ">=5.3.3",
24+
"paragonie/random_compat": "^1.0|^2.0"
2425
},
2526
"require-dev": {
2627
"moontoast/math": "~1.1",

src/Uuid.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ final class Uuid
111111
public static $forceNoBigNumber = false;
112112

113113
/**
114-
* For testing, openssl_random_pseudo_bytes() override; if true, treat as
115-
* if openssl_random_pseudo_bytes() is not available
114+
* For testing, random_bytes() override; if true, treat as
115+
* if random_bytes() is not available
116116
*
117117
* @var bool
118118
*/
119-
public static $forceNoOpensslRandomPseudoBytes = false;
119+
public static $forceNoRandomBytes = false;
120120

121121
/**
122122
* For testing, sets time of day to a static, known value
@@ -1185,13 +1185,13 @@ protected static function hasBigNumber()
11851185
}
11861186

11871187
/**
1188-
* Returns true if the system has openssl_random_pseudo_bytes()
1188+
* Returns true if the system has random_bytes()
11891189
*
11901190
* @return bool
11911191
*/
1192-
protected static function hasOpensslRandomPseudoBytes()
1192+
protected static function hasRandomBytes()
11931193
{
1194-
return (function_exists('openssl_random_pseudo_bytes') && !self::$forceNoOpensslRandomPseudoBytes);
1194+
return (function_exists('random_bytes') && !self::$forceNoRandomBytes);
11951195
}
11961196

11971197
/**
@@ -1244,8 +1244,8 @@ protected static function uuidFromHashedName($hash, $version)
12441244
*/
12451245
private static function generateBytes($length)
12461246
{
1247-
if (self::hasOpensslRandomPseudoBytes()) {
1248-
return openssl_random_pseudo_bytes($length);
1247+
if (self::hasRandomBytes()) {
1248+
return random_bytes($length);
12491249
}
12501250

12511251
$bytes = '';

tests/UuidTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ protected function setUp()
88
Uuid::$timeOfDayTest = null;
99
Uuid::$force32Bit = false;
1010
Uuid::$forceNoBigNumber = false;
11-
Uuid::$forceNoOpensslRandomPseudoBytes = false;
11+
Uuid::$forceNoRandomBytes = false;
1212
Uuid::$ignoreSystemNode = false;
1313
}
1414

@@ -826,9 +826,9 @@ public function testUuid4()
826826
* @covers Rhumsaa\Uuid\Uuid::generateBytes
827827
* @covers Rhumsaa\Uuid\Uuid::uuidFromHashedName
828828
*/
829-
public function testUuid4WithoutOpensslRandomPseudoBytes()
829+
public function testUuid4WithoutRandomBytes()
830830
{
831-
Uuid::$forceNoOpensslRandomPseudoBytes = true;
831+
Uuid::$forceNoRandomBytes = true;
832832
$uuid = Uuid::uuid4();
833833
$this->assertInstanceOf('Rhumsaa\Uuid\Uuid', $uuid);
834834
$this->assertEquals(2, $uuid->getVariant());
@@ -1275,21 +1275,21 @@ public function testHasBigNumber()
12751275
}
12761276

12771277
/**
1278-
* @covers Rhumsaa\Uuid\Uuid::hasOpensslRandomPseudoBytes
1278+
* @covers Rhumsaa\Uuid\Uuid::hasRandomBytes
12791279
*/
1280-
public function testHasOpensslRandomPseudoBytes()
1280+
public function testHasRandomBytes()
12811281
{
1282-
$hasOpensslRandomPseudoBytes = new \ReflectionMethod(
1283-
'Rhumsaa\Uuid\Uuid', 'hasOpensslRandomPseudoBytes'
1282+
$hasRandomBytes = new \ReflectionMethod(
1283+
'Rhumsaa\Uuid\Uuid', 'hasRandomBytes'
12841284
);
1285-
$hasOpensslRandomPseudoBytes->setAccessible(true);
1285+
$hasRandomBytes->setAccessible(true);
12861286

12871287
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
12881288

1289-
$this->assertTrue($hasOpensslRandomPseudoBytes->invoke($uuid));
1289+
$this->assertTrue($hasRandomBytes->invoke($uuid));
12901290

1291-
Uuid::$forceNoOpensslRandomPseudoBytes = true;
1292-
$this->assertFalse($hasOpensslRandomPseudoBytes->invoke($uuid));
1291+
Uuid::$forceNoRandomBytes = true;
1292+
$this->assertFalse($hasRandomBytes->invoke($uuid));
12931293
}
12941294

12951295
/**

0 commit comments

Comments
 (0)