bug #36180 [Uid] work around buggy libuuid (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Uid] work around buggy libuuid | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - As found while working on the polyfill, fixed upstream ind6ddf07d31
Commits -------ebf601b1a6
[Uid] work around buggy libuuid
This commit is contained in:
commit
f18294ba4b
@ -59,6 +59,7 @@ class UuidTest extends TestCase
|
||||
$uuid = Uuid::v3(new UuidV4(self::A_UUID_V4), 'the name');
|
||||
|
||||
$this->assertInstanceOf(UuidV3::class, $uuid);
|
||||
$this->assertSame('8dac64d3-937a-3e7c-aa1d-d5d6c06a61f5', (string) $uuid);
|
||||
}
|
||||
|
||||
public function testV4()
|
||||
@ -70,9 +71,10 @@ class UuidTest extends TestCase
|
||||
|
||||
public function testV5()
|
||||
{
|
||||
$uuid = Uuid::v5(new UuidV4(self::A_UUID_V4), 'the name');
|
||||
$uuid = Uuid::v5(new UuidV4('ec07aa88-f84e-47b9-a581-1c6b30a2f484'), 'the name');
|
||||
|
||||
$this->assertInstanceOf(UuidV5::class, $uuid);
|
||||
$this->assertSame('851def0c-b9c7-55aa-a991-130e769ec0a9', (string) $uuid);
|
||||
}
|
||||
|
||||
public function testV6()
|
||||
|
@ -74,7 +74,14 @@ class Uuid extends AbstractUid
|
||||
|
||||
final public static function v3(self $namespace, string $name): UuidV3
|
||||
{
|
||||
return new UuidV3(uuid_generate_md5($namespace->uid, $name));
|
||||
// don't use uuid_generate_md5(), some versions are buggy
|
||||
$uuid = md5(hex2bin(str_replace('-', '', $namespace->uid)).$name, true);
|
||||
$uuid[8] = $uuid[8] & "\x3F" | "\x80";
|
||||
$uuid = substr_replace(bin2hex($uuid), '-', 8, 0);
|
||||
$uuid = substr_replace($uuid, '-3', 13, 1);
|
||||
$uuid = substr_replace($uuid, '-', 18, 0);
|
||||
|
||||
return new UuidV3(substr_replace($uuid, '-', 23, 0));
|
||||
}
|
||||
|
||||
final public static function v4(): UuidV4
|
||||
@ -84,7 +91,14 @@ class Uuid extends AbstractUid
|
||||
|
||||
final public static function v5(self $namespace, string $name): UuidV5
|
||||
{
|
||||
return new UuidV5(uuid_generate_sha1($namespace->uid, $name));
|
||||
// don't use uuid_generate_sha1(), some versions are buggy
|
||||
$uuid = substr(sha1(hex2bin(str_replace('-', '', $namespace->uid)).$name, true), 0, 16);
|
||||
$uuid[8] = $uuid[8] & "\x3F" | "\x80";
|
||||
$uuid = substr_replace(bin2hex($uuid), '-', 8, 0);
|
||||
$uuid = substr_replace($uuid, '-5', 13, 1);
|
||||
$uuid = substr_replace($uuid, '-', 18, 0);
|
||||
|
||||
return new UuidV5(substr_replace($uuid, '-', 23, 0));
|
||||
}
|
||||
|
||||
final public static function v6(): UuidV6
|
||||
|
Reference in New Issue
Block a user