@@ -74,7 +74,14 @@ final public static function v1(): UuidV1
74
74
75
75
final public static function v3 (self $ namespace , string $ name ): UuidV3
76
76
{
77
- return new UuidV3 (uuid_generate_md5 ($ namespace ->uid , $ name ));
77
+ // don't use uuid_generate_md5(), some versions are buggy
78
+ $ uuid = md5 (hex2bin (str_replace ('- ' , '' , $ namespace ->uid )).$ name , true );
79
+ $ uuid [8 ] = $ uuid [8 ] & "\x3F" | "\x80" ;
80
+ $ uuid = substr_replace (bin2hex ($ uuid ), '- ' , 8 , 0 );
81
+ $ uuid = substr_replace ($ uuid , '-3 ' , 13 , 1 );
82
+ $ uuid = substr_replace ($ uuid , '- ' , 18 , 0 );
83
+
84
+ return new UuidV3 (substr_replace ($ uuid , '- ' , 23 , 0 ));
78
85
}
79
86
80
87
final public static function v4 (): UuidV4
@@ -84,7 +91,14 @@ final public static function v4(): UuidV4
84
91
85
92
final public static function v5 (self $ namespace , string $ name ): UuidV5
86
93
{
87
- return new UuidV5 (uuid_generate_sha1 ($ namespace ->uid , $ name ));
94
+ // don't use uuid_generate_sha1(), some versions are buggy
95
+ $ uuid = substr (sha1 (hex2bin (str_replace ('- ' , '' , $ namespace ->uid )).$ name , true ), 0 , 16 );
96
+ $ uuid [8 ] = $ uuid [8 ] & "\x3F" | "\x80" ;
97
+ $ uuid = substr_replace (bin2hex ($ uuid ), '- ' , 8 , 0 );
98
+ $ uuid = substr_replace ($ uuid , '-5 ' , 13 , 1 );
99
+ $ uuid = substr_replace ($ uuid , '- ' , 18 , 0 );
100
+
101
+ return new UuidV5 (substr_replace ($ uuid , '- ' , 23 , 0 ));
88
102
}
89
103
90
104
final public static function v6 (): UuidV6
0 commit comments