Subversion Repositories oidplus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
226 daniel-mar 1
<?php
2
 
3
# if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.');
4
# if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.');
5
 
6
require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php';
7
require_once __DIR__ . '/../../includes/uuid_utils.inc.php';
8
 
9
class ASN1SearchFieldExtender implements OIDPlusFieldExtenders {
10
        private static function detectDirectAsn1Notation($x, &$xx, $oidplusobj) {
11
                # At your root, you can define your own asn1-notation
12
                # FUT: as alternative, we could have "invisible" OIDs (cannot be queried) which give information about non-root OIDs
13
                $asn1path = $oidplusobj->getValuesOf($x, 'asn1-notation', true);
14
                if (count($asn1path) > 0) {
15
                        $oidplusobj->stripAttribs($x, 'asn1-notation');
16
 
17
                        $asn1path = trim($asn1path[0]);
18
                        if (!asn1_path_valid($asn1path)) {
19
                                throw new VolcanoException("ASN.1 notation '$asn1path' is invalid"); # TODO: source?
20
                        }
21
                        $asn1path = preg_replace('@^\\s*\\{(.+)\\}\\s*$@', '\\1', $asn1path);
22
 
23
                        $asn1path_neu = '';
24
                        $asn1path = str_replace("\t", ' ', $asn1path);
25
                        $z = explode(' ', $asn1path);
26
                        foreach ($z as $za) {
27
                                $za = trim($za);
28
                                if ($za == '') continue;
29
                                $asn1path_neu .= "$za ";
30
                        }
31
                        $asn1path_neu = trim($asn1path_neu);
32
 
33
                        $xx[] = $asn1path_neu;
34
                        return true;
35
                }
36
 
37
                return false;
38
        }
39
 
40
        public static function processOID($oid, &$out, &$oidplusobj) {
41
                $xx = array();
42
 
43
                $x = $oid;
44
                do {
45
                        $toparc = oid_toparc($x);
46
 
47
                        if (self::detectDirectAsn1Notation($x, $xx, $oidplusobj)) break;
48
 
49
                        $ids = $oidplusobj->getIdentifiers($x);
50
 
51
                        $id = null;
52
                        foreach ($ids as $m) {
53
                                if (oid_id_is_valid($m)) {
54
                                        $id = $m;
55
                                        break;
56
                                }
57
                        }
58
 
59
                        if (is_null($id)) {
60
                                $xx[] = $toparc;
61
                        } else {
62
                                $xx[]  = "$id($toparc)";
63
                        }
64
                } while (($x = oid_up($x)) != '.');
65
 
66
                $xx = array_reverse($xx);
67
 
68
                if (count($xx) > 0) {
69
                        $asn1path = '{ '.implode(' ', $xx).' }';
70
 
71
                        if (!asn1_path_valid($asn1path)) {
72
                                throw new VolcanoException("ASN.1 notation '$asn1path' is invalid"); # TODO: source?
73
                        }
74
 
75
                        $out[] = "asn1-notation: $asn1path";
76
                }
77
        }
78
}
79
 
80
require_once __DIR__ . '/../../core/2_OIDPlus.class.php';
81
OIDPlus::registerFieldExtender(new ASN1SearchFieldExtender());