From b532d52afc61415abf64d7ddfa7dc277884feae0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 7 Aug 2012 15:33:27 +0000 Subject: [PATCH] Added exceptions for BAS64-encoded data --- .gitattributes | 3 ++ inc/classes/exceptions/base64/.htaccess | 1 + .../class_Base64EncodingBadException.php | 47 +++++++++++++++++++ .../class_Base64EncodingModuloException.php | 46 ++++++++++++++++++ inc/classes/exceptions/class_ | 6 +-- 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 inc/classes/exceptions/base64/.htaccess create mode 100644 inc/classes/exceptions/base64/class_Base64EncodingBadException.php create mode 100644 inc/classes/exceptions/base64/class_Base64EncodingModuloException.php diff --git a/.gitattributes b/.gitattributes index f63ad9f0..6b590104 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,9 @@ inc/classes/exceptions/actions/.htaccess svneol=native#text/plain inc/classes/exceptions/actions/class_InvalidActionException.php svneol=native#text/plain inc/classes/exceptions/auth/.htaccess svneol=native#text/plain inc/classes/exceptions/auth/class_UserAuthorizationException.php svneol=native#text/plain +inc/classes/exceptions/base64/.htaccess svneol=native#text/plain +inc/classes/exceptions/base64/class_Base64EncodingBadException.php svneol=native#text/plain +inc/classes/exceptions/base64/class_Base64EncodingModuloException.php svneol=native#text/plain inc/classes/exceptions/class_ svneol=native#text/plain inc/classes/exceptions/class_FrameworkException.php svneol=native#text/plain inc/classes/exceptions/compressor/.htaccess svneol=native#text/plain diff --git a/inc/classes/exceptions/base64/.htaccess b/inc/classes/exceptions/base64/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/exceptions/base64/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/base64/class_Base64EncodingBadException.php b/inc/classes/exceptions/base64/class_Base64EncodingBadException.php new file mode 100644 index 00000000..239a6c90 --- /dev/null +++ b/inc/classes/exceptions/base64/class_Base64EncodingBadException.php @@ -0,0 +1,47 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class Base64EncodingBadException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $message Error message + * @param $code Error code + * @return void + */ + public function __construct (array $messageArray, $code) { + // Construct message + $message = sprintf("[%s:%d] Raw data %s contains invalid characters for BASE64-encoding.", + $messageArray[0]->__toString(), + $this->getLine(), + $messageArray[1] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/base64/class_Base64EncodingModuloException.php b/inc/classes/exceptions/base64/class_Base64EncodingModuloException.php new file mode 100644 index 00000000..6f766aab --- /dev/null +++ b/inc/classes/exceptions/base64/class_Base64EncodingModuloException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class Base64EncodingModuloException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageArray, $code) { + // Construct message + $message = sprintf("[%s:%d] Data length %s modulo 4 is not zero.", + $messageArray[0]->__toString(), + $this->getLine(), + strlen($messageArray[1]) + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/class_ b/inc/classes/exceptions/class_ index a270bd29..c3eab3b8 100644 --- a/inc/classes/exceptions/class_ +++ b/inc/classes/exceptions/class_ @@ -25,11 +25,11 @@ class ???Exception extends FrameworkException { /** * The super constructor for all exceptions * - * @param $message Error message - * @param $code Error code + * @param $message Error message + * @param $code Error code * @return void */ - public function __construct($message, $code) { + public function __construct ($message, $code) { // Call parent exception constructor parent::__construct($message, $code); } -- 2.39.5