Throw exception instead of triggering error, and added base exception interface

This commit is contained in:
Jack Worman 2022-08-15 09:10:28 -05:00
parent 3f3de53503
commit a8f30f516a
17 changed files with 39 additions and 17 deletions

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class BadConfigurationException extends \RuntimeException class BadConfigurationException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class BadDecryptionException extends \RuntimeException class BadDecryptionException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class BadModeException extends \RuntimeException class BadModeException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class ConnectionClosedException extends \RuntimeException class ConnectionClosedException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace phpseclib3\Exception;
/**
* Used to mark exceptions originating from this library.
*/
interface ExceptionInterface
{
}

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class FileNotFoundException extends \RuntimeException class FileNotFoundException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class InconsistentSetupException extends \RuntimeException class InconsistentSetupException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class InsufficientSetupException extends \RuntimeException class InsufficientSetupException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class NoKeyLoadedException extends \RuntimeException class NoKeyLoadedException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class NoSupportedAlgorithmsException extends \RuntimeException class NoSupportedAlgorithmsException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace phpseclib3\Exception;
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class UnableToConnectException extends \RuntimeException class UnableToConnectException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class UnsupportedAlgorithmException extends \RuntimeException class UnsupportedAlgorithmException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class UnsupportedCurveException extends \RuntimeException class UnsupportedCurveException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class UnsupportedFormatException extends \RuntimeException class UnsupportedFormatException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
* *
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class UnsupportedOperationException extends \RuntimeException class UnsupportedOperationException extends \RuntimeException implements ExceptionInterface
{ {
} }

View File

@ -67,6 +67,7 @@ use phpseclib3\Crypt\Twofish;
use phpseclib3\Exception\ConnectionClosedException; use phpseclib3\Exception\ConnectionClosedException;
use phpseclib3\Exception\InsufficientSetupException; use phpseclib3\Exception\InsufficientSetupException;
use phpseclib3\Exception\NoSupportedAlgorithmsException; use phpseclib3\Exception\NoSupportedAlgorithmsException;
use phpseclib3\Exception\RuntimeException;
use phpseclib3\Exception\UnableToConnectException; use phpseclib3\Exception\UnableToConnectException;
use phpseclib3\Exception\UnsupportedAlgorithmException; use phpseclib3\Exception\UnsupportedAlgorithmException;
use phpseclib3\Exception\UnsupportedCurveException; use phpseclib3\Exception\UnsupportedCurveException;
@ -3264,18 +3265,18 @@ class SSH2
$cmf = ord($payload[0]); $cmf = ord($payload[0]);
$cm = $cmf & 0x0F; $cm = $cmf & 0x0F;
if ($cm != 8) { // deflate if ($cm != 8) { // deflate
trigger_error("Only CM = 8 ('deflate') is supported ($cm)"); throw new UnsupportedAlgorithmException("Only CM = 8 ('deflate') is supported ($cm)");
} }
$cinfo = ($cmf & 0xF0) >> 4; $cinfo = ($cmf & 0xF0) >> 4;
if ($cinfo > 7) { if ($cinfo > 7) {
trigger_error("CINFO above 7 is not allowed ($cinfo)"); throw new RuntimeException("CINFO above 7 is not allowed ($cinfo)");
} }
$windowSize = 1 << ($cinfo + 8); $windowSize = 1 << ($cinfo + 8);
$flg = ord($payload[1]); $flg = ord($payload[1]);
//$fcheck = $flg && 0x0F; //$fcheck = $flg && 0x0F;
if ((($cmf << 8) | $flg) % 31) { if ((($cmf << 8) | $flg) % 31) {
trigger_error('fcheck failed'); throw new RuntimeException('fcheck failed');
} }
$fdict = boolval($flg & 0x20); $fdict = boolval($flg & 0x20);
$flevel = ($flg & 0xC0) >> 6; $flevel = ($flg & 0xC0) >> 6;