From 0565700461d5cbac83559129becb8eda34d6d559 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 17 Jul 2015 23:23:24 -0500 Subject: [PATCH] Crypt/Base: use the built-in spl exceptions instead --- phpseclib/Crypt/Base.php | 11 ++++---- phpseclib/Exception/InvalidInputException.php | 26 ------------------- .../Exception/KeyGenerationException.php | 26 ------------------- 3 files changed, 6 insertions(+), 57 deletions(-) delete mode 100644 phpseclib/Exception/InvalidInputException.php delete mode 100644 phpseclib/Exception/KeyGenerationException.php diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index 51d68026..2021c00c 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -37,8 +37,6 @@ namespace phpseclib\Crypt; use phpseclib\Crypt\Hash; -use phpseclib\Exception\InvalidInputException; -use phpseclib\Exception\KeyGenerationException; /** * Base Class for all \phpseclib\Crypt\* cipher classes @@ -547,6 +545,7 @@ abstract class Base * @see Crypt/Hash.php * @param String $password * @param optional String $method + * @throws \LengthException if pbkdf1 is being used and the derived key length exceeds the hash length * @return Boolean * @access public * @internal Could, but not must, extend by the child Crypt_* class @@ -581,7 +580,7 @@ abstract class Base $hashObj = new Hash(); $hashObj->setHash($hash); if ($dkLen > $hashObj->getLength()) { - throw new KeyGenerationException('Derived key too long'); + throw new \LengthException('Derived key length cannot be longer than the hash length'); } $t = $password . $salt; for ($i = 0; $i < $count; ++$i) { @@ -1769,6 +1768,7 @@ abstract class Base * * @see \phpseclib\Crypt\Base::_unpad() * @param String $text + * @throws \LengthException if padding is disabled and the plaintext's length is not a multiple of the block size * @access private * @return String */ @@ -1780,7 +1780,7 @@ abstract class Base if ($length % $this->block_size == 0) { return $text; } else { - throw new InvalidInputException("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size}). Try enabling padding."); + throw new \LengthException("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size}). Try enabling padding."); } } @@ -1797,6 +1797,7 @@ abstract class Base * * @see \phpseclib\Crypt\Base::_pad() * @param String $text + * @throws \LengthException if the ciphertext's length is not a multiple of the block size * @access private * @return String */ @@ -1809,7 +1810,7 @@ abstract class Base $length = ord($text[strlen($text) - 1]); if (!$length || $length > $this->block_size) { - throw new InvalidInputException("The ciphertext has an invalid padding length ($length) compared to the block size ({$this->block_size})"); + throw new \LengthException("The ciphertext has an invalid padding length ($length) compared to the block size ({$this->block_size})"); } return substr($text, 0, -$length); diff --git a/phpseclib/Exception/InvalidInputException.php b/phpseclib/Exception/InvalidInputException.php deleted file mode 100644 index 5dfd8305..00000000 --- a/phpseclib/Exception/InvalidInputException.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @copyright 2015 Jim Wigginton - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link http://phpseclib.sourceforge.net - */ - -namespace phpseclib\Exception; - -/** - * InvalidInputException - * - * @package InvalidInputException - * @author Jim Wigginton - */ -class InvalidInputException extends \Exception -{ -} diff --git a/phpseclib/Exception/KeyGenerationException.php b/phpseclib/Exception/KeyGenerationException.php deleted file mode 100644 index d8171ef4..00000000 --- a/phpseclib/Exception/KeyGenerationException.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @copyright 2015 Jim Wigginton - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link http://phpseclib.sourceforge.net - */ - -namespace phpseclib\Exception; - -/** - * KeyGenerationException - * - * @package InvalidInputException - * @author Jim Wigginton - */ -class KeyGenerationException extends \Exception -{ -}