Subversion Repositories oidplus

Rev

Rev 1261 | Rev 1294 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1261 Rev 1293
Line 33... Line 33...
33
        public static function getObjectTypeClassName(): string {
33
        public static function getObjectTypeClassName(): string {
34
                return OIDplusMac::class;
34
                return OIDplusMac::class;
35
        }
35
        }
36
 
36
 
37
        /**
37
        /**
38
         * @param string $actionID
-
 
39
         * @param array $params
38
         * @param array $params
40
         * @return array
39
         * @return array
41
         * @throws OIDplusException
40
         * @throws OIDplusException
42
         */
41
         */
43
        public function action(string $actionID, array $params): array {
42
        private function action_GenerateAAI(array $params): array {
44
                if ($actionID == 'generate_aai') {
-
 
45
                        _CheckParamExists($params, 'aai_bits');
43
                _CheckParamExists($params, 'aai_bits');
46
                        _CheckParamExists($params, 'aai_multicast');
44
                _CheckParamExists($params, 'aai_multicast');
47
 
45
 
48
                        if (($params['aai_bits'] != '48') && ($params['aai_bits'] != '64')) {
46
                if (($params['aai_bits'] != '48') && ($params['aai_bits'] != '64')) {
49
                                throw new OIDplusException(_L("Invalid bit amount"));
47
                        throw new OIDplusException(_L("Invalid bit amount"));
50
                        }
48
                }
51
 
49
 
52
                        $aai = '';
50
                $aai = '';
53
                        for ($i=0; $i<$params['aai_bits']/4; $i++) {
51
                for ($i=0; $i<$params['aai_bits']/4; $i++) {
54
                                try {
52
                        try {
55
                                        $aai .= dechex(random_int(0, 15));
53
                                $aai .= dechex(random_int(0, 15));
56
                                } catch (\Exception $e) {
54
                        } catch (\Exception $e) {
57
                                        $aai .= dechex(mt_rand(0, 15));
55
                                $aai .= dechex(mt_rand(0, 15));
58
                                }
-
 
59
                        }
56
                        }
-
 
57
                }
60
 
58
 
61
                        if ($params['aai_multicast'] == 'true') {
59
                if ($params['aai_multicast'] == 'true') {
62
                                $aai[1] = '3';
60
                        $aai[1] = '3';
63
                        } else {
61
                } else {
64
                                $aai[1] = '2';
62
                        $aai[1] = '2';
65
                        }
63
                }
66
 
64
 
67
                        $aai = strtoupper($aai);
65
                $aai = strtoupper($aai);
68
                        $aai = rtrim(chunk_split($aai, 2, '-'), '-');
66
                $aai = rtrim(chunk_split($aai, 2, '-'), '-');
69
 
67
 
70
                        return array("status" => 0, "aai" => $aai);
68
                return array("status" => 0, "aai" => $aai);
-
 
69
        }
-
 
70
 
-
 
71
        /**
-
 
72
         * @param string $actionID
-
 
73
         * @param array $params
-
 
74
         * @return array
-
 
75
         * @throws OIDplusException
-
 
76
         */
-
 
77
        public function action(string $actionID, array $params): array {
-
 
78
                if ($actionID == 'generate_aai') {
-
 
79
                        return $this->action_GenerateAAI($params);
71
                } else {
80
                } else {
72
                        return parent::action($actionID, $params);
81
                        return parent::action($actionID, $params);
73
                }
82
                }
74
        }
83
        }
75
 
84