Rev 193 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 194 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID utils for PHP |
4 | * UUID utils for PHP |
5 | * Copyright 2011-2019 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011-2019 Daniel Marschall, ViaThinkSoft |
6 | * Version 2019-11-01 |
6 | * Version 2019-11-04 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 303... | Line 303... | ||
303 | substr($y, 16, 4).'-'. |
303 | substr($y, 16, 4).'-'. |
304 | substr($y, 20, 12); |
304 | substr($y, 20, 12); |
305 | } |
305 | } |
306 | 306 | ||
307 | function is_uuid_oid($oid, $only_allow_root=false) { |
307 | function is_uuid_oid($oid, $only_allow_root=false) { |
308 | if ((substr($oid, 0, 5) != '2.25.') && (substr($oid, 0, 6) != '.2.25.')) return false; |
- | |
309 | - | ||
310 | if ($oid[0] == '.') $oid = substr($oid, 1); |
308 | if ($oid[0] == '.') $oid = substr($oid, 1); // remove leading dot |
311 | 309 | ||
312 | $ary = explode('.', $oid); |
310 | $ary = explode('.', $oid); |
313 | 311 | ||
314 | if ($only_allow_root) { |
312 | if ($only_allow_root) { |
315 | if (count($ary) != 3) return false; |
313 | if (count($ary) != 3) return false; |
316 | } |
314 | } |
317 | 315 | ||
- | 316 | if ($ary[0] != '2') return false; |
|
- | 317 | if ($ary[1] != '25') return false; |
|
318 | for ($i=2; $i<count($ary); $i++) { |
318 | for ($i=2; $i<count($ary); $i++) { |
319 | $v = $ary[$i]; |
319 | $v = $ary[$i]; |
320 | if (!is_numeric($v)) return false; |
320 | if (!is_numeric($v)) return false; |
- | 321 | if ($i == 2) { |
|
- | 322 | // Must be in the range of 128 bit UUID |
|
- | 323 | $test = gmp_init($v, 10); |
|
- | 324 | if (strlen(gmp_strval($test, 16)) > 32) return false; |
|
- | 325 | } |
|
321 | if ($v < 0) return false; |
326 | if ($v < 0) return false; |
322 | } |
327 | } |
323 | 328 | ||
324 | return true; |
329 | return true; |
325 | } |
330 | } |