Rev 23 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 27 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OID-Utilities for PHP |
4 | * OID-Utilities for PHP |
5 | * Copyright 2011-2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011-2022 Daniel Marschall, ViaThinkSoft |
6 | * Version 2021-09-23 |
6 | * Version 2022-01-07 |
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 331... | Line 331... | ||
331 | * Removes leading zeroes from an OID in dot notation. |
331 | * Removes leading zeroes from an OID in dot notation. |
332 | * @author Daniel Marschall, ViaThinkSoft |
332 | * @author Daniel Marschall, ViaThinkSoft |
333 | * @version 2015-08-17 |
333 | * @version 2015-08-17 |
334 | * @param string $oid<br/> |
334 | * @param string $oid<br/> |
335 | * An OID in dot notation. |
335 | * An OID in dot notation. |
336 | * @param boolean $leading_dot<br/> |
336 | * @param mixed $leading_dot<br/> |
337 | * true: The OID is valid, if it contains a leading dot.<br/> |
337 | * true: The OID is valid, if it contains a leading dot.<br/> |
338 | * false (default): The OID is valid, if it does not contain a leading dot. |
338 | * false (default): The OID is valid, if it does not contain a leading dot. |
339 | * 'auto: Allow both |
339 | * 'auto: Allow both |
340 | * @return string|false The OID without leading dots, or <code>false</code> if the OID is syntactically wrong. |
340 | * @return string|false The OID without leading dots, or <code>false</code> if the OID is syntactically wrong. |
341 | **/ |
341 | **/ |
342 | $oid_sanitize_cache = array(); |
- | |
343 | function sanitizeOID($oid, $leading_dot=false) { |
342 | function sanitizeOID($oid, $leading_dot=false) { |
- | 343 | static $oid_sanitize_cache = array(); |
|
- | 344 | ||
344 | if ($leading_dot) $leading_dot = substr($oid,0,1) == '.'; |
345 | if ($leading_dot) $leading_dot = substr($oid,0,1) == '.'; |
345 | 346 | ||
346 | // We are using a cache, since this function is used very often by OIDplus |
347 | // We are using a cache, since this function is used very often by OIDplus |
347 | global $oid_sanitize_cache; |
348 | global $oid_sanitize_cache; |
348 | $v = ($leading_dot ? 'T' : 'F').$oid; |
349 | $v = ($leading_dot ? 'T' : 'F').$oid; |
Line 360... | Line 361... | ||
360 | if (($leading_dot) && ($n == 0)) { |
361 | if (($leading_dot) && ($n == 0)) { |
361 | if ($a != '') return false; |
362 | if ($a != '') return false; |
362 | continue; |
363 | continue; |
363 | } |
364 | } |
364 | 365 | ||
365 | if (!ctype_digit($a)) return false; // does contain something other than digits |
366 | if (!preg_match('@^(\\d+)$@', $a, $m)) return false; // does contain something other than digits |
366 | 367 | ||
367 | // strike leading zeroes |
368 | // strike leading zeroes |
368 | $a = preg_replace("@^0+@", '', $a); |
369 | $a = preg_replace("@^0+@", '', $a); |
369 | if ($a == '') $a = 0; |
370 | if ($a == '') $a = 0; |
370 | 371 |