Rev 327 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 327 | Rev 386 | ||
---|---|---|---|
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-2020 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011-2020 Daniel Marschall, ViaThinkSoft |
6 | * Version 2020-06-11 |
6 | * Version 2020-09-12 |
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 40... | Line 40... | ||
40 | * @return (bool) true if the dot notation is valid. |
40 | * @return (bool) true if the dot notation is valid. |
41 | **/ |
41 | **/ |
42 | function oid_valid_dotnotation($oid, $allow_leading_zeroes=true, $allow_leading_dot=false, $min_len=0) { |
42 | function oid_valid_dotnotation($oid, $allow_leading_zeroes=true, $allow_leading_dot=false, $min_len=0) { |
43 | $regex = oid_validation_regex($allow_leading_zeroes, $allow_leading_dot, $min_len); |
43 | $regex = oid_validation_regex($allow_leading_zeroes, $allow_leading_dot, $min_len); |
44 | 44 | ||
- | 45 | $m = array(); |
|
45 | return preg_match($regex, $oid, $m) ? true : false; |
46 | return preg_match($regex, $oid, $m) ? true : false; |
46 | } |
47 | } |
47 | 48 | ||
48 | /** |
49 | /** |
49 | * Returns a full regular expression to validate an OID in dot-notation |
50 | * Returns a full regular expression to validate an OID in dot-notation |
Line 152... | Line 153... | ||
152 | * @return (array<string>) An array of OIDs in dot notation |
153 | * @return (array<string>) An array of OIDs in dot notation |
153 | **/ |
154 | **/ |
154 | function parse_oids($text, $min_len=2, $allow_leading_zeroes=false, $leading_dot_policy=OID_DOT_OPTIONAL, $requires_whitespace_delimiters=true) { |
155 | function parse_oids($text, $min_len=2, $allow_leading_zeroes=false, $leading_dot_policy=OID_DOT_OPTIONAL, $requires_whitespace_delimiters=true) { |
155 | $regex = oid_detection_regex($min_len, $allow_leading_zeroes, $leading_dot_policy, $requires_whitespace_delimiters); |
156 | $regex = oid_detection_regex($min_len, $allow_leading_zeroes, $leading_dot_policy, $requires_whitespace_delimiters); |
156 | 157 | ||
- | 158 | $matches = array(); |
|
157 | preg_match_all($regex, $text, $matches); |
159 | preg_match_all($regex, $text, $matches); |
158 | return $matches[1]; |
160 | return $matches[1]; |
159 | } |
161 | } |
160 | 162 | ||
161 | /** |
163 | /** |
Line 269... | Line 271... | ||
269 | * An array of OIDs in dot notation.<br /> |
271 | * An array of OIDs in dot notation.<br /> |
270 | * This array will be changed by this method. |
272 | * This array will be changed by this method. |
271 | * @param $output_with_leading_dot (bool)<br /> |
273 | * @param $output_with_leading_dot (bool)<br /> |
272 | * true: The array will be normalized to OIDs with a leading dot. |
274 | * true: The array will be normalized to OIDs with a leading dot. |
273 | * false: The array will be normalized to OIDs without a leading dot. (default) |
275 | * false: The array will be normalized to OIDs without a leading dot. (default) |
274 | * @return Nothing |
- | |
275 | **/ |
276 | **/ |
276 | function oidSort(&$ary, $output_with_leading_dot=false) { |
277 | function oidSort(&$ary, $output_with_leading_dot=false) { |
277 | $out = array(); |
278 | $out = array(); |
278 | 279 | ||
279 | $none = $output_with_leading_dot ? '.' : ''; |
280 | $none = $output_with_leading_dot ? '.' : ''; |
Line 575... | Line 576... | ||
575 | } |
576 | } |
576 | 577 | ||
577 | function iri_arc_valid($arc, $allow_numeric=true) { |
578 | function iri_arc_valid($arc, $allow_numeric=true) { |
578 | if ($arc == '') return false; |
579 | if ($arc == '') return false; |
579 | 580 | ||
- | 581 | $m = array(); |
|
580 | if ($allow_numeric && preg_match('@^(\\d+)$@', $arc, $m)) return true; # numeric arc |
582 | if ($allow_numeric && preg_match('@^(\\d+)$@', $arc, $m)) return true; # numeric arc |
581 | 583 | ||
582 | // Question: Should we strip RTL/LTR characters? |
584 | // Question: Should we strip RTL/LTR characters? |
583 | 585 | ||
584 | if (mb_substr($arc, 2, 2) == '--') return false; // see Rec. ITU-T X.660, clause 7.5.4 |
586 | if (mb_substr($arc, 2, 2) == '--') return false; // see Rec. ITU-T X.660, clause 7.5.4 |
Line 807... | Line 809... | ||
807 | **/ |
809 | **/ |
808 | function asn1_to_dot($asn) { |
810 | function asn1_to_dot($asn) { |
809 | $standardized = asn1_get_standardized_array(); |
811 | $standardized = asn1_get_standardized_array(); |
810 | 812 | ||
811 | // Clean up |
813 | // Clean up |
- | 814 | $count = -1; |
|
812 | $asn = preg_replace('@^\\{(.+)\\}$@', '\\1', $asn, -1, $count); |
815 | $asn = preg_replace('@^\\{(.+)\\}$@', '\\1', $asn, -1, $count); |
813 | if ($count == 0) return false; // { and } are required. The asn.1 path will NOT be trimmed by this function |
816 | if ($count == 0) return false; // { and } are required. The asn.1 path will NOT be trimmed by this function |
814 | 817 | ||
815 | // If identifier is set, apply it (no check if it overrides a standardized identifier) |
818 | // If identifier is set, apply it (no check if it overrides a standardized identifier) |
816 | $asn = preg_replace('|\s*([a-z][a-zA-Z0-9-]*)\s*\((\d+)\)|', ' \\2', $asn); |
819 | $asn = preg_replace('|\s*([a-z][a-zA-Z0-9-]*)\s*\((\d+)\)|', ' \\2', $asn); |
Line 830... | Line 833... | ||
830 | // -> every arc must be resolved |
833 | // -> every arc must be resolved |
831 | // -> numeric arcs must not have a leading zero |
834 | // -> numeric arcs must not have a leading zero |
832 | // -> invalid stuff will be recognized, e.g. a "(1)" without an identifier in front of it |
835 | // -> invalid stuff will be recognized, e.g. a "(1)" without an identifier in front of it |
833 | $ary = explode('.', $asn); |
836 | $ary = explode('.', $asn); |
834 | foreach ($ary as $a) { |
837 | foreach ($ary as $a) { |
- | 838 | $m = array(); |
|
835 | if (!preg_match('@^(0|([1-9]\\d*))$@', $a, $m)) return false; |
839 | if (!preg_match('@^(0|([1-9]\\d*))$@', $a, $m)) return false; |
836 | } |
840 | } |
837 | 841 | ||
838 | return $asn; |
842 | return $asn; |
839 | } |
843 | } |