@@ -141,6 +141,9 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | |
144 | +/** |
|
145 | + * @param string $setting |
|
146 | + */ |
|
144 | 147 | function getSettingValue($setting) { |
145 | 148 | |
146 | 149 | // get default language |
@@ -1999,6 +2002,9 @@ discard block |
||
1999 | 2002 | } |
2000 | 2003 | } |
2001 | 2004 | |
2005 | +/** |
|
2006 | + * @param string $type |
|
2007 | + */ |
|
2002 | 2008 | function rest_error ($type,$detail = 'N/A') { |
2003 | 2009 | switch ($type) { |
2004 | 2010 | case 'APIKEY': |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | 'renewal_period' => $params[3], |
973 | 973 | 'bloquer_creation' => '0', |
974 | 974 | 'bloquer_modification' => '0' |
975 | - ) |
|
975 | + ) |
|
976 | 976 | ); |
977 | 977 | $newId = DB::insertId(); |
978 | 978 | |
@@ -1790,7 +1790,7 @@ discard block |
||
1790 | 1790 | 'intitule' => "f".$array_category[$i], |
1791 | 1791 | 'valeur' => $folder->id.', '.$folder->parent_id.', '. |
1792 | 1792 | $folder->title.', '.$folder->nleft.', '.$folder->nright.', '. $folder->nlevel.', 0, 0, 0, 0' |
1793 | - ) |
|
1793 | + ) |
|
1794 | 1794 | ); |
1795 | 1795 | //delete folder |
1796 | 1796 | DB::delete(prefix_table("nested_tree"), "id = %i", $folder->id); |
@@ -19,17 +19,17 @@ discard block |
||
19 | 19 | require_once "../sources/main.functions.php"; |
20 | 20 | |
21 | 21 | function get_ip() { |
22 | - if ( function_exists( 'apache_request_headers' ) ) { |
|
22 | + if (function_exists('apache_request_headers')) { |
|
23 | 23 | $headers = apache_request_headers(); |
24 | 24 | } else { |
25 | 25 | $headers = $_SERVER; |
26 | 26 | } |
27 | - if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP ) ) { |
|
27 | + if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP)) { |
|
28 | 28 | $the_ip = $headers['X-Forwarded-For']; |
29 | - } elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP ) ) { |
|
29 | + } elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) { |
|
30 | 30 | $the_ip = $headers['HTTP_X_FORWARDED_FOR']; |
31 | 31 | } else { |
32 | - $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); |
|
32 | + $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); |
|
33 | 33 | } |
34 | 34 | return $the_ip; |
35 | 35 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return $response; |
91 | 91 | } |
92 | 92 | |
93 | -function rest_head () { |
|
93 | +function rest_head() { |
|
94 | 94 | header('HTTP/1.1 402 Payment Required'); |
95 | 95 | } |
96 | 96 | |
@@ -153,32 +153,32 @@ discard block |
||
153 | 153 | return $set['valeur']; |
154 | 154 | } |
155 | 155 | |
156 | -function rest_delete () { |
|
157 | - if(!@count($GLOBALS['request'])==0){ |
|
156 | +function rest_delete() { |
|
157 | + if (!@count($GLOBALS['request']) == 0) { |
|
158 | 158 | $request_uri = $GLOBALS['_SERVER']['REQUEST_URI']; |
159 | - preg_match('/\/api(\/index.php|)\/(.*)\?apikey=(.*)/',$request_uri,$matches); |
|
159 | + preg_match('/\/api(\/index.php|)\/(.*)\?apikey=(.*)/', $request_uri, $matches); |
|
160 | 160 | if (count($matches) == 0) { |
161 | - rest_error ('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
161 | + rest_error('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
162 | 162 | } |
163 | - $GLOBALS['request'] = explode('/',$matches[2]); |
|
163 | + $GLOBALS['request'] = explode('/', $matches[2]); |
|
164 | 164 | } |
165 | - if(apikey_checker($GLOBALS['apikey'])) { |
|
165 | + if (apikey_checker($GLOBALS['apikey'])) { |
|
166 | 166 | global $server, $user, $pass, $database, $pre, $link; |
167 | 167 | include "../sources/main.functions.php"; |
168 | 168 | teampass_connect(); |
169 | 169 | $category_query = ""; |
170 | 170 | |
171 | 171 | if ($GLOBALS['request'][0] == "write") { |
172 | - if($GLOBALS['request'][1] == "category") { |
|
173 | - $array_category = explode(';',$GLOBALS['request'][2]); |
|
172 | + if ($GLOBALS['request'][1] == "category") { |
|
173 | + $array_category = explode(';', $GLOBALS['request'][2]); |
|
174 | 174 | |
175 | - foreach($array_category as $category) { |
|
176 | - if(!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category,$result)) { |
|
175 | + foreach ($array_category as $category) { |
|
176 | + if (!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category, $result)) { |
|
177 | 177 | rest_error('CATEGORY_MALFORMED'); |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - if(count($array_category) > 1 && count($array_category) < 5) { |
|
181 | + if (count($array_category) > 1 && count($array_category) < 5) { |
|
182 | 182 | for ($i = count($array_category); $i > 0; $i--) { |
183 | 183 | $slot = $i - 1; |
184 | 184 | if (!$slot) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } elseif (count($array_category) == 1) { |
192 | 192 | $category_query = "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[0]."' AND parent_id = 0"; |
193 | 193 | } else { |
194 | - rest_error ('NO_CATEGORY'); |
|
194 | + rest_error('NO_CATEGORY'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | // Delete items which in category |
@@ -203,29 +203,29 @@ discard block |
||
203 | 203 | |
204 | 204 | $json['type'] = 'category'; |
205 | 205 | $json['category'] = $GLOBALS['request'][2]; |
206 | - if($response) { |
|
206 | + if ($response) { |
|
207 | 207 | $json['status'] = 'OK'; |
208 | 208 | } else { |
209 | 209 | $json['status'] = 'KO'; |
210 | 210 | } |
211 | 211 | |
212 | - } elseif($GLOBALS['request'][1] == "item") { |
|
213 | - $array_category = explode(';',$GLOBALS['request'][2]); |
|
212 | + } elseif ($GLOBALS['request'][1] == "item") { |
|
213 | + $array_category = explode(';', $GLOBALS['request'][2]); |
|
214 | 214 | $item = $GLOBALS['request'][3]; |
215 | 215 | |
216 | - foreach($array_category as $category) { |
|
217 | - if(!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category,$result)) { |
|
216 | + foreach ($array_category as $category) { |
|
217 | + if (!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category, $result)) { |
|
218 | 218 | rest_error('CATEGORY_MALFORMED'); |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - if(!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $item,$result)) { |
|
222 | + if (!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $item, $result)) { |
|
223 | 223 | rest_error('ITEM_MALFORMED'); |
224 | 224 | } elseif (empty($item) || count($array_category) == 0) { |
225 | 225 | rest_error('MALFORMED'); |
226 | 226 | } |
227 | 227 | |
228 | - if(count($array_category) > 1 && count($array_category) < 5) { |
|
228 | + if (count($array_category) > 1 && count($array_category) < 5) { |
|
229 | 229 | for ($i = count($array_category); $i > 0; $i--) { |
230 | 230 | $slot = $i - 1; |
231 | 231 | if (!$slot) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | } elseif (count($array_category) == 1) { |
239 | 239 | $category_query = "select id from ".prefix_table("nested_tree")." where title LIKE '".$array_category[0]."' AND parent_id = 0"; |
240 | 240 | } else { |
241 | - rest_error ('NO_CATEGORY'); |
|
241 | + rest_error('NO_CATEGORY'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Delete item |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $json['type'] = 'item'; |
247 | 247 | $json['item'] = $item; |
248 | 248 | $json['category'] = $GLOBALS['request'][2]; |
249 | - if($response) { |
|
249 | + if ($response) { |
|
250 | 250 | $json['status'] = 'OK'; |
251 | 251 | } else { |
252 | 252 | $json['status'] = 'KO'; |
@@ -256,27 +256,27 @@ discard block |
||
256 | 256 | if ($json) { |
257 | 257 | echo json_encode($json); |
258 | 258 | } else { |
259 | - rest_error ('EMPTY'); |
|
259 | + rest_error('EMPTY'); |
|
260 | 260 | } |
261 | 261 | } else { |
262 | - rest_error ('METHOD'); |
|
262 | + rest_error('METHOD'); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | -function rest_get () { |
|
267 | +function rest_get() { |
|
268 | 268 | global $api_version; |
269 | 269 | |
270 | - if(!@count($GLOBALS['request'])==0){ |
|
270 | + if (!@count($GLOBALS['request']) == 0) { |
|
271 | 271 | $request_uri = $GLOBALS['_SERVER']['REQUEST_URI']; |
272 | 272 | preg_match('/\/api(\/index.php|)\/(.*)\?apikey=(.*)/', $request_uri, $matches); |
273 | 273 | if (count($matches) == 0) { |
274 | - rest_error ('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
274 | + rest_error('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
275 | 275 | } |
276 | - $GLOBALS['request'] = explode('/',$matches[2]); |
|
276 | + $GLOBALS['request'] = explode('/', $matches[2]); |
|
277 | 277 | } |
278 | 278 | |
279 | - if(apikey_checker($GLOBALS['apikey'])) { |
|
279 | + if (apikey_checker($GLOBALS['apikey'])) { |
|
280 | 280 | global $server, $user, $pass, $database, $pre, $link; |
281 | 281 | teampass_connect(); |
282 | 282 | $category_query = ""; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | ); |
291 | 291 | |
292 | 292 | if ($GLOBALS['request'][0] == "read") { |
293 | - if($GLOBALS['request'][1] == "folder") { |
|
293 | + if ($GLOBALS['request'][1] == "folder") { |
|
294 | 294 | /* |
295 | 295 | * READ FOLDERS |
296 | 296 | */ |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $tree = new Tree\NestedTree\NestedTree(prefix_table("nested_tree"), 'id', 'parent_id', 'title'); |
304 | 304 | |
305 | 305 | // get ids |
306 | - if (strpos($GLOBALS['request'][2],";") > 0) { |
|
306 | + if (strpos($GLOBALS['request'][2], ";") > 0) { |
|
307 | 307 | $condition = "id_tree IN %ls"; |
308 | 308 | $condition_value = explode(';', $GLOBALS['request'][2]); |
309 | 309 | } else { |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $x++; |
351 | 351 | } |
352 | 352 | } |
353 | - else if($GLOBALS['request'][1] == "userpw") { |
|
353 | + else if ($GLOBALS['request'][1] == "userpw") { |
|
354 | 354 | /* |
355 | 355 | * READ USER ITEMS |
356 | 356 | */ |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | |
365 | 365 | // about the user |
366 | 366 | $username = $GLOBALS['request'][2]; |
367 | - if(strcmp($username,"admin")==0) { |
|
367 | + if (strcmp($username, "admin") == 0) { |
|
368 | 368 | // forbid admin access |
369 | 369 | } |
370 | 370 | $response = DB::query("SELECT fonction_id FROM ".prefix_table("users")." WHERE login='".$username."'"); |
@@ -383,8 +383,8 @@ discard block |
||
383 | 383 | foreach ($response as $data) |
384 | 384 | { |
385 | 385 | $folder_id = $data['folder_id']; |
386 | - if(!array_key_exists($folder_id,$folder_arr)) { |
|
387 | - array_push($folder_arr,$folder_id); |
|
386 | + if (!array_key_exists($folder_id, $folder_arr)) { |
|
387 | + array_push($folder_arr, $folder_id); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
@@ -435,14 +435,14 @@ discard block |
||
435 | 435 | $x++; |
436 | 436 | } |
437 | 437 | } |
438 | - else if($GLOBALS['request'][1] == "userfolders") { |
|
438 | + else if ($GLOBALS['request'][1] == "userfolders") { |
|
439 | 439 | /* |
440 | 440 | * READ USER FOLDERS |
441 | 441 | * Sends back a list of folders |
442 | 442 | */ |
443 | 443 | $json = ""; |
444 | 444 | $username = $GLOBALS['request'][2]; |
445 | - if(strcmp($username,"admin")==0) { |
|
445 | + if (strcmp($username, "admin") == 0) { |
|
446 | 446 | // forbid admin access |
447 | 447 | } |
448 | 448 | $response = DB::query("SELECT fonction_id FROM ".prefix_table("users")." WHERE login='".$username."'"); |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | foreach ($response as $data) |
464 | 464 | { |
465 | 465 | $folder_id = $data['folder_id']; |
466 | - if(!array_key_exists($folder_id,$folder_arr)) { |
|
467 | - array_push($folder_arr,$folder_id); |
|
466 | + if (!array_key_exists($folder_id, $folder_arr)) { |
|
467 | + array_push($folder_arr, $folder_id); |
|
468 | 468 | |
469 | 469 | $response2 = DB::queryFirstRow("SELECT title, nlevel FROM ".prefix_table("nested_tree")." WHERE id='".$folder_id."'"); |
470 | 470 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | } |
480 | 480 | } |
481 | 481 | } |
482 | - elseif($GLOBALS['request'][1] == "items") { |
|
482 | + elseif ($GLOBALS['request'][1] == "items") { |
|
483 | 483 | /* |
484 | 484 | * READ ITEMS asked |
485 | 485 | */ |
@@ -492,16 +492,16 @@ discard block |
||
492 | 492 | $tree = new Tree\NestedTree\NestedTree(prefix_table("nested_tree"), 'id', 'parent_id', 'title'); |
493 | 493 | |
494 | 494 | // get parameters |
495 | - $array_items = explode(';',$GLOBALS['request'][2]); |
|
495 | + $array_items = explode(';', $GLOBALS['request'][2]); |
|
496 | 496 | |
497 | 497 | // check if not empty |
498 | 498 | if (count($array_items) == 0) { |
499 | - rest_error ('NO_ITEM'); |
|
499 | + rest_error('NO_ITEM'); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | // only accepts numeric |
503 | - foreach($array_items as $item) { |
|
504 | - if(!is_numeric($item)) { |
|
503 | + foreach ($array_items as $item) { |
|
504 | + if (!is_numeric($item)) { |
|
505 | 505 | rest_error('ITEM_MALFORMED'); |
506 | 506 | } |
507 | 507 | } |
@@ -544,10 +544,10 @@ discard block |
||
544 | 544 | if (isset($json) && $json) { |
545 | 545 | echo json_encode($json); |
546 | 546 | } else { |
547 | - rest_error ('EMPTY'); |
|
547 | + rest_error('EMPTY'); |
|
548 | 548 | } |
549 | 549 | } elseif ($GLOBALS['request'][0] == "find") { |
550 | - if($GLOBALS['request'][1] == "item") { |
|
550 | + if ($GLOBALS['request'][1] == "item") { |
|
551 | 551 | /* |
552 | 552 | * FIND ITEMS in FOLDERS |
553 | 553 | */ |
@@ -562,20 +562,20 @@ discard block |
||
562 | 562 | // get parameters |
563 | 563 | $array_category = explode(';', $GLOBALS['request'][2]); |
564 | 564 | $item = $GLOBALS['request'][3]; |
565 | - foreach($array_category as $category) { |
|
566 | - if(!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category,$result)) { |
|
565 | + foreach ($array_category as $category) { |
|
566 | + if (!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $category, $result)) { |
|
567 | 567 | rest_error('CATEGORY_MALFORMED'); |
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | - if(!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $item, $result)) { |
|
571 | + if (!preg_match_all("/^([\w\:\'\-\sà áâãäåçèéêëìĂîïðòóôõöùúûüýÿ]+)$/i", $item, $result)) { |
|
572 | 572 | rest_error('ITEM_MALFORMED'); |
573 | 573 | } elseif (empty($item) || count($array_category) == 0) { |
574 | 574 | rest_error('MALFORMED'); |
575 | 575 | } |
576 | 576 | |
577 | - if(count($array_category) === 0) { |
|
578 | - rest_error ('NO_CATEGORY'); |
|
577 | + if (count($array_category) === 0) { |
|
578 | + rest_error('NO_CATEGORY'); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | DB::debugMode(false); |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | if (isset($json) && $json) { |
622 | 622 | echo json_encode($json); |
623 | 623 | } else { |
624 | - rest_error ('EMPTY'); |
|
624 | + rest_error('EMPTY'); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | } elseif ($GLOBALS['request'][0] == "add") { |
628 | - if($GLOBALS['request'][1] == "item") { |
|
628 | + if ($GLOBALS['request'][1] == "item") { |
|
629 | 629 | // get sent parameters |
630 | 630 | $params = explode(';', base64_decode($GLOBALS['request'][2])); |
631 | 631 | if (count($params) != 9) { |
632 | - rest_error ('ITEMBADDEFINITION'); |
|
632 | + rest_error('ITEMBADDEFINITION'); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | $item_label = $params[0]; |
@@ -646,14 +646,14 @@ discard block |
||
646 | 646 | if (!empty($item_label) && !empty($item_pwd) && !empty($item_folder_id)) { |
647 | 647 | // Check length |
648 | 648 | if (strlen($item_pwd) > 50) { |
649 | - rest_error ('PASSWORDTOOLONG'); |
|
649 | + rest_error('PASSWORDTOOLONG'); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | // Check Folder ID |
653 | 653 | DB::query("SELECT * FROM ".prefix_table("nested_tree")." WHERE id = %i", $item_folder_id); |
654 | 654 | $counter = DB::count(); |
655 | 655 | if ($counter == 0) { |
656 | - rest_error ('NOSUCHFOLDER'); |
|
656 | + rest_error('NOSUCHFOLDER'); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // check if element doesn't already exist |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $itemExists = 1; |
666 | 666 | // prevent the error if the label already exists |
667 | 667 | // so lets just add the time() as a random factor |
668 | - $item_label .= " (" . time() .")"; |
|
668 | + $item_label .= " (".time().")"; |
|
669 | 669 | } else { |
670 | 670 | $itemExists = 0; |
671 | 671 | } |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | "encrypt" |
680 | 680 | ); |
681 | 681 | if (empty($encrypt['string'])) { |
682 | - rest_error ('PASSWORDEMPTY'); |
|
682 | + rest_error('PASSWORDEMPTY'); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // ADD item |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | |
718 | 718 | // Add tags |
719 | 719 | $tags = explode(' ', $item_tags); |
720 | - foreach ((array)$tags as $tag) { |
|
720 | + foreach ((array) $tags as $tag) { |
|
721 | 721 | if (!empty($tag)) { |
722 | 722 | DB::insert( |
723 | 723 | prefix_table("tags"), |
@@ -750,14 +750,14 @@ discard block |
||
750 | 750 | ); |
751 | 751 | |
752 | 752 | echo '{"status":"item added" , "new_item_id" : "'.$newID.'"}'; |
753 | - } catch(PDOException $ex) { |
|
754 | - echo '<br />' . $ex->getMessage(); |
|
753 | + } catch (PDOException $ex) { |
|
754 | + echo '<br />'.$ex->getMessage(); |
|
755 | 755 | } |
756 | 756 | } else { |
757 | - rest_error ('ITEMEXISTS'); |
|
757 | + rest_error('ITEMEXISTS'); |
|
758 | 758 | } |
759 | 759 | } else { |
760 | - rest_error ('ITEMMISSINGDATA'); |
|
760 | + rest_error('ITEMMISSINGDATA'); |
|
761 | 761 | } |
762 | 762 | } |
763 | 763 | /* |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | * Example: /api/index.php/add/user/U4;Nils;Laumaille;test;[email protected];Users;0;Managers,Users;0;1;1?apikey=sae6iekahxiseL3viShoo0chahc1ievei8aequi |
772 | 772 | * |
773 | 773 | */ |
774 | - elseif($GLOBALS['request'][1] == "user") { |
|
774 | + elseif ($GLOBALS['request'][1] == "user") { |
|
775 | 775 | |
776 | 776 | // get user definition |
777 | 777 | $array_user = explode(';', base64_decode($GLOBALS['request'][2])); |
778 | 778 | if (count($array_user) != 11) { |
779 | - rest_error ('USERBADDEFINITION'); |
|
779 | + rest_error('USERBADDEFINITION'); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | $login = $array_user[0]; |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | |
794 | 794 | // Empty user |
795 | 795 | if (mysqli_escape_string($link, htmlspecialchars_decode($login)) == "") { |
796 | - rest_error ('USERLOGINEMPTY'); |
|
796 | + rest_error('USERLOGINEMPTY'); |
|
797 | 797 | } |
798 | 798 | // Check if user already exists |
799 | 799 | $data = DB::query( |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | $role |
828 | 828 | ); |
829 | 829 | if (empty($rolesList)) $rolesList = $tmp['id']; |
830 | - else $rolesList .= ";" . $tmp['id']; |
|
830 | + else $rolesList .= ";".$tmp['id']; |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | // Add user in DB |
@@ -882,18 +882,18 @@ discard block |
||
882 | 882 | logEvents('user_mngt', 'at_user_added', 'api - '.$GLOBALS['apikey'], $new_user_id, ""); |
883 | 883 | |
884 | 884 | echo '{"status":"user added"}'; |
885 | - } catch(PDOException $ex) { |
|
886 | - echo '<br />' . $ex->getMessage(); |
|
885 | + } catch (PDOException $ex) { |
|
886 | + echo '<br />'.$ex->getMessage(); |
|
887 | 887 | } |
888 | 888 | } else { |
889 | - rest_error ('USERALREADYEXISTS'); |
|
889 | + rest_error('USERALREADYEXISTS'); |
|
890 | 890 | } |
891 | 891 | } |
892 | 892 | /* |
893 | 893 | * ADDING A FOLDER |
894 | 894 | * <url to teampass>/api/index.php/add/folder/<title>;<complexity_level>;<parent_id>;<renewal_period>;<personal>?apikey=<valid api key> |
895 | 895 | */ |
896 | - elseif($GLOBALS['request'][1] == "folder") { |
|
896 | + elseif ($GLOBALS['request'][1] == "folder") { |
|
897 | 897 | if (!empty($GLOBALS['request'][2])) { |
898 | 898 | // get sent parameters |
899 | 899 | $params = explode(';', base64_decode($GLOBALS['request'][2])); |
@@ -902,17 +902,17 @@ discard block |
||
902 | 902 | if (empty($params[3])) $params[3] = 0; |
903 | 903 | if (empty($params[4])) $params[4] = 0; |
904 | 904 | if ($params[2] < 0) { |
905 | - rest_error ('NO_DATA_EXIST'); |
|
905 | + rest_error('NO_DATA_EXIST'); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | //Check if title doesn't contains html codes |
909 | 909 | if (preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $params[0], $out)) { |
910 | - rest_error ('HTML_CODES_NOT_ALLOWED'); |
|
910 | + rest_error('HTML_CODES_NOT_ALLOWED'); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | // check if title is numeric |
914 | 914 | if (is_numeric($params[0]) === true) { |
915 | - rest_error ('TITLE_ONLY_WITH_NUMBERS'); |
|
915 | + rest_error('TITLE_ONLY_WITH_NUMBERS'); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | //Check if duplicate folders name are allowed |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | DB::query("SELECT * FROM ".prefix_table("nested_tree")." WHERE title = %s", $params[0]); |
929 | 929 | $counter = DB::count(); |
930 | 930 | if ($counter != 0) { |
931 | - rest_error ('ALREADY_EXISTS'); |
|
931 | + rest_error('ALREADY_EXISTS'); |
|
932 | 932 | } |
933 | 933 | } |
934 | 934 | |
@@ -957,7 +957,7 @@ discard block |
||
957 | 957 | "complex" |
958 | 958 | ); |
959 | 959 | if (intval($params[1]) < intval($data['valeur'])) { |
960 | - rest_error ('COMPLEXICITY_LEVEL_NOT_REACHED'); |
|
960 | + rest_error('COMPLEXICITY_LEVEL_NOT_REACHED'); |
|
961 | 961 | } |
962 | 962 | } |
963 | 963 | |
@@ -987,11 +987,11 @@ discard block |
||
987 | 987 | ); |
988 | 988 | |
989 | 989 | echo '{"status":"folder created" , "new_folder_id":"'.$newId.'"}'; |
990 | - } catch(PDOException $ex) { |
|
991 | - echo '<br />' . $ex->getMessage(); |
|
990 | + } catch (PDOException $ex) { |
|
991 | + echo '<br />'.$ex->getMessage(); |
|
992 | 992 | } |
993 | 993 | } else { |
994 | - rest_error ('NO_DATA_EXIST'); |
|
994 | + rest_error('NO_DATA_EXIST'); |
|
995 | 995 | } |
996 | 996 | } else { |
997 | 997 | rest_error('SET_NO_DATA'); |
@@ -1012,14 +1012,14 @@ discard block |
||
1012 | 1012 | if (!empty($params[0]) && !empty($params[1]) && !empty($params[3])) { |
1013 | 1013 | // Check length |
1014 | 1014 | if (strlen($params[1]) > 50) { |
1015 | - rest_error ('PASSWORDTOOLONG'); |
|
1015 | + rest_error('PASSWORDTOOLONG'); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | // Check Folder ID |
1019 | 1019 | DB::query("SELECT * FROM ".prefix_table("nested_tree")." WHERE id = %i", $params[3]); |
1020 | 1020 | $counter = DB::count(); |
1021 | 1021 | if ($counter == 0) { |
1022 | - rest_error ('NOSUCHFOLDER'); |
|
1022 | + rest_error('NOSUCHFOLDER'); |
|
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | // check if item exists |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | "encrypt" |
1037 | 1037 | ); |
1038 | 1038 | if (empty($encrypt['string'])) { |
1039 | - rest_error ('PASSWORDEMPTY'); |
|
1039 | + rest_error('PASSWORDEMPTY'); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | // ADD item |
@@ -1071,7 +1071,7 @@ discard block |
||
1071 | 1071 | |
1072 | 1072 | // Add tags |
1073 | 1073 | $tags = explode(' ', $params[7]); |
1074 | - foreach ((array)$tags as $tag) { |
|
1074 | + foreach ((array) $tags as $tag) { |
|
1075 | 1075 | if (!empty($tag)) { |
1076 | 1076 | // check if already exists |
1077 | 1077 | DB::query( |
@@ -1114,14 +1114,14 @@ discard block |
||
1114 | 1114 | ); |
1115 | 1115 | |
1116 | 1116 | echo '{"status":"item updated"}'; |
1117 | - } catch(PDOException $ex) { |
|
1118 | - echo '<br />' . $ex->getMessage(); |
|
1117 | + } catch (PDOException $ex) { |
|
1118 | + echo '<br />'.$ex->getMessage(); |
|
1119 | 1119 | } |
1120 | 1120 | } else { |
1121 | - rest_error ('NO_DATA_EXIST'); |
|
1121 | + rest_error('NO_DATA_EXIST'); |
|
1122 | 1122 | } |
1123 | 1123 | } else { |
1124 | - rest_error ('ITEMMISSINGDATA'); |
|
1124 | + rest_error('ITEMMISSINGDATA'); |
|
1125 | 1125 | } |
1126 | 1126 | } else { |
1127 | 1127 | rest_error('NO_ITEM'); |
@@ -1131,14 +1131,14 @@ discard block |
||
1131 | 1131 | * UPDATING A FOLDER |
1132 | 1132 | * <url to teampass>/api/index.php/update/folder/<folder_id>/<title>;<complexity_level>;<renewal_period>?apikey=<valid api key> |
1133 | 1133 | */ |
1134 | - else if($GLOBALS['request'][1] == "folder") { |
|
1134 | + else if ($GLOBALS['request'][1] == "folder") { |
|
1135 | 1135 | if ($GLOBALS['request'][2] !== "" && is_numeric($GLOBALS['request'][2])) { |
1136 | 1136 | // get sent parameters |
1137 | 1137 | $params = explode(';', base64_decode($GLOBALS['request'][3])); |
1138 | 1138 | |
1139 | 1139 | if (!empty($params[0])) { |
1140 | 1140 | if ($params[1] < 0) { |
1141 | - rest_error ('NO_DATA_EXIST'); |
|
1141 | + rest_error('NO_DATA_EXIST'); |
|
1142 | 1142 | } |
1143 | 1143 | if (empty($params[2])) $params[2] = 0; |
1144 | 1144 | |
@@ -1146,17 +1146,17 @@ discard block |
||
1146 | 1146 | $data_folder = DB::queryfirstrow("SELECT * FROM ".prefix_table("nested_tree")." WHERE id = %s", $GLOBALS['request'][2]); |
1147 | 1147 | $counter = DB::count(); |
1148 | 1148 | if ($counter === 0) { |
1149 | - rest_error ('NO_DATA_EXIST'); |
|
1149 | + rest_error('NO_DATA_EXIST'); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | //Check if title doesn't contains html codes |
1153 | 1153 | if (preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $params[0], $out)) { |
1154 | - rest_error ('HTML_CODES_NOT_ALLOWED'); |
|
1154 | + rest_error('HTML_CODES_NOT_ALLOWED'); |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | // check if title is numeric |
1158 | 1158 | if (is_numeric($params[0]) === true) { |
1159 | - rest_error ('TITLE_ONLY_WITH_NUMBERS'); |
|
1159 | + rest_error('TITLE_ONLY_WITH_NUMBERS'); |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | // get complexity level for this folder |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | "complex" |
1169 | 1169 | ); |
1170 | 1170 | if (intval($params[1]) < intval($data['valeur'])) { |
1171 | - rest_error ('COMPLEXICITY_LEVEL_NOT_REACHED'); |
|
1171 | + rest_error('COMPLEXICITY_LEVEL_NOT_REACHED'); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | try { |
@@ -1198,11 +1198,11 @@ discard block |
||
1198 | 1198 | ); |
1199 | 1199 | |
1200 | 1200 | echo '{"status":"folder updated"}'; |
1201 | - } catch(PDOException $ex) { |
|
1202 | - echo '<br />' . $ex->getMessage(); |
|
1201 | + } catch (PDOException $ex) { |
|
1202 | + echo '<br />'.$ex->getMessage(); |
|
1203 | 1203 | } |
1204 | 1204 | } else { |
1205 | - rest_error ('ITEMMISSINGDATA'); |
|
1205 | + rest_error('ITEMMISSINGDATA'); |
|
1206 | 1206 | } |
1207 | 1207 | } else { |
1208 | 1208 | rest_error('NO_ITEM'); |
@@ -1227,9 +1227,9 @@ discard block |
||
1227 | 1227 | ** |
1228 | 1228 | */ |
1229 | 1229 | // get user credentials |
1230 | - if(isset($GLOBALS['request'][3]) && isset($GLOBALS['request'][4])) { |
|
1230 | + if (isset($GLOBALS['request'][3]) && isset($GLOBALS['request'][4])) { |
|
1231 | 1231 | // get url |
1232 | - if(isset($GLOBALS['request'][1]) && isset($GLOBALS['request'][2])) { |
|
1232 | + if (isset($GLOBALS['request'][1]) && isset($GLOBALS['request'][2])) { |
|
1233 | 1233 | // is user granted? |
1234 | 1234 | $userData = DB::queryFirstRow( |
1235 | 1235 | "SELECT `id`, `pw`, `groupes_interdits`, `groupes_visibles`, `fonction_id` FROM ".$pre."users WHERE login = %s", |
@@ -1292,21 +1292,21 @@ discard block |
||
1292 | 1292 | } |
1293 | 1293 | // prepare answer. If no access then inform |
1294 | 1294 | if (empty($json)) { |
1295 | - rest_error ('AUTH_NO_DATA'); |
|
1295 | + rest_error('AUTH_NO_DATA'); |
|
1296 | 1296 | } else { |
1297 | 1297 | echo json_encode($json); |
1298 | 1298 | } |
1299 | 1299 | } else { |
1300 | - rest_error ('NO_DATA_EXIST'); |
|
1300 | + rest_error('NO_DATA_EXIST'); |
|
1301 | 1301 | } |
1302 | 1302 | } else { |
1303 | - rest_error ('AUTH_NOT_GRANTED'); |
|
1303 | + rest_error('AUTH_NOT_GRANTED'); |
|
1304 | 1304 | } |
1305 | 1305 | } else { |
1306 | - rest_error ('AUTH_NO_URL'); |
|
1306 | + rest_error('AUTH_NO_URL'); |
|
1307 | 1307 | } |
1308 | 1308 | } else { |
1309 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1309 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1310 | 1310 | } |
1311 | 1311 | } elseif ($GLOBALS['request'][0] == "auth_tpc") { |
1312 | 1312 | /* |
@@ -1314,9 +1314,9 @@ discard block |
||
1314 | 1314 | ** |
1315 | 1315 | */ |
1316 | 1316 | // get user credentials |
1317 | - if(isset($GLOBALS['request'][2]) && isset($GLOBALS['request'][3]) && isset($GLOBALS['request'][4])) { |
|
1317 | + if (isset($GLOBALS['request'][2]) && isset($GLOBALS['request'][3]) && isset($GLOBALS['request'][4])) { |
|
1318 | 1318 | // get url |
1319 | - if(isset($GLOBALS['request'][1])) { |
|
1319 | + if (isset($GLOBALS['request'][1])) { |
|
1320 | 1320 | // decode base64 criterium |
1321 | 1321 | $tpc_url = base64_decode($GLOBALS['request'][1]); |
1322 | 1322 | $user_pwd = base64_decode($GLOBALS['request'][3]); |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | ); |
1337 | 1337 | if (strpos($user_saltkey, "Error ") !== false) { |
1338 | 1338 | // error |
1339 | - rest_error ('AUTH_NO_DATA'); |
|
1339 | + rest_error('AUTH_NO_DATA'); |
|
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | // load passwordLib library |
@@ -1393,7 +1393,7 @@ discard block |
||
1393 | 1393 | ) { |
1394 | 1394 | // prepare export |
1395 | 1395 | $json[$data['id']]['label'] = mb_convert_encoding($data['label'], mb_detect_encoding($data['label']), 'UTF-8'); |
1396 | - $json[$data['id']]['login'] = mb_convert_encoding($data['login'], mb_detect_encoding($data['login']), 'UTF-8'); |
|
1396 | + $json[$data['id']]['login'] = mb_convert_encoding($data['login'], mb_detect_encoding($data['login']), 'UTF-8'); |
|
1397 | 1397 | if ($data['perso'] === "0") { |
1398 | 1398 | $crypt_pw = cryption( |
1399 | 1399 | $data['pw'], |
@@ -1415,21 +1415,21 @@ discard block |
||
1415 | 1415 | } |
1416 | 1416 | // prepare answer. If no access then inform |
1417 | 1417 | if (empty($json)) { |
1418 | - rest_error ('AUTH_NO_DATA'); |
|
1418 | + rest_error('AUTH_NO_DATA'); |
|
1419 | 1419 | } else { |
1420 | 1420 | echo json_encode($json); |
1421 | 1421 | } |
1422 | 1422 | } else { |
1423 | - rest_error ('NO_DATA_EXIST'); |
|
1423 | + rest_error('NO_DATA_EXIST'); |
|
1424 | 1424 | } |
1425 | 1425 | } else { |
1426 | - rest_error ('AUTH_NOT_GRANTED'); |
|
1426 | + rest_error('AUTH_NOT_GRANTED'); |
|
1427 | 1427 | } |
1428 | 1428 | } else { |
1429 | - rest_error ('AUTH_NO_URL'); |
|
1429 | + rest_error('AUTH_NO_URL'); |
|
1430 | 1430 | } |
1431 | 1431 | } else { |
1432 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1432 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1433 | 1433 | } |
1434 | 1434 | } elseif ($GLOBALS['request'][0] == "set") { |
1435 | 1435 | /* |
@@ -1439,16 +1439,16 @@ discard block |
||
1439 | 1439 | * NEW ITEM WILL BE STORED IN SPECIFIC FOLDER |
1440 | 1440 | */ |
1441 | 1441 | // get user credentials |
1442 | - if(isset($GLOBALS['request'][4]) && isset($GLOBALS['request'][5])) { |
|
1442 | + if (isset($GLOBALS['request'][4]) && isset($GLOBALS['request'][5])) { |
|
1443 | 1443 | // get url |
1444 | 1444 | if (isset($GLOBALS['request'][1]) && isset($GLOBALS['request'][2]) && isset($GLOBALS['request'][3])) { |
1445 | 1445 | // is user granted? |
1446 | 1446 | $userData = DB::queryFirstRow( |
1447 | - "SELECT `id`, `pw`, `groupes_interdits`, `groupes_visibles`, `fonction_id` FROM " . $pre . "users WHERE login = %s", |
|
1447 | + "SELECT `id`, `pw`, `groupes_interdits`, `groupes_visibles`, `fonction_id` FROM ".$pre."users WHERE login = %s", |
|
1448 | 1448 | $GLOBALS['request'][4] |
1449 | 1449 | ); |
1450 | 1450 | if (DB::count() == 0) { |
1451 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1451 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | // load passwordLib library |
@@ -1463,7 +1463,7 @@ discard block |
||
1463 | 1463 | // does the personal folder of this user exists? |
1464 | 1464 | DB::queryFirstRow( |
1465 | 1465 | "SELECT `id` |
1466 | - FROM " . $pre . "nested_tree |
|
1466 | + FROM " . $pre."nested_tree |
|
1467 | 1467 | WHERE title = %s AND personal_folder = 1", |
1468 | 1468 | $userData['id'] |
1469 | 1469 | ); |
@@ -1472,7 +1472,7 @@ discard block |
||
1472 | 1472 | // if not create it |
1473 | 1473 | $folder = DB::queryFirstRow( |
1474 | 1474 | "SELECT `id` |
1475 | - FROM " . $pre . "nested_tree |
|
1475 | + FROM " . $pre."nested_tree |
|
1476 | 1476 | WHERE title = %s", |
1477 | 1477 | "teampass-connect" |
1478 | 1478 | ); |
@@ -1552,37 +1552,37 @@ discard block |
||
1552 | 1552 | $json['status'] = "ok"; |
1553 | 1553 | // prepare answer. If no access then inform |
1554 | 1554 | if (empty($json)) { |
1555 | - rest_error ('AUTH_NO_DATA'); |
|
1555 | + rest_error('AUTH_NO_DATA'); |
|
1556 | 1556 | } else { |
1557 | 1557 | echo json_encode($json); |
1558 | 1558 | } |
1559 | 1559 | } else { |
1560 | - rest_error ('NO_PF_EXIST_FOR_USER'); |
|
1560 | + rest_error('NO_PF_EXIST_FOR_USER'); |
|
1561 | 1561 | } |
1562 | 1562 | } else { |
1563 | - rest_error ('AUTH_NOT_GRANTED'); |
|
1563 | + rest_error('AUTH_NOT_GRANTED'); |
|
1564 | 1564 | } |
1565 | 1565 | } else { |
1566 | - rest_error ('SET_NO_DATA'); |
|
1566 | + rest_error('SET_NO_DATA'); |
|
1567 | 1567 | } |
1568 | 1568 | } else { |
1569 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1569 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1570 | 1570 | } |
1571 | 1571 | } elseif ($GLOBALS['request'][0] == "set_tpc") { |
1572 | 1572 | /* |
1573 | 1573 | * TO BE USED ONLY BY TEAMPASS-CONNECT |
1574 | 1574 | */ |
1575 | 1575 | // get user credentials |
1576 | - if(isset($GLOBALS['request'][2]) && isset($GLOBALS['request'][3])) { |
|
1576 | + if (isset($GLOBALS['request'][2]) && isset($GLOBALS['request'][3])) { |
|
1577 | 1577 | // get url |
1578 | 1578 | if (isset($GLOBALS['request'][1])) { |
1579 | 1579 | // is user granted? |
1580 | 1580 | $userData = DB::queryFirstRow( |
1581 | - "SELECT `id`, `pw`, `groupes_interdits`, `groupes_visibles`, `fonction_id`, `encrypted_psk` FROM " . $pre . "users WHERE login = %s", |
|
1581 | + "SELECT `id`, `pw`, `groupes_interdits`, `groupes_visibles`, `fonction_id`, `encrypted_psk` FROM ".$pre."users WHERE login = %s", |
|
1582 | 1582 | $GLOBALS['request'][2] |
1583 | 1583 | ); |
1584 | 1584 | if (DB::count() == 0) { |
1585 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1585 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1586 | 1586 | } |
1587 | 1587 | |
1588 | 1588 | // load passwordLib library |
@@ -1617,7 +1617,7 @@ discard block |
||
1617 | 1617 | ); |
1618 | 1618 | if (strpos($user_key_encoded, "Error ") !== false) { |
1619 | 1619 | // error |
1620 | - rest_error ('AUTH_NO_DATA'); |
|
1620 | + rest_error('AUTH_NO_DATA'); |
|
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | |
@@ -1627,7 +1627,7 @@ discard block |
||
1627 | 1627 | // does the personal folder of this user exists? |
1628 | 1628 | $user_folder = DB::queryFirstRow( |
1629 | 1629 | "SELECT `id` |
1630 | - FROM " . $pre . "nested_tree |
|
1630 | + FROM " . $pre."nested_tree |
|
1631 | 1631 | WHERE title = %s AND personal_folder = 1", |
1632 | 1632 | $userData['id'] |
1633 | 1633 | ); |
@@ -1636,7 +1636,7 @@ discard block |
||
1636 | 1636 | // if not create it |
1637 | 1637 | $folder = DB::queryFirstRow( |
1638 | 1638 | "SELECT `id` |
1639 | - FROM " . $pre . "nested_tree |
|
1639 | + FROM " . $pre."nested_tree |
|
1640 | 1640 | WHERE title = %s", |
1641 | 1641 | "teampass-connect" |
1642 | 1642 | ); |
@@ -1673,7 +1673,7 @@ discard block |
||
1673 | 1673 | } |
1674 | 1674 | } else { |
1675 | 1675 | // there is an error in PSALT |
1676 | - rest_error ('NO_PSALTK_PROVIDED'); |
|
1676 | + rest_error('NO_PSALTK_PROVIDED'); |
|
1677 | 1677 | } |
1678 | 1678 | |
1679 | 1679 | // now we continue |
@@ -1725,18 +1725,18 @@ discard block |
||
1725 | 1725 | $json['new_item_id'] = $newID; |
1726 | 1726 | // prepare answer. If no access then inform |
1727 | 1727 | if (empty($json)) { |
1728 | - rest_error ('AUTH_NO_DATA'); |
|
1728 | + rest_error('AUTH_NO_DATA'); |
|
1729 | 1729 | } else { |
1730 | 1730 | echo json_encode($json); |
1731 | 1731 | } |
1732 | 1732 | } else { |
1733 | - rest_error ('AUTH_NOT_GRANTED'); |
|
1733 | + rest_error('AUTH_NOT_GRANTED'); |
|
1734 | 1734 | } |
1735 | 1735 | } else { |
1736 | - rest_error ('SET_NO_DATA'); |
|
1736 | + rest_error('SET_NO_DATA'); |
|
1737 | 1737 | } |
1738 | 1738 | } else { |
1739 | - rest_error ('AUTH_NO_IDENTIFIER'); |
|
1739 | + rest_error('AUTH_NO_IDENTIFIER'); |
|
1740 | 1740 | } |
1741 | 1741 | } |
1742 | 1742 | /* |
@@ -1747,13 +1747,13 @@ discard block |
||
1747 | 1747 | */ |
1748 | 1748 | elseif ($GLOBALS['request'][0] == "delete") { |
1749 | 1749 | $_SESSION['settings']['cpassman_dir'] = ".."; |
1750 | - if($GLOBALS['request'][1] == "folder") { |
|
1750 | + if ($GLOBALS['request'][1] == "folder") { |
|
1751 | 1751 | $array_category = explode(';', $GLOBALS['request'][2]); |
1752 | 1752 | |
1753 | 1753 | // get user info |
1754 | 1754 | if (isset($GLOBALS['request'][3]) && !empty($GLOBALS['request'][3])) { |
1755 | 1755 | $userData = DB::queryFirstRow( |
1756 | - "SELECT `id` FROM " . $pre . "users WHERE login = %s", |
|
1756 | + "SELECT `id` FROM ".$pre."users WHERE login = %s", |
|
1757 | 1757 | $GLOBALS['request'][3] |
1758 | 1758 | ); |
1759 | 1759 | if (DB::count() == 0) { |
@@ -1765,7 +1765,7 @@ discard block |
||
1765 | 1765 | $user_id = API_USER_ID; |
1766 | 1766 | } |
1767 | 1767 | |
1768 | - if(count($array_category) > 0 && count($array_category) < 5) { |
|
1768 | + if (count($array_category) > 0 && count($array_category) < 5) { |
|
1769 | 1769 | // load passwordLib library |
1770 | 1770 | require_once '../sources/SplClassLoader.php'; |
1771 | 1771 | |
@@ -1775,7 +1775,7 @@ discard block |
||
1775 | 1775 | $tree = new Tree\NestedTree\NestedTree(prefix_table("nested_tree"), 'id', 'parent_id', 'title', 'personal_folder'); |
1776 | 1776 | |
1777 | 1777 | // this will delete all sub folders and items associated |
1778 | - for ($i=0; $i < count($array_category); $i ++) {echo "\n".$array_category[$i]."\n"; |
|
1778 | + for ($i = 0; $i < count($array_category); $i++) {echo "\n".$array_category[$i]."\n"; |
|
1779 | 1779 | // Get through each subfolder |
1780 | 1780 | $folders = $tree->getDescendants($array_category[$i], true); |
1781 | 1781 | print_r($folders); |
@@ -1789,7 +1789,7 @@ discard block |
||
1789 | 1789 | 'type' => 'folder_deleted', |
1790 | 1790 | 'intitule' => "f".$array_category[$i], |
1791 | 1791 | 'valeur' => $folder->id.', '.$folder->parent_id.', '. |
1792 | - $folder->title.', '.$folder->nleft.', '.$folder->nright.', '. $folder->nlevel.', 0, 0, 0, 0' |
|
1792 | + $folder->title.', '.$folder->nleft.', '.$folder->nright.', '.$folder->nlevel.', 0, 0, 0, 0' |
|
1793 | 1793 | ) |
1794 | 1794 | ); |
1795 | 1795 | //delete folder |
@@ -1829,18 +1829,18 @@ discard block |
||
1829 | 1829 | } |
1830 | 1830 | } |
1831 | 1831 | } else { |
1832 | - rest_error ('NO_CATEGORY'); |
|
1832 | + rest_error('NO_CATEGORY'); |
|
1833 | 1833 | } |
1834 | 1834 | |
1835 | 1835 | $json['status'] = 'OK'; |
1836 | 1836 | |
1837 | - } elseif($GLOBALS['request'][1] == "item") { |
|
1837 | + } elseif ($GLOBALS['request'][1] == "item") { |
|
1838 | 1838 | $array_items = explode(';', $GLOBALS['request'][2]); |
1839 | 1839 | |
1840 | 1840 | // get user info |
1841 | 1841 | if (isset($GLOBALS['request'][3]) && !empty($GLOBALS['request'][3])) { |
1842 | 1842 | $userData = DB::queryFirstRow( |
1843 | - "SELECT `id` FROM " . $pre . "users WHERE login = %s", |
|
1843 | + "SELECT `id` FROM ".$pre."users WHERE login = %s", |
|
1844 | 1844 | $GLOBALS['request'][3] |
1845 | 1845 | ); |
1846 | 1846 | if (DB::count() == 0) { |
@@ -1850,7 +1850,7 @@ discard block |
||
1850 | 1850 | } |
1851 | 1851 | } |
1852 | 1852 | |
1853 | - for ($i=0; $i < count($array_items); $i ++) { |
|
1853 | + for ($i = 0; $i < count($array_items); $i++) { |
|
1854 | 1854 | DB::update( |
1855 | 1855 | prefix_table("items"), |
1856 | 1856 | array( |
@@ -1880,7 +1880,7 @@ discard block |
||
1880 | 1880 | if ($json) { |
1881 | 1881 | echo json_encode($json); |
1882 | 1882 | } else { |
1883 | - rest_error ('EMPTY'); |
|
1883 | + rest_error('EMPTY'); |
|
1884 | 1884 | } |
1885 | 1885 | } else if ($GLOBALS['request'][0] == "new_password") { |
1886 | 1886 | if (!empty($GLOBALS['request'][1])) { |
@@ -1902,11 +1902,11 @@ discard block |
||
1902 | 1902 | |
1903 | 1903 | // init |
1904 | 1904 | $pwgen->setLength($params[0]); |
1905 | - if($params[1] === "1") $pwgen->setSecure(true); |
|
1906 | - if($params[2] === "1") $pwgen->setNumerals(true); |
|
1907 | - if($params[3] === "1") $pwgen->setCapitalize(true); |
|
1908 | - if($params[4] === "1") $pwgen->setAmbiguous(true); |
|
1909 | - if($params[5] === "1" && $params[6] === "1") $pwgen->setSymbols(true); |
|
1905 | + if ($params[1] === "1") $pwgen->setSecure(true); |
|
1906 | + if ($params[2] === "1") $pwgen->setNumerals(true); |
|
1907 | + if ($params[3] === "1") $pwgen->setCapitalize(true); |
|
1908 | + if ($params[4] === "1") $pwgen->setAmbiguous(true); |
|
1909 | + if ($params[5] === "1" && $params[6] === "1") $pwgen->setSymbols(true); |
|
1910 | 1910 | |
1911 | 1911 | // generate and send back (generate in base64 if symbols are asked) |
1912 | 1912 | if ($params[6] === "1") { |
@@ -1915,7 +1915,7 @@ discard block |
||
1915 | 1915 | echo '{"password" : "'.($pwgen->generate()).'"}'; |
1916 | 1916 | } |
1917 | 1917 | } else { |
1918 | - rest_error ('NO_PARAMETERS'); |
|
1918 | + rest_error('NO_PARAMETERS'); |
|
1919 | 1919 | } |
1920 | 1920 | } else if ($GLOBALS['request'][0] === "info") { |
1921 | 1921 | if ($GLOBALS['request'][1] === "complexicity_levels_list") { |
@@ -1935,11 +1935,11 @@ discard block |
||
1935 | 1935 | } else if ($GLOBALS['request'][1] === "folder") { |
1936 | 1936 | if (!empty($GLOBALS['request'][2]) && is_numeric($GLOBALS['request'][2])) { |
1937 | 1937 | $data = DB::queryFirstRow( |
1938 | - "SELECT * FROM " . $pre . "nested_tree WHERE id = %i", |
|
1938 | + "SELECT * FROM ".$pre."nested_tree WHERE id = %i", |
|
1939 | 1939 | $GLOBALS['request'][2] |
1940 | 1940 | ); |
1941 | 1941 | if (DB::count() == 0) { |
1942 | - rest_error ('NOSUCHFOLDER'); |
|
1942 | + rest_error('NOSUCHFOLDER'); |
|
1943 | 1943 | } |
1944 | 1944 | |
1945 | 1945 | // form id_tree to full foldername |
@@ -1970,36 +1970,36 @@ discard block |
||
1970 | 1970 | |
1971 | 1971 | echo json_encode($json); |
1972 | 1972 | } else { |
1973 | - rest_error ('NO_PARAMETERS'); |
|
1973 | + rest_error('NO_PARAMETERS'); |
|
1974 | 1974 | } |
1975 | 1975 | } else if ($GLOBALS['request'][1] === "version") { |
1976 | 1976 | echo '{"api-version":"'.$api_version.'"}'; |
1977 | 1977 | } else { |
1978 | - rest_error ('NO_PARAMETERS'); |
|
1978 | + rest_error('NO_PARAMETERS'); |
|
1979 | 1979 | } |
1980 | 1980 | } else { |
1981 | - rest_error ('METHOD'); |
|
1981 | + rest_error('METHOD'); |
|
1982 | 1982 | } |
1983 | 1983 | } |
1984 | 1984 | } |
1985 | 1985 | |
1986 | 1986 | function rest_put() { |
1987 | - if(!@count($GLOBALS['request'])==0){ |
|
1987 | + if (!@count($GLOBALS['request']) == 0) { |
|
1988 | 1988 | $request_uri = $GLOBALS['_SERVER']['REQUEST_URI']; |
1989 | - preg_match('/\/api(\/index.php|)\/(.*)\?apikey=(.*)/',$request_uri,$matches); |
|
1989 | + preg_match('/\/api(\/index.php|)\/(.*)\?apikey=(.*)/', $request_uri, $matches); |
|
1990 | 1990 | if (count($matches) == 0) { |
1991 | - rest_error ('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
1991 | + rest_error('REQUEST_SENT_NOT_UNDERSTANDABLE'); |
|
1992 | 1992 | } |
1993 | - $GLOBALS['request'] = explode('/',$matches[2]); |
|
1993 | + $GLOBALS['request'] = explode('/', $matches[2]); |
|
1994 | 1994 | } |
1995 | - if(apikey_checker($GLOBALS['apikey'])) { |
|
1995 | + if (apikey_checker($GLOBALS['apikey'])) { |
|
1996 | 1996 | global $server, $user, $pass, $database, $pre, $link; |
1997 | 1997 | teampass_connect(); |
1998 | 1998 | |
1999 | 1999 | } |
2000 | 2000 | } |
2001 | 2001 | |
2002 | -function rest_error ($type,$detail = 'N/A') { |
|
2002 | +function rest_error($type, $detail = 'N/A') { |
|
2003 | 2003 | switch ($type) { |
2004 | 2004 | case 'APIKEY': |
2005 | 2005 | $message = Array('err' => 'This api_key '.$GLOBALS['apikey'].' doesn\'t exist'); |
@@ -2116,13 +2116,13 @@ discard block |
||
2116 | 2116 | exit(0); |
2117 | 2117 | } |
2118 | 2118 | |
2119 | -function apikey_checker ($apikey_used) { |
|
2119 | +function apikey_checker($apikey_used) { |
|
2120 | 2120 | teampass_connect(); |
2121 | 2121 | $apikey_pool = teampass_get_keys(); |
2122 | 2122 | if (in_array($apikey_used, $apikey_pool)) { |
2123 | 2123 | return(1); |
2124 | 2124 | } else { |
2125 | - rest_error('APIKEY',$apikey_used); |
|
2125 | + rest_error('APIKEY', $apikey_used); |
|
2126 | 2126 | } |
2127 | 2127 | } |
2128 | 2128 | |
@@ -2132,7 +2132,7 @@ discard block |
||
2132 | 2132 | $dk = ''; |
2133 | 2133 | |
2134 | 2134 | for ($block = 1; $block <= $kb; $block++) { |
2135 | - $ib = $h = hash_hmac($a, $s . pack('N', $block), $p, true); |
|
2135 | + $ib = $h = hash_hmac($a, $s.pack('N', $block), $p, true); |
|
2136 | 2136 | for ($i = 1; $i < $c; $i++) { |
2137 | 2137 | $ib ^= ($h = hash_hmac($a, $h, $p, true)); |
2138 | 2138 | } |
@@ -349,8 +349,7 @@ discard block |
||
349 | 349 | |
350 | 350 | $x++; |
351 | 351 | } |
352 | - } |
|
353 | - else if($GLOBALS['request'][1] == "userpw") { |
|
352 | + } else if($GLOBALS['request'][1] == "userpw") { |
|
354 | 353 | /* |
355 | 354 | * READ USER ITEMS |
356 | 355 | */ |
@@ -434,8 +433,7 @@ discard block |
||
434 | 433 | |
435 | 434 | $x++; |
436 | 435 | } |
437 | - } |
|
438 | - else if($GLOBALS['request'][1] == "userfolders") { |
|
436 | + } else if($GLOBALS['request'][1] == "userfolders") { |
|
439 | 437 | /* |
440 | 438 | * READ USER FOLDERS |
441 | 439 | * Sends back a list of folders |
@@ -478,8 +476,7 @@ discard block |
||
478 | 476 | } |
479 | 477 | } |
480 | 478 | } |
481 | - } |
|
482 | - elseif($GLOBALS['request'][1] == "items") { |
|
479 | + } elseif($GLOBALS['request'][1] == "items") { |
|
483 | 480 | /* |
484 | 481 | * READ ITEMS asked |
485 | 482 | */ |
@@ -826,8 +823,11 @@ discard block |
||
826 | 823 | "SELECT `id` FROM ".prefix_table("roles_title")." WHERE title = %s", |
827 | 824 | $role |
828 | 825 | ); |
829 | - if (empty($rolesList)) $rolesList = $tmp['id']; |
|
830 | - else $rolesList .= ";" . $tmp['id']; |
|
826 | + if (empty($rolesList)) { |
|
827 | + $rolesList = $tmp['id']; |
|
828 | + } else { |
|
829 | + $rolesList .= ";" . $tmp['id']; |
|
830 | + } |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | // Add user in DB |
@@ -899,8 +899,12 @@ discard block |
||
899 | 899 | $params = explode(';', base64_decode($GLOBALS['request'][2])); |
900 | 900 | |
901 | 901 | if (!empty($params[0]) && !empty($params[1])) { |
902 | - if (empty($params[3])) $params[3] = 0; |
|
903 | - if (empty($params[4])) $params[4] = 0; |
|
902 | + if (empty($params[3])) { |
|
903 | + $params[3] = 0; |
|
904 | + } |
|
905 | + if (empty($params[4])) { |
|
906 | + $params[4] = 0; |
|
907 | + } |
|
904 | 908 | if ($params[2] < 0) { |
905 | 909 | rest_error ('NO_DATA_EXIST'); |
906 | 910 | } |
@@ -1140,7 +1144,9 @@ discard block |
||
1140 | 1144 | if ($params[1] < 0) { |
1141 | 1145 | rest_error ('NO_DATA_EXIST'); |
1142 | 1146 | } |
1143 | - if (empty($params[2])) $params[2] = 0; |
|
1147 | + if (empty($params[2])) { |
|
1148 | + $params[2] = 0; |
|
1149 | + } |
|
1144 | 1150 | |
1145 | 1151 | // check if folder exists and get folder data |
1146 | 1152 | $data_folder = DB::queryfirstrow("SELECT * FROM ".prefix_table("nested_tree")." WHERE id = %s", $GLOBALS['request'][2]); |
@@ -1886,13 +1892,27 @@ discard block |
||
1886 | 1892 | if (!empty($GLOBALS['request'][1])) { |
1887 | 1893 | $params = explode(";", $GLOBALS['request'][1]); |
1888 | 1894 | |
1889 | - if (empty($params[0])) $params[0] = 8; |
|
1890 | - if (empty($params[1])) $params[1] = 0; |
|
1891 | - if (empty($params[2])) $params[2] = 0; |
|
1892 | - if (empty($params[3])) $params[3] = 0; |
|
1893 | - if (empty($params[4])) $params[4] = 0; |
|
1894 | - if (empty($params[5])) $params[5] = 0; |
|
1895 | - if (empty($params[6])) $params[6] = 0; |
|
1895 | + if (empty($params[0])) { |
|
1896 | + $params[0] = 8; |
|
1897 | + } |
|
1898 | + if (empty($params[1])) { |
|
1899 | + $params[1] = 0; |
|
1900 | + } |
|
1901 | + if (empty($params[2])) { |
|
1902 | + $params[2] = 0; |
|
1903 | + } |
|
1904 | + if (empty($params[3])) { |
|
1905 | + $params[3] = 0; |
|
1906 | + } |
|
1907 | + if (empty($params[4])) { |
|
1908 | + $params[4] = 0; |
|
1909 | + } |
|
1910 | + if (empty($params[5])) { |
|
1911 | + $params[5] = 0; |
|
1912 | + } |
|
1913 | + if (empty($params[6])) { |
|
1914 | + $params[6] = 0; |
|
1915 | + } |
|
1896 | 1916 | |
1897 | 1917 | // load library |
1898 | 1918 | require_once '../sources/SplClassLoader.php'; |
@@ -1902,11 +1922,21 @@ discard block |
||
1902 | 1922 | |
1903 | 1923 | // init |
1904 | 1924 | $pwgen->setLength($params[0]); |
1905 | - if($params[1] === "1") $pwgen->setSecure(true); |
|
1906 | - if($params[2] === "1") $pwgen->setNumerals(true); |
|
1907 | - if($params[3] === "1") $pwgen->setCapitalize(true); |
|
1908 | - if($params[4] === "1") $pwgen->setAmbiguous(true); |
|
1909 | - if($params[5] === "1" && $params[6] === "1") $pwgen->setSymbols(true); |
|
1925 | + if($params[1] === "1") { |
|
1926 | + $pwgen->setSecure(true); |
|
1927 | + } |
|
1928 | + if($params[2] === "1") { |
|
1929 | + $pwgen->setNumerals(true); |
|
1930 | + } |
|
1931 | + if($params[3] === "1") { |
|
1932 | + $pwgen->setCapitalize(true); |
|
1933 | + } |
|
1934 | + if($params[4] === "1") { |
|
1935 | + $pwgen->setAmbiguous(true); |
|
1936 | + } |
|
1937 | + if($params[5] === "1" && $params[6] === "1") { |
|
1938 | + $pwgen->setSymbols(true); |
|
1939 | + } |
|
1910 | 1940 | |
1911 | 1941 | // generate and send back (generate in base64 if symbols are asked) |
1912 | 1942 | if ($params[6] === "1") { |
@@ -40,6 +40,10 @@ |
||
40 | 40 | return $response['flickerCode']; |
41 | 41 | } |
42 | 42 | |
43 | + /** |
|
44 | + * @param string $response |
|
45 | + * @param string $hedgeId |
|
46 | + */ |
|
43 | 47 | function verifyResponse($apn, $response, $hedgeId) { |
44 | 48 | |
45 | 49 | $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
@@ -1,54 +1,54 @@ |
||
1 | 1 | <?php |
2 | 2 | class AXSILPortal_V1_Auth { |
3 | - var $server; |
|
3 | + var $server; |
|
4 | 4 | |
5 | - private $url = ""; |
|
6 | - private $AAId = ""; |
|
7 | - private $apiKey = ""; |
|
5 | + private $url = ""; |
|
6 | + private $AAId = ""; |
|
7 | + private $apiKey = ""; |
|
8 | 8 | |
9 | - private $baseUrl = ""; |
|
9 | + private $baseUrl = ""; |
|
10 | 10 | |
11 | - function setUrl($url) { |
|
12 | - $this->url = $url; |
|
13 | - } |
|
11 | + function setUrl($url) { |
|
12 | + $this->url = $url; |
|
13 | + } |
|
14 | 14 | |
15 | - function setAAId($AAId) { |
|
16 | - $this->AAId = $AAId; |
|
17 | - } |
|
15 | + function setAAId($AAId) { |
|
16 | + $this->AAId = $AAId; |
|
17 | + } |
|
18 | 18 | |
19 | - function setApiKey($apiKey) { |
|
20 | - $this->apiKey = $apiKey; |
|
21 | - } |
|
19 | + function setApiKey($apiKey) { |
|
20 | + $this->apiKey = $apiKey; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - // Verify that you can open the URL from the web server. |
|
25 | - function create() { |
|
26 | - if ($this->url != "" && $this->AAId != "" && $this->apiKey != "") { |
|
27 | - $this->baseUrl = $this->url."".$this->apiKey."/".$this->AAId; |
|
28 | - } else { |
|
29 | - die("Cannot initialize Agses webservice without credentials, please set them in settings"); |
|
30 | - } |
|
31 | - } |
|
24 | + // Verify that you can open the URL from the web server. |
|
25 | + function create() { |
|
26 | + if ($this->url != "" && $this->AAId != "" && $this->apiKey != "") { |
|
27 | + $this->baseUrl = $this->url."".$this->apiKey."/".$this->AAId; |
|
28 | + } else { |
|
29 | + die("Cannot initialize Agses webservice without credentials, please set them in settings"); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - function createAuthenticationMessage($apn, $createFlickerCode, $returnPath, $authenticationLevel, $hedgeId) { |
|
33 | + function createAuthenticationMessage($apn, $createFlickerCode, $returnPath, $authenticationLevel, $hedgeId) { |
|
34 | 34 | |
35 | - $serviceCall = $this->baseUrl."/authmessage/".$apn."/create/".$hedgeId; |
|
35 | + $serviceCall = $this->baseUrl."/authmessage/".$apn."/create/".$hedgeId; |
|
36 | 36 | |
37 | - $json = file_get_contents($serviceCall); |
|
38 | - $response = json_decode($json,true); |
|
37 | + $json = file_get_contents($serviceCall); |
|
38 | + $response = json_decode($json,true); |
|
39 | 39 | |
40 | - return $response['flickerCode']; |
|
41 | - } |
|
40 | + return $response['flickerCode']; |
|
41 | + } |
|
42 | 42 | |
43 | - function verifyResponse($apn, $response, $hedgeId) { |
|
43 | + function verifyResponse($apn, $response, $hedgeId) { |
|
44 | 44 | |
45 | - $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
|
45 | + $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
|
46 | 46 | |
47 | - $json = file_get_contents($serviceCall); |
|
48 | - $response = json_decode($json,true); |
|
47 | + $json = file_get_contents($serviceCall); |
|
48 | + $response = json_decode($json,true); |
|
49 | 49 | |
50 | - return $response['response']; |
|
51 | - } |
|
50 | + return $response['response']; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | } |
54 | 54 | ?> |
55 | 55 | \ No newline at end of file |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $serviceCall = $this->baseUrl."/authmessage/".$apn."/create/".$hedgeId; |
36 | 36 | |
37 | 37 | $json = file_get_contents($serviceCall); |
38 | - $response = json_decode($json,true); |
|
38 | + $response = json_decode($json, true); |
|
39 | 39 | |
40 | 40 | return $response['flickerCode']; |
41 | 41 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
46 | 46 | |
47 | 47 | $json = file_get_contents($serviceCall); |
48 | - $response = json_decode($json,true); |
|
48 | + $response = json_decode($json, true); |
|
49 | 49 | |
50 | 50 | return $response['response']; |
51 | 51 | } |
@@ -82,7 +82,7 @@ |
||
82 | 82 | * Base64 character set "./[A-Z][a-z][0-9]" |
83 | 83 | * |
84 | 84 | * @param string $src |
85 | - * @return string|bool |
|
85 | + * @return string|false |
|
86 | 86 | * @throws \RangeException |
87 | 87 | */ |
88 | 88 | public static function decode($src, $strictPadding = false) |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | $b2 = $chunk[3]; |
53 | 53 | |
54 | 54 | $dest .= |
55 | - static::encode6Bits( $b0 >> 2 ) . |
|
56 | - static::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63) . |
|
57 | - static::encode6Bits((($b1 << 2) | ($b2 >> 6)) & 63) . |
|
58 | - static::encode6Bits( $b2 & 63); |
|
55 | + static::encode6Bits($b0 >> 2). |
|
56 | + static::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63). |
|
57 | + static::encode6Bits((($b1 << 2) | ($b2 >> 6)) & 63). |
|
58 | + static::encode6Bits($b2 & 63); |
|
59 | 59 | } |
60 | 60 | // The last chunk, which may have padding: |
61 | 61 | if ($i < $srcLen) { |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | if ($i + 1 < $srcLen) { |
65 | 65 | $b1 = $chunk[2]; |
66 | 66 | $dest .= |
67 | - static::encode6Bits( $b0 >> 2 ) . |
|
68 | - static::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63) . |
|
69 | - static::encode6Bits( ($b1 << 2) & 63) . '='; |
|
67 | + static::encode6Bits($b0 >> 2). |
|
68 | + static::encode6Bits((($b0 << 4) | ($b1 >> 4)) & 63). |
|
69 | + static::encode6Bits(($b1 << 2) & 63).'='; |
|
70 | 70 | } else { |
71 | 71 | $dest .= |
72 | - static::encode6Bits( $b0 >> 2) . |
|
73 | - static::encode6Bits(($b0 << 4) & 63) . '=='; |
|
72 | + static::encode6Bits($b0 >> 2). |
|
73 | + static::encode6Bits(($b0 << 4) & 63).'=='; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | return $dest; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | 'CCC', |
126 | 126 | ((($c0 << 2) | ($c1 >> 4)) & 0xff), |
127 | 127 | ((($c1 << 4) | ($c2 >> 2)) & 0xff), |
128 | - ((($c2 << 6) | $c3 ) & 0xff) |
|
128 | + ((($c2 << 6) | $c3) & 0xff) |
|
129 | 129 | ); |
130 | 130 | $err |= ($c0 | $c1 | $c2 | $c3) >> 8; |
131 | 131 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | ((($c1 << 4) | ($c2 >> 2)) & 0xff) |
143 | 143 | ); |
144 | 144 | $err |= ($c0 | $c1 | $c2) >> 8; |
145 | - } elseif($i + 1 < $srcLen) { |
|
145 | + } elseif ($i + 1 < $srcLen) { |
|
146 | 146 | $c1 = static::decode6Bits($chunk[2]); |
147 | 147 | $dest .= \pack( |
148 | 148 | 'C', |
@@ -1458,7 +1458,7 @@ discard block |
||
1458 | 1458 | * |
1459 | 1459 | * May need to be overwritten by classes extending this one in some cases |
1460 | 1460 | * |
1461 | - * @return int |
|
1461 | + * @return string|null |
|
1462 | 1462 | * @access private |
1463 | 1463 | */ |
1464 | 1464 | function _openssl_translate_mode() |
@@ -2541,7 +2541,7 @@ discard block |
||
2541 | 2541 | * |
2542 | 2542 | * @see self::_setupInlineCrypt() |
2543 | 2543 | * @access private |
2544 | - * @param $bytes |
|
2544 | + * @param string $bytes |
|
2545 | 2545 | * @return string |
2546 | 2546 | */ |
2547 | 2547 | function _hashInlineCryptFunction($bytes) |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | } |
518 | 518 | |
519 | 519 | if (strlen($iv) != $this->block_size) { |
520 | - throw new \LengthException('Received initialization vector of size ' . strlen($iv) . ', but size ' . $this->block_size . ' is required'); |
|
520 | + throw new \LengthException('Received initialization vector of size '.strlen($iv).', but size '.$this->block_size.' is required'); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | $this->iv = $iv; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | if (is_string($this->key) && strlen($this->key) != $this->explicit_key_length) { |
573 | 573 | $this->key = false; |
574 | - throw new \LengthException('Key has already been set and is not ' .$this->explicit_key_length . ' bytes long'); |
|
574 | + throw new \LengthException('Key has already been set and is not '.$this->explicit_key_length.' bytes long'); |
|
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | function setKey($key) |
593 | 593 | { |
594 | 594 | if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) { |
595 | - throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes'); |
|
595 | + throw new \LengthException('Key length has already been set to '.$this->explicit_key_length.' bytes and this key is '.strlen($key).' bytes'); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | $this->key = $key; |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | if ($dkLen > $hashObj->getLength()) { |
652 | 652 | throw new \LengthException('Derived key length cannot be longer than the hash length'); |
653 | 653 | } |
654 | - $t = $password . $salt; |
|
654 | + $t = $password.$salt; |
|
655 | 655 | for ($i = 0; $i < $count; ++$i) { |
656 | 656 | $t = $hashObj->hash($t); |
657 | 657 | } |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | $hmac = new Hash(); |
671 | 671 | $hmac->setHash($hash); |
672 | 672 | $hmac->setKey($password); |
673 | - $f = $u = $hmac->hash($salt . pack('N', $i++)); |
|
673 | + $f = $u = $hmac->hash($salt.pack('N', $i++)); |
|
674 | 674 | for ($j = 2; $j <= $count; ++$j) { |
675 | 675 | $u = $hmac->hash($u); |
676 | - $f^= $u; |
|
676 | + $f ^= $u; |
|
677 | 677 | } |
678 | - $key.= $f; |
|
678 | + $key .= $f; |
|
679 | 679 | } |
680 | 680 | $key = substr($key, 0, $dkLen); |
681 | 681 | break; |
@@ -755,11 +755,11 @@ discard block |
||
755 | 755 | $max = $this->block_size - $pos; |
756 | 756 | if ($len >= $max) { |
757 | 757 | $i = $max; |
758 | - $len-= $max; |
|
758 | + $len -= $max; |
|
759 | 759 | $pos = 0; |
760 | 760 | } else { |
761 | 761 | $i = $len; |
762 | - $pos+= $len; |
|
762 | + $pos += $len; |
|
763 | 763 | $len = 0; |
764 | 764 | } |
765 | 765 | // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize |
@@ -771,13 +771,13 @@ discard block |
||
771 | 771 | $overflow = $len % $this->block_size; |
772 | 772 | |
773 | 773 | if ($overflow) { |
774 | - $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
774 | + $ciphertext .= openssl_encrypt(substr($plaintext, 0, -$overflow).str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
775 | 775 | $iv = $this->_string_pop($ciphertext, $this->block_size); |
776 | 776 | |
777 | 777 | $size = $len - $overflow; |
778 | 778 | $block = $iv ^ substr($plaintext, -$overflow); |
779 | 779 | $iv = substr_replace($iv, $block, 0, $overflow); |
780 | - $ciphertext.= $block; |
|
780 | + $ciphertext .= $block; |
|
781 | 781 | $pos = $overflow; |
782 | 782 | } elseif ($len) { |
783 | 783 | $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
@@ -815,11 +815,11 @@ discard block |
||
815 | 815 | $max = $block_size - $pos; |
816 | 816 | if ($len >= $max) { |
817 | 817 | $i = $max; |
818 | - $len-= $max; |
|
818 | + $len -= $max; |
|
819 | 819 | $pos = 0; |
820 | 820 | } else { |
821 | 821 | $i = $len; |
822 | - $pos+= $len; |
|
822 | + $pos += $len; |
|
823 | 823 | $len = 0; |
824 | 824 | } |
825 | 825 | $ciphertext = substr($iv, $orig_pos) ^ $plaintext; |
@@ -832,15 +832,15 @@ discard block |
||
832 | 832 | @mcrypt_generic_init($this->enmcrypt, $this->key, $iv); |
833 | 833 | $this->enbuffer['enmcrypt_init'] = false; |
834 | 834 | } |
835 | - $ciphertext.= @mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size)); |
|
835 | + $ciphertext .= @mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size)); |
|
836 | 836 | $iv = substr($ciphertext, -$block_size); |
837 | - $len%= $block_size; |
|
837 | + $len %= $block_size; |
|
838 | 838 | } else { |
839 | 839 | while ($len >= $block_size) { |
840 | 840 | $iv = @mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $block_size); |
841 | - $ciphertext.= $iv; |
|
842 | - $len-= $block_size; |
|
843 | - $i+= $block_size; |
|
841 | + $ciphertext .= $iv; |
|
842 | + $len -= $block_size; |
|
843 | + $i += $block_size; |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | $iv = @mcrypt_generic($this->ecb, $iv); |
850 | 850 | $block = $iv ^ substr($plaintext, -$len); |
851 | 851 | $iv = substr_replace($iv, $block, 0, $len); |
852 | - $ciphertext.= $block; |
|
852 | + $ciphertext .= $block; |
|
853 | 853 | $pos = $len; |
854 | 854 | } |
855 | 855 | |
@@ -879,17 +879,17 @@ discard block |
||
879 | 879 | $ciphertext = ''; |
880 | 880 | switch ($this->mode) { |
881 | 881 | case self::MODE_ECB: |
882 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
883 | - $ciphertext.= $this->_encryptBlock(substr($plaintext, $i, $block_size)); |
|
882 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
883 | + $ciphertext .= $this->_encryptBlock(substr($plaintext, $i, $block_size)); |
|
884 | 884 | } |
885 | 885 | break; |
886 | 886 | case self::MODE_CBC: |
887 | 887 | $xor = $this->encryptIV; |
888 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
888 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
889 | 889 | $block = substr($plaintext, $i, $block_size); |
890 | 890 | $block = $this->_encryptBlock($block ^ $xor); |
891 | 891 | $xor = $block; |
892 | - $ciphertext.= $block; |
|
892 | + $ciphertext .= $block; |
|
893 | 893 | } |
894 | 894 | if ($this->continuousBuffer) { |
895 | 895 | $this->encryptIV = $xor; |
@@ -898,27 +898,27 @@ discard block |
||
898 | 898 | case self::MODE_CTR: |
899 | 899 | $xor = $this->encryptIV; |
900 | 900 | if (strlen($buffer['ciphertext'])) { |
901 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
901 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
902 | 902 | $block = substr($plaintext, $i, $block_size); |
903 | 903 | if (strlen($block) > strlen($buffer['ciphertext'])) { |
904 | - $buffer['ciphertext'].= $this->_encryptBlock($xor); |
|
904 | + $buffer['ciphertext'] .= $this->_encryptBlock($xor); |
|
905 | 905 | } |
906 | 906 | $this->_increment_str($xor); |
907 | 907 | $key = Strings::shift($buffer['ciphertext'], $block_size); |
908 | - $ciphertext.= $block ^ $key; |
|
908 | + $ciphertext .= $block ^ $key; |
|
909 | 909 | } |
910 | 910 | } else { |
911 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
911 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
912 | 912 | $block = substr($plaintext, $i, $block_size); |
913 | 913 | $key = $this->_encryptBlock($xor); |
914 | 914 | $this->_increment_str($xor); |
915 | - $ciphertext.= $block ^ $key; |
|
915 | + $ciphertext .= $block ^ $key; |
|
916 | 916 | } |
917 | 917 | } |
918 | 918 | if ($this->continuousBuffer) { |
919 | 919 | $this->encryptIV = $xor; |
920 | 920 | if ($start = strlen($plaintext) % $block_size) { |
921 | - $buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext']; |
|
921 | + $buffer['ciphertext'] = substr($key, $start).$buffer['ciphertext']; |
|
922 | 922 | } |
923 | 923 | } |
924 | 924 | break; |
@@ -939,11 +939,11 @@ discard block |
||
939 | 939 | $max = $block_size - $pos; |
940 | 940 | if ($len >= $max) { |
941 | 941 | $i = $max; |
942 | - $len-= $max; |
|
942 | + $len -= $max; |
|
943 | 943 | $pos = 0; |
944 | 944 | } else { |
945 | 945 | $i = $len; |
946 | - $pos+= $len; |
|
946 | + $pos += $len; |
|
947 | 947 | $len = 0; |
948 | 948 | } |
949 | 949 | // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize |
@@ -952,41 +952,41 @@ discard block |
||
952 | 952 | } |
953 | 953 | while ($len >= $block_size) { |
954 | 954 | $iv = $this->_encryptBlock($iv) ^ substr($plaintext, $i, $block_size); |
955 | - $ciphertext.= $iv; |
|
956 | - $len-= $block_size; |
|
957 | - $i+= $block_size; |
|
955 | + $ciphertext .= $iv; |
|
956 | + $len -= $block_size; |
|
957 | + $i += $block_size; |
|
958 | 958 | } |
959 | 959 | if ($len) { |
960 | 960 | $iv = $this->_encryptBlock($iv); |
961 | 961 | $block = $iv ^ substr($plaintext, $i); |
962 | 962 | $iv = substr_replace($iv, $block, 0, $len); |
963 | - $ciphertext.= $block; |
|
963 | + $ciphertext .= $block; |
|
964 | 964 | $pos = $len; |
965 | 965 | } |
966 | 966 | break; |
967 | 967 | case self::MODE_OFB: |
968 | 968 | $xor = $this->encryptIV; |
969 | 969 | if (strlen($buffer['xor'])) { |
970 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
970 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
971 | 971 | $block = substr($plaintext, $i, $block_size); |
972 | 972 | if (strlen($block) > strlen($buffer['xor'])) { |
973 | 973 | $xor = $this->_encryptBlock($xor); |
974 | - $buffer['xor'].= $xor; |
|
974 | + $buffer['xor'] .= $xor; |
|
975 | 975 | } |
976 | 976 | $key = Strings::shift($buffer['xor'], $block_size); |
977 | - $ciphertext.= $block ^ $key; |
|
977 | + $ciphertext .= $block ^ $key; |
|
978 | 978 | } |
979 | 979 | } else { |
980 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
980 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
981 | 981 | $xor = $this->_encryptBlock($xor); |
982 | - $ciphertext.= substr($plaintext, $i, $block_size) ^ $xor; |
|
982 | + $ciphertext .= substr($plaintext, $i, $block_size) ^ $xor; |
|
983 | 983 | } |
984 | 984 | $key = $xor; |
985 | 985 | } |
986 | 986 | if ($this->continuousBuffer) { |
987 | 987 | $this->encryptIV = $xor; |
988 | 988 | if ($start = strlen($plaintext) % $block_size) { |
989 | - $buffer['xor'] = substr($key, $start) . $buffer['xor']; |
|
989 | + $buffer['xor'] = substr($key, $start).$buffer['xor']; |
|
990 | 990 | } |
991 | 991 | } |
992 | 992 | break; |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | function decrypt($ciphertext) |
1015 | 1015 | { |
1016 | 1016 | if ($this->paddable && strlen($ciphertext) % $this->block_size) { |
1017 | - throw new \LengthException('The ciphertext length (' . strlen($ciphertext) . ') needs to be a multiple of the block size (' . $this->block_size . ')'); |
|
1017 | + throw new \LengthException('The ciphertext length ('.strlen($ciphertext).') needs to be a multiple of the block size ('.$this->block_size.')'); |
|
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | if ($this->engine === self::ENGINE_OPENSSL) { |
@@ -1028,14 +1028,14 @@ discard block |
||
1028 | 1028 | break; |
1029 | 1029 | case self::MODE_ECB: |
1030 | 1030 | if (!defined('OPENSSL_RAW_DATA')) { |
1031 | - $ciphertext.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $this->key, true); |
|
1031 | + $ciphertext .= openssl_encrypt('', $this->cipher_name_openssl_ecb, $this->key, true); |
|
1032 | 1032 | } |
1033 | 1033 | $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options); |
1034 | 1034 | break; |
1035 | 1035 | case self::MODE_CBC: |
1036 | 1036 | if (!defined('OPENSSL_RAW_DATA')) { |
1037 | 1037 | $padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$this->block_size); |
1038 | - $ciphertext.= substr(openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true), 0, $this->block_size); |
|
1038 | + $ciphertext .= substr(openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true), 0, $this->block_size); |
|
1039 | 1039 | $offset = 2 * $this->block_size; |
1040 | 1040 | } else { |
1041 | 1041 | $offset = $this->block_size; |
@@ -1066,11 +1066,11 @@ discard block |
||
1066 | 1066 | $max = $this->block_size - $pos; |
1067 | 1067 | if ($len >= $max) { |
1068 | 1068 | $i = $max; |
1069 | - $len-= $max; |
|
1069 | + $len -= $max; |
|
1070 | 1070 | $pos = 0; |
1071 | 1071 | } else { |
1072 | 1072 | $i = $len; |
1073 | - $pos+= $len; |
|
1073 | + $pos += $len; |
|
1074 | 1074 | $len = 0; |
1075 | 1075 | } |
1076 | 1076 | // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $this->blocksize |
@@ -1080,16 +1080,16 @@ discard block |
||
1080 | 1080 | } |
1081 | 1081 | $overflow = $len % $this->block_size; |
1082 | 1082 | if ($overflow) { |
1083 | - $plaintext.= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
1083 | + $plaintext .= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
1084 | 1084 | if ($len - $overflow) { |
1085 | 1085 | $iv = substr($ciphertext, -$overflow - $this->block_size, -$overflow); |
1086 | 1086 | } |
1087 | 1087 | $iv = openssl_encrypt(str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
1088 | - $plaintext.= $iv ^ substr($ciphertext, -$overflow); |
|
1088 | + $plaintext .= $iv ^ substr($ciphertext, -$overflow); |
|
1089 | 1089 | $iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow); |
1090 | 1090 | $pos = $overflow; |
1091 | 1091 | } elseif ($len) { |
1092 | - $plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
1092 | + $plaintext .= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); |
|
1093 | 1093 | $iv = substr($ciphertext, -$this->block_size); |
1094 | 1094 | } |
1095 | 1095 | break; |
@@ -1122,11 +1122,11 @@ discard block |
||
1122 | 1122 | $max = $block_size - $pos; |
1123 | 1123 | if ($len >= $max) { |
1124 | 1124 | $i = $max; |
1125 | - $len-= $max; |
|
1125 | + $len -= $max; |
|
1126 | 1126 | $pos = 0; |
1127 | 1127 | } else { |
1128 | 1128 | $i = $len; |
1129 | - $pos+= $len; |
|
1129 | + $pos += $len; |
|
1130 | 1130 | $len = 0; |
1131 | 1131 | } |
1132 | 1132 | // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize |
@@ -1135,13 +1135,13 @@ discard block |
||
1135 | 1135 | } |
1136 | 1136 | if ($len >= $block_size) { |
1137 | 1137 | $cb = substr($ciphertext, $i, $len - $len % $block_size); |
1138 | - $plaintext.= @mcrypt_generic($this->ecb, $iv . $cb) ^ $cb; |
|
1138 | + $plaintext .= @mcrypt_generic($this->ecb, $iv.$cb) ^ $cb; |
|
1139 | 1139 | $iv = substr($cb, -$block_size); |
1140 | - $len%= $block_size; |
|
1140 | + $len %= $block_size; |
|
1141 | 1141 | } |
1142 | 1142 | if ($len) { |
1143 | 1143 | $iv = @mcrypt_generic($this->ecb, $iv); |
1144 | - $plaintext.= $iv ^ substr($ciphertext, -$len); |
|
1144 | + $plaintext .= $iv ^ substr($ciphertext, -$len); |
|
1145 | 1145 | $iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len); |
1146 | 1146 | $pos = $len; |
1147 | 1147 | } |
@@ -1173,15 +1173,15 @@ discard block |
||
1173 | 1173 | $plaintext = ''; |
1174 | 1174 | switch ($this->mode) { |
1175 | 1175 | case self::MODE_ECB: |
1176 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1177 | - $plaintext.= $this->_decryptBlock(substr($ciphertext, $i, $block_size)); |
|
1176 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1177 | + $plaintext .= $this->_decryptBlock(substr($ciphertext, $i, $block_size)); |
|
1178 | 1178 | } |
1179 | 1179 | break; |
1180 | 1180 | case self::MODE_CBC: |
1181 | 1181 | $xor = $this->decryptIV; |
1182 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1182 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1183 | 1183 | $block = substr($ciphertext, $i, $block_size); |
1184 | - $plaintext.= $this->_decryptBlock($block) ^ $xor; |
|
1184 | + $plaintext .= $this->_decryptBlock($block) ^ $xor; |
|
1185 | 1185 | $xor = $block; |
1186 | 1186 | } |
1187 | 1187 | if ($this->continuousBuffer) { |
@@ -1191,27 +1191,27 @@ discard block |
||
1191 | 1191 | case self::MODE_CTR: |
1192 | 1192 | $xor = $this->decryptIV; |
1193 | 1193 | if (strlen($buffer['ciphertext'])) { |
1194 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1194 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1195 | 1195 | $block = substr($ciphertext, $i, $block_size); |
1196 | 1196 | if (strlen($block) > strlen($buffer['ciphertext'])) { |
1197 | - $buffer['ciphertext'].= $this->_encryptBlock($xor); |
|
1197 | + $buffer['ciphertext'] .= $this->_encryptBlock($xor); |
|
1198 | 1198 | $this->_increment_str($xor); |
1199 | 1199 | } |
1200 | 1200 | $key = Strings::shift($buffer['ciphertext'], $block_size); |
1201 | - $plaintext.= $block ^ $key; |
|
1201 | + $plaintext .= $block ^ $key; |
|
1202 | 1202 | } |
1203 | 1203 | } else { |
1204 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1204 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1205 | 1205 | $block = substr($ciphertext, $i, $block_size); |
1206 | 1206 | $key = $this->_encryptBlock($xor); |
1207 | 1207 | $this->_increment_str($xor); |
1208 | - $plaintext.= $block ^ $key; |
|
1208 | + $plaintext .= $block ^ $key; |
|
1209 | 1209 | } |
1210 | 1210 | } |
1211 | 1211 | if ($this->continuousBuffer) { |
1212 | 1212 | $this->decryptIV = $xor; |
1213 | 1213 | if ($start = strlen($ciphertext) % $block_size) { |
1214 | - $buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext']; |
|
1214 | + $buffer['ciphertext'] = substr($key, $start).$buffer['ciphertext']; |
|
1215 | 1215 | } |
1216 | 1216 | } |
1217 | 1217 | break; |
@@ -1230,11 +1230,11 @@ discard block |
||
1230 | 1230 | $max = $block_size - $pos; |
1231 | 1231 | if ($len >= $max) { |
1232 | 1232 | $i = $max; |
1233 | - $len-= $max; |
|
1233 | + $len -= $max; |
|
1234 | 1234 | $pos = 0; |
1235 | 1235 | } else { |
1236 | 1236 | $i = $len; |
1237 | - $pos+= $len; |
|
1237 | + $pos += $len; |
|
1238 | 1238 | $len = 0; |
1239 | 1239 | } |
1240 | 1240 | // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize |
@@ -1244,14 +1244,14 @@ discard block |
||
1244 | 1244 | while ($len >= $block_size) { |
1245 | 1245 | $iv = $this->_encryptBlock($iv); |
1246 | 1246 | $cb = substr($ciphertext, $i, $block_size); |
1247 | - $plaintext.= $iv ^ $cb; |
|
1247 | + $plaintext .= $iv ^ $cb; |
|
1248 | 1248 | $iv = $cb; |
1249 | - $len-= $block_size; |
|
1250 | - $i+= $block_size; |
|
1249 | + $len -= $block_size; |
|
1250 | + $i += $block_size; |
|
1251 | 1251 | } |
1252 | 1252 | if ($len) { |
1253 | 1253 | $iv = $this->_encryptBlock($iv); |
1254 | - $plaintext.= $iv ^ substr($ciphertext, $i); |
|
1254 | + $plaintext .= $iv ^ substr($ciphertext, $i); |
|
1255 | 1255 | $iv = substr_replace($iv, substr($ciphertext, $i), 0, $len); |
1256 | 1256 | $pos = $len; |
1257 | 1257 | } |
@@ -1259,26 +1259,26 @@ discard block |
||
1259 | 1259 | case self::MODE_OFB: |
1260 | 1260 | $xor = $this->decryptIV; |
1261 | 1261 | if (strlen($buffer['xor'])) { |
1262 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1262 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1263 | 1263 | $block = substr($ciphertext, $i, $block_size); |
1264 | 1264 | if (strlen($block) > strlen($buffer['xor'])) { |
1265 | 1265 | $xor = $this->_encryptBlock($xor); |
1266 | - $buffer['xor'].= $xor; |
|
1266 | + $buffer['xor'] .= $xor; |
|
1267 | 1267 | } |
1268 | 1268 | $key = Strings::shift($buffer['xor'], $block_size); |
1269 | - $plaintext.= $block ^ $key; |
|
1269 | + $plaintext .= $block ^ $key; |
|
1270 | 1270 | } |
1271 | 1271 | } else { |
1272 | - for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { |
|
1272 | + for ($i = 0; $i < strlen($ciphertext); $i += $block_size) { |
|
1273 | 1273 | $xor = $this->_encryptBlock($xor); |
1274 | - $plaintext.= substr($ciphertext, $i, $block_size) ^ $xor; |
|
1274 | + $plaintext .= substr($ciphertext, $i, $block_size) ^ $xor; |
|
1275 | 1275 | } |
1276 | 1276 | $key = $xor; |
1277 | 1277 | } |
1278 | 1278 | if ($this->continuousBuffer) { |
1279 | 1279 | $this->decryptIV = $xor; |
1280 | 1280 | if ($start = strlen($ciphertext) % $block_size) { |
1281 | - $buffer['xor'] = substr($key, $start) . $buffer['xor']; |
|
1281 | + $buffer['xor'] = substr($key, $start).$buffer['xor']; |
|
1282 | 1282 | } |
1283 | 1283 | } |
1284 | 1284 | break; |
@@ -1331,30 +1331,30 @@ discard block |
||
1331 | 1331 | if ($this->openssl_emulate_ctr) { |
1332 | 1332 | $xor = $encryptIV; |
1333 | 1333 | if (strlen($buffer['ciphertext'])) { |
1334 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
1334 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
1335 | 1335 | $block = substr($plaintext, $i, $block_size); |
1336 | 1336 | if (strlen($block) > strlen($buffer['ciphertext'])) { |
1337 | 1337 | $result = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); |
1338 | 1338 | $result = !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result; |
1339 | - $buffer['ciphertext'].= $result; |
|
1339 | + $buffer['ciphertext'] .= $result; |
|
1340 | 1340 | } |
1341 | 1341 | $this->_increment_str($xor); |
1342 | 1342 | $otp = Strings::shift($buffer['ciphertext'], $block_size); |
1343 | - $ciphertext.= $block ^ $otp; |
|
1343 | + $ciphertext .= $block ^ $otp; |
|
1344 | 1344 | } |
1345 | 1345 | } else { |
1346 | - for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { |
|
1346 | + for ($i = 0; $i < strlen($plaintext); $i += $block_size) { |
|
1347 | 1347 | $block = substr($plaintext, $i, $block_size); |
1348 | 1348 | $otp = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); |
1349 | 1349 | $otp = !defined('OPENSSL_RAW_DATA') ? substr($otp, 0, -$this->block_size) : $otp; |
1350 | 1350 | $this->_increment_str($xor); |
1351 | - $ciphertext.= $block ^ $otp; |
|
1351 | + $ciphertext .= $block ^ $otp; |
|
1352 | 1352 | } |
1353 | 1353 | } |
1354 | 1354 | if ($this->continuousBuffer) { |
1355 | 1355 | $encryptIV = $xor; |
1356 | 1356 | if ($start = strlen($plaintext) % $block_size) { |
1357 | - $buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext']; |
|
1357 | + $buffer['ciphertext'] = substr($key, $start).$buffer['ciphertext']; |
|
1358 | 1358 | } |
1359 | 1359 | } |
1360 | 1360 | |
@@ -1373,15 +1373,15 @@ discard block |
||
1373 | 1373 | $overflow = strlen($plaintext) % $block_size; |
1374 | 1374 | if ($overflow) { |
1375 | 1375 | $plaintext2 = $this->_string_pop($plaintext, $overflow); // ie. trim $plaintext to a multiple of $block_size and put rest of $plaintext in $plaintext2 |
1376 | - $encrypted = openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1376 | + $encrypted = openssl_encrypt($plaintext.str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1377 | 1377 | $temp = $this->_string_pop($encrypted, $block_size); |
1378 | - $ciphertext.= $encrypted . ($plaintext2 ^ $temp); |
|
1378 | + $ciphertext .= $encrypted.($plaintext2 ^ $temp); |
|
1379 | 1379 | if ($this->continuousBuffer) { |
1380 | 1380 | $buffer['ciphertext'] = substr($temp, $overflow); |
1381 | 1381 | $encryptIV = $temp; |
1382 | 1382 | } |
1383 | 1383 | } elseif (!strlen($buffer['ciphertext'])) { |
1384 | - $ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1384 | + $ciphertext .= openssl_encrypt($plaintext.str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1385 | 1385 | $temp = $this->_string_pop($ciphertext, $block_size); |
1386 | 1386 | if ($this->continuousBuffer) { |
1387 | 1387 | $encryptIV = $temp; |
@@ -1389,7 +1389,7 @@ discard block |
||
1389 | 1389 | } |
1390 | 1390 | if ($this->continuousBuffer) { |
1391 | 1391 | if (!defined('OPENSSL_RAW_DATA')) { |
1392 | - $encryptIV.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $key, $this->openssl_options); |
|
1392 | + $encryptIV .= openssl_encrypt('', $this->cipher_name_openssl_ecb, $key, $this->openssl_options); |
|
1393 | 1393 | } |
1394 | 1394 | $encryptIV = openssl_decrypt($encryptIV, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); |
1395 | 1395 | if ($overflow) { |
@@ -1433,12 +1433,12 @@ discard block |
||
1433 | 1433 | |
1434 | 1434 | if (strlen($plaintext)) { |
1435 | 1435 | if ($overflow) { |
1436 | - $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1436 | + $ciphertext .= openssl_encrypt(substr($plaintext, 0, -$overflow).str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); |
|
1437 | 1437 | $xor = $this->_string_pop($ciphertext, $block_size); |
1438 | 1438 | if ($this->continuousBuffer) { |
1439 | 1439 | $encryptIV = $xor; |
1440 | 1440 | } |
1441 | - $ciphertext.= Strings::shift($xor, $overflow) ^ substr($plaintext, -$overflow); |
|
1441 | + $ciphertext .= Strings::shift($xor, $overflow) ^ substr($plaintext, -$overflow); |
|
1442 | 1442 | if ($this->continuousBuffer) { |
1443 | 1443 | $buffer['xor'] = $xor; |
1444 | 1444 | } |
@@ -1954,7 +1954,7 @@ discard block |
||
1954 | 1954 | */ |
1955 | 1955 | function _increment_str(&$var) |
1956 | 1956 | { |
1957 | - for ($i = 4; $i <= strlen($var); $i+= 4) { |
|
1957 | + for ($i = 4; $i <= strlen($var); $i += 4) { |
|
1958 | 1958 | $temp = substr($var, -$i, 4); |
1959 | 1959 | switch ($temp) { |
1960 | 1960 | case "\xFF\xFF\xFF\xFF": |
@@ -2168,9 +2168,9 @@ discard block |
||
2168 | 2168 | $block_size = $this->block_size; |
2169 | 2169 | |
2170 | 2170 | // optional |
2171 | - $init_crypt = isset($cipher_code['init_crypt']) ? $cipher_code['init_crypt'] : ''; |
|
2172 | - $init_encrypt = isset($cipher_code['init_encrypt']) ? $cipher_code['init_encrypt'] : ''; |
|
2173 | - $init_decrypt = isset($cipher_code['init_decrypt']) ? $cipher_code['init_decrypt'] : ''; |
|
2171 | + $init_crypt = isset($cipher_code['init_crypt']) ? $cipher_code['init_crypt'] : ''; |
|
2172 | + $init_encrypt = isset($cipher_code['init_encrypt']) ? $cipher_code['init_encrypt'] : ''; |
|
2173 | + $init_decrypt = isset($cipher_code['init_decrypt']) ? $cipher_code['init_decrypt'] : ''; |
|
2174 | 2174 | // required |
2175 | 2175 | $encrypt_block = $cipher_code['encrypt_block']; |
2176 | 2176 | $decrypt_block = $cipher_code['decrypt_block']; |
@@ -2180,7 +2180,7 @@ discard block |
||
2180 | 2180 | // for encrypt- and decryption. |
2181 | 2181 | switch ($this->mode) { |
2182 | 2182 | case self::MODE_ECB: |
2183 | - $encrypt = $init_encrypt . ' |
|
2183 | + $encrypt = $init_encrypt.' |
|
2184 | 2184 | $_ciphertext = ""; |
2185 | 2185 | $_plaintext_len = strlen($_text); |
2186 | 2186 | |
@@ -2193,7 +2193,7 @@ discard block |
||
2193 | 2193 | return $_ciphertext; |
2194 | 2194 | '; |
2195 | 2195 | |
2196 | - $decrypt = $init_decrypt . ' |
|
2196 | + $decrypt = $init_decrypt.' |
|
2197 | 2197 | $_plaintext = ""; |
2198 | 2198 | $_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0)); |
2199 | 2199 | $_ciphertext_len = strlen($_text); |
@@ -2208,7 +2208,7 @@ discard block |
||
2208 | 2208 | '; |
2209 | 2209 | break; |
2210 | 2210 | case self::MODE_CTR: |
2211 | - $encrypt = $init_encrypt . ' |
|
2211 | + $encrypt = $init_encrypt.' |
|
2212 | 2212 | $_ciphertext = ""; |
2213 | 2213 | $_plaintext_len = strlen($_text); |
2214 | 2214 | $_xor = $self->encryptIV; |
@@ -2245,7 +2245,7 @@ discard block |
||
2245 | 2245 | return $_ciphertext; |
2246 | 2246 | '; |
2247 | 2247 | |
2248 | - $decrypt = $init_encrypt . ' |
|
2248 | + $decrypt = $init_encrypt.' |
|
2249 | 2249 | $_plaintext = ""; |
2250 | 2250 | $_ciphertext_len = strlen($_text); |
2251 | 2251 | $_xor = $self->decryptIV; |
@@ -2284,7 +2284,7 @@ discard block |
||
2284 | 2284 | '; |
2285 | 2285 | break; |
2286 | 2286 | case self::MODE_CFB: |
2287 | - $encrypt = $init_encrypt . ' |
|
2287 | + $encrypt = $init_encrypt.' |
|
2288 | 2288 | $_ciphertext = ""; |
2289 | 2289 | $_buffer = &$self->enbuffer; |
2290 | 2290 | |
@@ -2332,7 +2332,7 @@ discard block |
||
2332 | 2332 | return $_ciphertext; |
2333 | 2333 | '; |
2334 | 2334 | |
2335 | - $decrypt = $init_encrypt . ' |
|
2335 | + $decrypt = $init_encrypt.' |
|
2336 | 2336 | $_plaintext = ""; |
2337 | 2337 | $_buffer = &$self->debuffer; |
2338 | 2338 | |
@@ -2383,7 +2383,7 @@ discard block |
||
2383 | 2383 | '; |
2384 | 2384 | break; |
2385 | 2385 | case self::MODE_OFB: |
2386 | - $encrypt = $init_encrypt . ' |
|
2386 | + $encrypt = $init_encrypt.' |
|
2387 | 2387 | $_ciphertext = ""; |
2388 | 2388 | $_plaintext_len = strlen($_text); |
2389 | 2389 | $_xor = $self->encryptIV; |
@@ -2419,7 +2419,7 @@ discard block |
||
2419 | 2419 | return $_ciphertext; |
2420 | 2420 | '; |
2421 | 2421 | |
2422 | - $decrypt = $init_encrypt . ' |
|
2422 | + $decrypt = $init_encrypt.' |
|
2423 | 2423 | $_plaintext = ""; |
2424 | 2424 | $_ciphertext_len = strlen($_text); |
2425 | 2425 | $_xor = $self->decryptIV; |
@@ -2456,12 +2456,12 @@ discard block |
||
2456 | 2456 | '; |
2457 | 2457 | break; |
2458 | 2458 | case self::MODE_STREAM: |
2459 | - $encrypt = $init_encrypt . ' |
|
2459 | + $encrypt = $init_encrypt.' |
|
2460 | 2460 | $_ciphertext = ""; |
2461 | 2461 | '.$encrypt_block.' |
2462 | 2462 | return $_ciphertext; |
2463 | 2463 | '; |
2464 | - $decrypt = $init_decrypt . ' |
|
2464 | + $decrypt = $init_decrypt.' |
|
2465 | 2465 | $_plaintext = ""; |
2466 | 2466 | '.$decrypt_block.' |
2467 | 2467 | return $_plaintext; |
@@ -2469,7 +2469,7 @@ discard block |
||
2469 | 2469 | break; |
2470 | 2470 | // case self::MODE_CBC: |
2471 | 2471 | default: |
2472 | - $encrypt = $init_encrypt . ' |
|
2472 | + $encrypt = $init_encrypt.' |
|
2473 | 2473 | $_ciphertext = ""; |
2474 | 2474 | $_plaintext_len = strlen($_text); |
2475 | 2475 | |
@@ -2488,7 +2488,7 @@ discard block |
||
2488 | 2488 | return $_ciphertext; |
2489 | 2489 | '; |
2490 | 2490 | |
2491 | - $decrypt = $init_decrypt . ' |
|
2491 | + $decrypt = $init_decrypt.' |
|
2492 | 2492 | $_plaintext = ""; |
2493 | 2493 | $_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0)); |
2494 | 2494 | $_ciphertext_len = strlen($_text); |
@@ -2512,7 +2512,7 @@ discard block |
||
2512 | 2512 | } |
2513 | 2513 | |
2514 | 2514 | // Create the $inline function and return its name as string. Ready to run! |
2515 | - return create_function('$_action, &$self, $_text', $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }'); |
|
2515 | + return create_function('$_action, &$self, $_text', $init_crypt.'if ($_action == "encrypt") { '.$encrypt.' } else { '.$decrypt.' }'); |
|
2516 | 2516 | } |
2517 | 2517 | |
2518 | 2518 | /** |
@@ -2559,15 +2559,15 @@ discard block |
||
2559 | 2559 | $hash = hash('whirlpool', $hash, true); |
2560 | 2560 | $result .= $t ^ $hash; |
2561 | 2561 | } |
2562 | - return $result . hash('whirlpool', $hash, true); |
|
2562 | + return $result.hash('whirlpool', $hash, true); |
|
2563 | 2563 | default: |
2564 | 2564 | $len = strlen($bytes); |
2565 | - for ($i = 0; $i < $len; $i+=20) { |
|
2565 | + for ($i = 0; $i < $len; $i += 20) { |
|
2566 | 2566 | $t = substr($bytes, $i, 20); |
2567 | 2567 | $hash = sha1($hash, true); |
2568 | 2568 | $result .= $t ^ $hash; |
2569 | 2569 | } |
2570 | - return $result . sha1($hash, true); |
|
2570 | + return $result.sha1($hash, true); |
|
2571 | 2571 | } |
2572 | 2572 | } |
2573 | 2573 | } |
@@ -147,7 +147,7 @@ |
||
147 | 147 | * As set by the constructor or by the setHash() method. |
148 | 148 | * |
149 | 149 | * @access public |
150 | - * @return string |
|
150 | + * @return integer |
|
151 | 151 | */ |
152 | 152 | function getHash() |
153 | 153 | { |
@@ -336,16 +336,16 @@ |
||
336 | 336 | // Extend the sixteen 32-bit words into eighty 32-bit words |
337 | 337 | for ($i = 16; $i < 80; $i++) { |
338 | 338 | $temp = array( |
339 | - $w[$i - 15]->bitwise_rightRotate(1), |
|
340 | - $w[$i - 15]->bitwise_rightRotate(8), |
|
341 | - $w[$i - 15]->bitwise_rightShift(7) |
|
339 | + $w[$i - 15]->bitwise_rightRotate(1), |
|
340 | + $w[$i - 15]->bitwise_rightRotate(8), |
|
341 | + $w[$i - 15]->bitwise_rightShift(7) |
|
342 | 342 | ); |
343 | 343 | $s0 = $temp[0]->bitwise_xor($temp[1]); |
344 | 344 | $s0 = $s0->bitwise_xor($temp[2]); |
345 | 345 | $temp = array( |
346 | - $w[$i - 2]->bitwise_rightRotate(19), |
|
347 | - $w[$i - 2]->bitwise_rightRotate(61), |
|
348 | - $w[$i - 2]->bitwise_rightShift(6) |
|
346 | + $w[$i - 2]->bitwise_rightRotate(19), |
|
347 | + $w[$i - 2]->bitwise_rightRotate(61), |
|
348 | + $w[$i - 2]->bitwise_rightShift(6) |
|
349 | 349 | ); |
350 | 350 | $s1 = $temp[0]->bitwise_xor($temp[1]); |
351 | 351 | $s1 = $s1->bitwise_xor($temp[2]); |
@@ -209,8 +209,7 @@ discard block |
||
209 | 209 | array( |
210 | 210 | '22312194FC2BF72C', '9F555FA3C84C64C2', '2393B86B6F53B151', '963877195940EABD', |
211 | 211 | '96283EE2A88EFFE3', 'BE5E1E2553863992', '2B0199FC2C85B8AA', '0EB72DDC81C52CA2' |
212 | - ) : |
|
213 | - array( |
|
212 | + ) : array( |
|
214 | 213 | '8C3D37C819544DA2', '73E1996689DCD4D6', '1DFAB7AE32FF9C82', '679DD514582F9FCF', |
215 | 214 | '0F6D2B697BD44DA8', '77E36F7304C48942', '3F9D85A86A1D36C8', '1112E6AD91D692A1' |
216 | 215 | ); |
@@ -244,19 +243,18 @@ discard block |
||
244 | 243 | -- http://tools.ietf.org/html/rfc2104#section-2 */ |
245 | 244 | $key = strlen($this->key) > $this->b ? self::_sha512($this->key, $this->initial) : $this->key; |
246 | 245 | |
247 | - $key = str_pad($this->key, 128, chr(0)); // step 1 |
|
248 | - $temp = $this->ipad ^ $this->key; // step 2 |
|
249 | - $temp .= $text; // step 3 |
|
250 | - $temp = self::_sha512($temp, $this->initial); // step 4 |
|
251 | - $output = $this->opad ^ $this->key; // step 5 |
|
252 | - $output.= $temp; // step 6 |
|
246 | + $key = str_pad($this->key, 128, chr(0)); // step 1 |
|
247 | + $temp = $this->ipad ^ $this->key; // step 2 |
|
248 | + $temp .= $text; // step 3 |
|
249 | + $temp = self::_sha512($temp, $this->initial); // step 4 |
|
250 | + $output = $this->opad ^ $this->key; // step 5 |
|
251 | + $output .= $temp; // step 6 |
|
253 | 252 | $output = self::_sha512($output, $this->initial); // step 7 |
254 | 253 | |
255 | 254 | return substr($output, 0, $this->length); |
256 | 255 | } |
257 | 256 | $output = !empty($this->key) || is_string($this->key) ? |
258 | - hash_hmac($this->hash, $text, $this->key, true) : |
|
259 | - hash($this->hash, $text, true); |
|
257 | + hash_hmac($this->hash, $text, $this->key, true) : hash($this->hash, $text, true); |
|
260 | 258 | |
261 | 259 | return strlen($output) > $this->length |
262 | 260 | ? substr($output, 0, $this->length) |
@@ -318,10 +316,10 @@ discard block |
||
318 | 316 | // Pre-processing |
319 | 317 | $length = strlen($m); |
320 | 318 | // to round to nearest 112 mod 128, we'll add 128 - (length + (128 - 112)) % 128 |
321 | - $m.= str_repeat(chr(0), 128 - (($length + 16) & 0x7F)); |
|
319 | + $m .= str_repeat(chr(0), 128 - (($length + 16) & 0x7F)); |
|
322 | 320 | $m[$length] = chr(0x80); |
323 | 321 | // we don't support hashing strings 512MB long |
324 | - $m.= pack('N4', 0, 0, 0, $length << 3); |
|
322 | + $m .= pack('N4', 0, 0, 0, $length << 3); |
|
325 | 323 | |
326 | 324 | // Process the message in successive 1024-bit chunks |
327 | 325 | $chunks = str_split($m, 128); |
@@ -425,8 +423,8 @@ discard block |
||
425 | 423 | |
426 | 424 | // Produce the final hash value (big-endian) |
427 | 425 | // (\phpseclib\Crypt\Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here) |
428 | - $temp = $hash[0]->toBytes() . $hash[1]->toBytes() . $hash[2]->toBytes() . $hash[3]->toBytes() . |
|
429 | - $hash[4]->toBytes() . $hash[5]->toBytes() . $hash[6]->toBytes() . $hash[7]->toBytes(); |
|
426 | + $temp = $hash[0]->toBytes().$hash[1]->toBytes().$hash[2]->toBytes().$hash[3]->toBytes(). |
|
427 | + $hash[4]->toBytes().$hash[5]->toBytes().$hash[6]->toBytes().$hash[7]->toBytes(); |
|
430 | 428 | |
431 | 429 | return $temp; |
432 | 430 | } |
@@ -201,8 +201,8 @@ |
||
201 | 201 | * Keys can be between 1 and 256 bytes long. |
202 | 202 | * |
203 | 203 | * @access public |
204 | - * @param int $length |
|
205 | 204 | * @throws \LengthException if the key length is invalid |
205 | + * @param string $key |
|
206 | 206 | */ |
207 | 207 | function setKey($key) |
208 | 208 | { |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | function setKeyLength($length) |
188 | 188 | { |
189 | 189 | if ($length < 8 || $length > 2048) { |
190 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 256 bytes are supported'); |
|
190 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys between 1 and 256 bytes are supported'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | $this->key_length = $length >> 3; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | $length = strlen($key); |
210 | 210 | if ($length < 1 || $length > 256) { |
211 | - throw new \LengthException('Key size of ' . $length . ' bytes is not supported by RC4. Keys must be between 1 and 256 bytes long'); |
|
211 | + throw new \LengthException('Key size of '.$length.' bytes is not supported by RC4. Keys must be between 1 and 256 bytes long'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | parent::setKey($key); |
@@ -402,7 +402,6 @@ discard block |
||
402 | 402 | * @access public |
403 | 403 | * @param int $bits |
404 | 404 | * @param int $timeout |
405 | - * @param array $p |
|
406 | 405 | */ |
407 | 406 | static function createKey($bits = 2048, $timeout = false, $partial = array()) |
408 | 407 | { |
@@ -608,7 +607,7 @@ discard block |
||
608 | 607 | * @see self::load() |
609 | 608 | * @param string $fullname |
610 | 609 | * @access public |
611 | - * @return bool |
|
610 | + * @return boolean|null |
|
612 | 611 | */ |
613 | 612 | static function addFileFormat($fullname) |
614 | 613 | { |
@@ -750,7 +749,7 @@ discard block |
||
750 | 749 | * |
751 | 750 | * @see self::load() |
752 | 751 | * @access public |
753 | - * @return mixed |
|
752 | + * @return false|string |
|
754 | 753 | */ |
755 | 754 | function getLoadedFormat() |
756 | 755 | { |
@@ -971,7 +970,7 @@ discard block |
||
971 | 970 | * @access public |
972 | 971 | * @param string $algorithm The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned |
973 | 972 | * for invalid values. |
974 | - * @return mixed |
|
973 | + * @return false|string |
|
975 | 974 | */ |
976 | 975 | function getPublicKeyFingerprint($algorithm = 'md5') |
977 | 976 | { |
@@ -1154,7 +1153,6 @@ discard block |
||
1154 | 1153 | * of the hash function Hash) and 0. |
1155 | 1154 | * |
1156 | 1155 | * @access public |
1157 | - * @param int $format |
|
1158 | 1156 | */ |
1159 | 1157 | function setSaltLength($sLen) |
1160 | 1158 | { |
@@ -1169,7 +1167,7 @@ discard block |
||
1169 | 1167 | * @access private |
1170 | 1168 | * @param bool|\phpseclib\Math\BigInteger $x |
1171 | 1169 | * @param int $xLen |
1172 | - * @return bool|string |
|
1170 | + * @return false|string |
|
1173 | 1171 | */ |
1174 | 1172 | function _i2osp($x, $xLen) |
1175 | 1173 | { |
@@ -1405,7 +1403,6 @@ discard block |
||
1405 | 1403 | * |
1406 | 1404 | * @access private |
1407 | 1405 | * @param string $mgfSeed |
1408 | - * @param int $mgfLen |
|
1409 | 1406 | * @return string |
1410 | 1407 | */ |
1411 | 1408 | function _mgf1($mgfSeed, $maskLen) |
@@ -1494,7 +1491,7 @@ discard block |
||
1494 | 1491 | * @access private |
1495 | 1492 | * @param string $c |
1496 | 1493 | * @param string $l |
1497 | - * @return bool|string |
|
1494 | + * @return false|string |
|
1498 | 1495 | */ |
1499 | 1496 | function _rsaes_oaep_decrypt($c, $l = '') |
1500 | 1497 | { |
@@ -1548,7 +1545,7 @@ discard block |
||
1548 | 1545 | * |
1549 | 1546 | * @access private |
1550 | 1547 | * @param string $m |
1551 | - * @return bool|string |
|
1548 | + * @return false|string |
|
1552 | 1549 | * @throws \OutOfBoundsException if strlen($m) > $this->k |
1553 | 1550 | */ |
1554 | 1551 | function _raw_encrypt($m) |
@@ -1571,7 +1568,7 @@ discard block |
||
1571 | 1568 | * @param string $m |
1572 | 1569 | * @param bool $pkcs15_compat optional |
1573 | 1570 | * @throws \OutOfBoundsException if strlen($m) > $this->k - 11 |
1574 | - * @return bool|string |
|
1571 | + * @return false|string |
|
1575 | 1572 | */ |
1576 | 1573 | function _rsaes_pkcs1_v1_5_encrypt($m, $pkcs15_compat = false) |
1577 | 1574 | { |
@@ -1629,7 +1626,7 @@ discard block |
||
1629 | 1626 | * |
1630 | 1627 | * @access private |
1631 | 1628 | * @param string $c |
1632 | - * @return bool|string |
|
1629 | + * @return false|string |
|
1633 | 1630 | */ |
1634 | 1631 | function _rsaes_pkcs1_v1_5_decrypt($c) |
1635 | 1632 | { |
@@ -1711,7 +1708,7 @@ discard block |
||
1711 | 1708 | * @param string $m |
1712 | 1709 | * @param string $em |
1713 | 1710 | * @param int $emBits |
1714 | - * @return string |
|
1711 | + * @return boolean |
|
1715 | 1712 | */ |
1716 | 1713 | function _emsa_pss_verify($m, $em, $emBits) |
1717 | 1714 | { |
@@ -1756,7 +1753,7 @@ discard block |
||
1756 | 1753 | * |
1757 | 1754 | * @access private |
1758 | 1755 | * @param string $m |
1759 | - * @return bool|string |
|
1756 | + * @return false|string |
|
1760 | 1757 | */ |
1761 | 1758 | function _rsassa_pss_sign($m) |
1762 | 1759 | { |
@@ -1876,7 +1873,7 @@ discard block |
||
1876 | 1873 | * @access private |
1877 | 1874 | * @param string $m |
1878 | 1875 | * @throws \LengthException if the RSA modulus is too short |
1879 | - * @return bool|string |
|
1876 | + * @return false|string |
|
1880 | 1877 | */ |
1881 | 1878 | function _rsassa_pkcs1_v1_5_sign($m) |
1882 | 1879 | { |
@@ -2058,7 +2055,7 @@ discard block |
||
2058 | 2055 | * @access public |
2059 | 2056 | * @param string $plaintext |
2060 | 2057 | * @param int $padding optional |
2061 | - * @return bool|string |
|
2058 | + * @return false|string |
|
2062 | 2059 | * @throws \LengthException if the RSA modulus is too short |
2063 | 2060 | */ |
2064 | 2061 | function encrypt($plaintext, $padding = self::PADDING_OAEP) |
@@ -2080,9 +2077,8 @@ discard block |
||
2080 | 2077 | * |
2081 | 2078 | * @see self::encrypt() |
2082 | 2079 | * @access public |
2083 | - * @param string $plaintext |
|
2084 | 2080 | * @param int $padding optional |
2085 | - * @return bool|string |
|
2081 | + * @return false|string |
|
2086 | 2082 | */ |
2087 | 2083 | function decrypt($ciphertext, $padding = self::PADDING_OAEP) |
2088 | 2084 | { |
@@ -2130,7 +2126,7 @@ discard block |
||
2130 | 2126 | * @param string $message |
2131 | 2127 | * @param string $signature |
2132 | 2128 | * @param int $padding optional |
2133 | - * @return bool |
|
2129 | + * @return boolean|string |
|
2134 | 2130 | */ |
2135 | 2131 | function verify($message, $signature, $padding = self::PADDING_PSS) |
2136 | 2132 | { |
@@ -350,15 +350,15 @@ discard block |
||
350 | 350 | static function _initialize_static_variables() |
351 | 351 | { |
352 | 352 | if (!isset(self::$zero)) { |
353 | - self::$zero= new BigInteger(0); |
|
353 | + self::$zero = new BigInteger(0); |
|
354 | 354 | self::$one = new BigInteger(1); |
355 | - self::$configFile = __DIR__ . '/../openssl.cnf'; |
|
355 | + self::$configFile = __DIR__.'/../openssl.cnf'; |
|
356 | 356 | |
357 | 357 | if (self::$fileFormats === false) { |
358 | 358 | self::$fileFormats = array(); |
359 | - foreach (glob(__DIR__ . '/RSA/*.php') as $file) { |
|
359 | + foreach (glob(__DIR__.'/RSA/*.php') as $file) { |
|
360 | 360 | $name = pathinfo($file, PATHINFO_FILENAME); |
361 | - $type = 'phpseclib\Crypt\RSA\\' . $name; |
|
361 | + $type = 'phpseclib\Crypt\RSA\\'.$name; |
|
362 | 362 | $meta = new \ReflectionClass($type); |
363 | 363 | if (!$meta->isAbstract()) { |
364 | 364 | self::$fileFormats[strtolower($name)] = $type; |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | do { |
499 | 499 | for ($i = $i0; $i <= $num_primes; $i++) { |
500 | 500 | if ($timeout !== false) { |
501 | - $timeout-= time() - $start; |
|
501 | + $timeout -= time() - $start; |
|
502 | 502 | $start = time(); |
503 | 503 | if ($timeout <= 0) { |
504 | 504 | return array( |
@@ -1416,7 +1416,7 @@ discard block |
||
1416 | 1416 | $count = ceil($maskLen / $this->mgfHLen); |
1417 | 1417 | for ($i = 0; $i < $count; $i++) { |
1418 | 1418 | $c = pack('N', $i); |
1419 | - $t.= $this->mgfHash->hash($mgfSeed . $c); |
|
1419 | + $t .= $this->mgfHash->hash($mgfSeed.$c); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | return substr($t, 0, $maskLen); |
@@ -1451,13 +1451,13 @@ discard block |
||
1451 | 1451 | |
1452 | 1452 | $lHash = $this->hash->hash($l); |
1453 | 1453 | $ps = str_repeat(chr(0), $this->k - $mLen - 2 * $this->hLen - 2); |
1454 | - $db = $lHash . $ps . chr(1) . $m; |
|
1454 | + $db = $lHash.$ps.chr(1).$m; |
|
1455 | 1455 | $seed = Random::string($this->hLen); |
1456 | 1456 | $dbMask = $this->_mgf1($seed, $this->k - $this->hLen - 1); |
1457 | 1457 | $maskedDB = $db ^ $dbMask; |
1458 | 1458 | $seedMask = $this->_mgf1($maskedDB, $this->hLen); |
1459 | 1459 | $maskedSeed = $seed ^ $seedMask; |
1460 | - $em = chr(0) . $maskedSeed . $maskedDB; |
|
1460 | + $em = chr(0).$maskedSeed.$maskedDB; |
|
1461 | 1461 | |
1462 | 1462 | // RSA encryption |
1463 | 1463 | |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | while (strlen($ps) != $psLen) { |
1591 | 1591 | $temp = Random::string($psLen - strlen($ps)); |
1592 | 1592 | $temp = str_replace("\x00", '', $temp); |
1593 | - $ps.= $temp; |
|
1593 | + $ps .= $temp; |
|
1594 | 1594 | } |
1595 | 1595 | $type = 2; |
1596 | 1596 | // see the comments of _rsaes_pkcs1_v1_5_decrypt() to understand why this is being done |
@@ -1599,7 +1599,7 @@ discard block |
||
1599 | 1599 | // "The padding string PS shall consist of k-3-||D|| octets. ... for block type 01, they shall have value FF" |
1600 | 1600 | $ps = str_repeat("\xFF", $psLen); |
1601 | 1601 | } |
1602 | - $em = chr(0) . chr($type) . $ps . chr(0) . $m; |
|
1602 | + $em = chr(0).chr($type).$ps.chr(0).$m; |
|
1603 | 1603 | |
1604 | 1604 | // RSA encryption |
1605 | 1605 | $m = $this->_os2ip($em); |
@@ -1690,14 +1690,14 @@ discard block |
||
1690 | 1690 | } |
1691 | 1691 | |
1692 | 1692 | $salt = Random::string($sLen); |
1693 | - $m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt; |
|
1693 | + $m2 = "\0\0\0\0\0\0\0\0".$mHash.$salt; |
|
1694 | 1694 | $h = $this->hash->hash($m2); |
1695 | 1695 | $ps = str_repeat(chr(0), $emLen - $sLen - $this->hLen - 2); |
1696 | - $db = $ps . chr(1) . $salt; |
|
1696 | + $db = $ps.chr(1).$salt; |
|
1697 | 1697 | $dbMask = $this->_mgf1($h, $emLen - $this->hLen - 1); |
1698 | 1698 | $maskedDB = $db ^ $dbMask; |
1699 | 1699 | $maskedDB[0] = ~chr(0xFF << ($emBits & 7)) & $maskedDB[0]; |
1700 | - $em = $maskedDB . $h . chr(0xBC); |
|
1700 | + $em = $maskedDB.$h.chr(0xBC); |
|
1701 | 1701 | |
1702 | 1702 | return $em; |
1703 | 1703 | } |
@@ -1744,7 +1744,7 @@ discard block |
||
1744 | 1744 | return false; |
1745 | 1745 | } |
1746 | 1746 | $salt = substr($db, $temp + 1); // should be $sLen long |
1747 | - $m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt; |
|
1747 | + $m2 = "\0\0\0\0\0\0\0\0".$mHash.$salt; |
|
1748 | 1748 | $h2 = $this->hash->hash($m2); |
1749 | 1749 | return $this->_equals($h, $h2); |
1750 | 1750 | } |
@@ -1854,7 +1854,7 @@ discard block |
||
1854 | 1854 | case 'sha512/256': |
1855 | 1855 | $t = "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x06\x05\x00\x04\x20"; |
1856 | 1856 | } |
1857 | - $t.= $h; |
|
1857 | + $t .= $h; |
|
1858 | 1858 | $tLen = strlen($t); |
1859 | 1859 | |
1860 | 1860 | if ($emLen < $tLen + 11) { |
@@ -19,7 +19,6 @@ |
||
19 | 19 | use ParagonIE\ConstantTime\Hex; |
20 | 20 | use phpseclib\Crypt\Common\BlockCipher; |
21 | 21 | use phpseclib\Crypt\AES; |
22 | -use phpseclib\Crypt\Base; |
|
23 | 22 | use phpseclib\Crypt\DES; |
24 | 23 | use phpseclib\Crypt\TripleDES; |
25 | 24 | use phpseclib\Math\BigInteger; |
@@ -150,7 +150,7 @@ |
||
150 | 150 | $symkey = ''; |
151 | 151 | $iv = substr($iv, 0, 8); |
152 | 152 | while (strlen($symkey) < $length) { |
153 | - $symkey.= md5($symkey . $password . $iv, true); |
|
153 | + $symkey .= md5($symkey.$password.$iv, true); |
|
154 | 154 | } |
155 | 155 | return substr($symkey, 0, $length); |
156 | 156 | } |
@@ -26,10 +26,8 @@ |
||
26 | 26 | |
27 | 27 | use ParagonIE\ConstantTime\Base64; |
28 | 28 | use ParagonIE\ConstantTime\Hex; |
29 | -use phpseclib\Crypt\AES; |
|
30 | 29 | use phpseclib\Crypt\DES; |
31 | 30 | use phpseclib\Crypt\Random; |
32 | -use phpseclib\Crypt\TripleDES; |
|
33 | 31 | use phpseclib\Math\BigInteger; |
34 | 32 | use phpseclib\Common\Functions\ASN1; |
35 | 33 |
@@ -123,15 +123,15 @@ |
||
123 | 123 | $cipher->setIV($iv); |
124 | 124 | $iv = strtoupper(Hex::encode($iv)); |
125 | 125 | $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" . |
126 | - "Proc-Type: 4,ENCRYPTED\r\n" . |
|
127 | - "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",$iv\r\n" . |
|
128 | - "\r\n" . |
|
129 | - chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64) . |
|
130 | - '-----END RSA PRIVATE KEY-----'; |
|
126 | + "Proc-Type: 4,ENCRYPTED\r\n" . |
|
127 | + "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",$iv\r\n" . |
|
128 | + "\r\n" . |
|
129 | + chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64) . |
|
130 | + '-----END RSA PRIVATE KEY-----'; |
|
131 | 131 | } else { |
132 | 132 | $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" . |
133 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
134 | - '-----END RSA PRIVATE KEY-----'; |
|
133 | + chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
134 | + '-----END RSA PRIVATE KEY-----'; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return $RSAPrivateKey; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | // coefficient INTEGER -- ti |
108 | 108 | // } |
109 | 109 | $OtherPrimeInfo = pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true)); |
110 | - $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true)); |
|
111 | - $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true)); |
|
112 | - $OtherPrimeInfos.= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo); |
|
110 | + $OtherPrimeInfo .= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true)); |
|
111 | + $OtherPrimeInfo .= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true)); |
|
112 | + $OtherPrimeInfos .= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo); |
|
113 | 113 | } |
114 | - $RSAPrivateKey.= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos); |
|
114 | + $RSAPrivateKey .= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | $cipher->setKey(self::generateSymmetricKey($password, $iv, $cipher->getKeyLength() >> 3)); |
123 | 123 | $cipher->setIV($iv); |
124 | 124 | $iv = strtoupper(Hex::encode($iv)); |
125 | - $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" . |
|
126 | - "Proc-Type: 4,ENCRYPTED\r\n" . |
|
127 | - "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",$iv\r\n" . |
|
128 | - "\r\n" . |
|
129 | - chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64) . |
|
125 | + $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n". |
|
126 | + "Proc-Type: 4,ENCRYPTED\r\n". |
|
127 | + "DEK-Info: ".self::$defaultEncryptionAlgorithm.",$iv\r\n". |
|
128 | + "\r\n". |
|
129 | + chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64). |
|
130 | 130 | '-----END RSA PRIVATE KEY-----'; |
131 | 131 | } else { |
132 | - $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" . |
|
133 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
132 | + $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n". |
|
133 | + chunk_split(Base64::encode($RSAPrivateKey), 64). |
|
134 | 134 | '-----END RSA PRIVATE KEY-----'; |
135 | 135 | } |
136 | 136 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | $components['publicExponent'] |
169 | 169 | ); |
170 | 170 | |
171 | - $RSAPublicKey = "-----BEGIN RSA PUBLIC KEY-----\r\n" . |
|
172 | - chunk_split(Base64::encode($RSAPublicKey), 64) . |
|
171 | + $RSAPublicKey = "-----BEGIN RSA PUBLIC KEY-----\r\n". |
|
172 | + chunk_split(Base64::encode($RSAPublicKey), 64). |
|
173 | 173 | '-----END RSA PUBLIC KEY-----'; |
174 | 174 | |
175 | 175 | return $RSAPublicKey; |