Crypt/Base: use the built-in spl exceptions instead

This commit is contained in:
terrafrost 2015-07-17 23:23:24 -05:00
parent 51700b6065
commit 0565700461
3 changed files with 6 additions and 57 deletions

View File

@ -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);

View File

@ -1,26 +0,0 @@
<?php
/**
* InvalidInputException
*
* PHP version 5
*
* @category Exception
* @package InvalidInputException
* @author Jim Wigginton <terrafrost@php.net>
* @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 <terrafrost@php.net>
*/
class InvalidInputException extends \Exception
{
}

View File

@ -1,26 +0,0 @@
<?php
/**
* KeyGenerationException
*
* PHP version 5
*
* @category Exception
* @package KeyGenerationException
* @author Jim Wigginton <terrafrost@php.net>
* @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 <terrafrost@php.net>
*/
class KeyGenerationException extends \Exception
{
}