mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 03:29:20 +03:00
Changed some InvalidArgumentException to the better suited ValueError
This commit is contained in:
parent
4d66c02190
commit
4a2de54c3e
15 changed files with 72 additions and 58 deletions
|
|
@ -56,7 +56,7 @@ trait Folders
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -64,7 +64,7 @@ trait Folders
|
|||
public function FolderDelete(string $sFolderName) : void
|
||||
{
|
||||
if (!$sFolderName || 'INBOX' === $sFolderName) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$oInfo = $this->hasCapability('IMAP4rev2')
|
||||
|
|
@ -360,7 +360,7 @@ trait Folders
|
|||
}
|
||||
|
||||
if (!\strlen(\trim($sFolderName))) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$aSelectParams = array();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use MailSo\Imap\Enumerations\StoreAction;
|
|||
trait Messages
|
||||
{
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -35,7 +35,7 @@ trait Messages
|
|||
public function FetchIterate(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : iterable
|
||||
{
|
||||
if (!\strlen(\trim($sIndexRange))) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError('$sIndexRange is empty'), \LOG_ERR);
|
||||
}
|
||||
|
||||
$aReturn = array();
|
||||
|
|
@ -138,14 +138,21 @@ trait Messages
|
|||
* @param resource $rMessageStream
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
*/
|
||||
public function MessageAppendStream(string $sFolderName, $rMessageStream, int $iStreamSize, array $aFlagsList = null, int $iDateTime = 0) : ?int
|
||||
{
|
||||
if (!\is_resource($rMessageStream) || !\strlen($sFolderName) || 1 > $iStreamSize) {
|
||||
throw new \InvalidArgumentException;
|
||||
if (!\is_resource($rMessageStream)) {
|
||||
throw new \InvalidArgumentException('$rMessageStream must be a resource');
|
||||
}
|
||||
if (!\strlen($sFolderName)) {
|
||||
throw new \ValueError('$sFolderName is empty');
|
||||
}
|
||||
if (1 > $iStreamSize) {
|
||||
throw new \ValueError('$iStreamSize must be higher then 0');
|
||||
}
|
||||
|
||||
$aParams = array(
|
||||
|
|
@ -202,7 +209,7 @@ trait Messages
|
|||
*/
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -210,7 +217,7 @@ trait Messages
|
|||
public function MessageCopy(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : ResponseCollection
|
||||
{
|
||||
if (!$sFromFolder || !$sToFolder || !\count($oRange)) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError, \LOG_ERR);
|
||||
}
|
||||
|
||||
$this->FolderSelect($sFromFolder);
|
||||
|
|
@ -222,7 +229,7 @@ trait Messages
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -230,7 +237,7 @@ trait Messages
|
|||
public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : void
|
||||
{
|
||||
if (!$sFromFolder || !$sToFolder || !\count($oRange)) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError, \LOG_ERR);
|
||||
}
|
||||
|
||||
if ($this->hasCapability('MOVE')) {
|
||||
|
|
@ -246,7 +253,7 @@ trait Messages
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -254,7 +261,7 @@ trait Messages
|
|||
public function MessageDelete(string $sFolder, SequenceSet $oRange, bool $bExpungeAll = false) : void
|
||||
{
|
||||
if (!$sFolder || !\count($oRange)) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError, \LOG_ERR);
|
||||
}
|
||||
|
||||
$this->FolderSelect($sFolder);
|
||||
|
|
@ -279,6 +286,7 @@ trait Messages
|
|||
* @param resource $rMessageStream
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ trait Metadata
|
|||
{
|
||||
if ($this->hasCapability('METADATA')) {
|
||||
if (!$aEntries) {
|
||||
throw new \InvalidArgumentException('Wrong argument for SETMETADATA command');
|
||||
throw new \ValueError('Wrong argument for SETMETADATA command');
|
||||
}
|
||||
|
||||
$arguments = [$this->EscapeFolderName($sFolderName)];
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ class Folder implements \JsonSerializable
|
|||
public ?Responses\ACL $myRights = null;
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
*/
|
||||
function __construct(string $sFullName, string $sDelimiter = null, array $aAttributes = array())
|
||||
{
|
||||
if (!\strlen($sFullName)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
$this->FullName = $sFullName;
|
||||
$this->setDelimiter($sDelimiter);
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -123,7 +123,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||
|
||||
if (!\strlen($sLogin) || !\strlen($sPassword)) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \UnexpectedValueException, \LOG_ERR);
|
||||
}
|
||||
|
||||
$type = '';
|
||||
|
|
@ -421,7 +421,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
@ -430,7 +430,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
{
|
||||
$sCommand = \trim($sCommand);
|
||||
if (!\strlen($sCommand)) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError, \LOG_ERR);
|
||||
}
|
||||
|
||||
$this->IsConnected(true);
|
||||
|
|
@ -454,7 +454,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\*
|
||||
* @throws \MailSo\Imap\Exceptions\*
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class MailClient
|
|||
public function Message(string $sFolderName, int $iIndex, bool $bIndexIsUid = true, ?\MailSo\Cache\CacheClient $oCacher = null) : ?Message
|
||||
{
|
||||
if (1 > $iIndex) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$this->oImapClient->FolderExamine($sFolderName);
|
||||
|
|
@ -187,7 +187,7 @@ class MailClient
|
|||
public function MessageMimeStream($mCallback, string $sFolderName, int $iIndex, string $sMimeIndex) : bool
|
||||
{
|
||||
if (!\is_callable($mCallback)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$this->oImapClient->FolderExamine($sFolderName);
|
||||
|
|
@ -278,7 +278,7 @@ class MailClient
|
|||
public function MessageAppendFile(string $sMessageFileName, string $sFolderToSave, array $aAppendFlags = null) : int
|
||||
{
|
||||
if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$iMessageStreamSize = \filesize($sMessageFileName);
|
||||
|
|
@ -687,7 +687,7 @@ class MailClient
|
|||
public function MessageList(MessageListParams $oParams) : MessageCollection
|
||||
{
|
||||
if (0 > $oParams->iOffset || 0 > $oParams->iLimit || 999 < $oParams->iLimit) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$sSearch = \trim($oParams->sSearch);
|
||||
|
|
@ -707,7 +707,7 @@ class MailClient
|
|||
$oParams->bUseThreads = $oParams->bUseThreads && $this->oImapClient->CapabilityValue('THREAD');
|
||||
// && ($this->oImapClient->hasCapability('THREAD=REFS') || $this->oImapClient->hasCapability('THREAD=REFERENCES') || $this->oImapClient->hasCapability('THREAD=ORDEREDSUBJECT'));
|
||||
if ($oParams->iThreadUid && !$oParams->bUseThreads) {
|
||||
throw new \InvalidArgumentException('THREAD not supported');
|
||||
throw new \ValueError('THREAD not supported');
|
||||
}
|
||||
|
||||
if (!$oInfo->MESSAGES || $oParams->iOffset > $oInfo->MESSAGES) {
|
||||
|
|
@ -851,7 +851,7 @@ class MailClient
|
|||
public function FindMessageUidByMessageId(string $sFolderName, string $sMessageId) : ?int
|
||||
{
|
||||
if (!\strlen($sMessageId)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$this->oImapClient->FolderExamine($sFolderName);
|
||||
|
|
@ -892,7 +892,7 @@ class MailClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
*/
|
||||
public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : ?\MailSo\Imap\Folder
|
||||
{
|
||||
|
|
@ -900,7 +900,7 @@ class MailClient
|
|||
$sFolderParentFullName = \trim($sFolderParentFullName);
|
||||
|
||||
if (!\strlen($sFolderNameInUtf8)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
if (!\strlen($sDelimiter) || \strlen($sFolderParentFullName)) {
|
||||
|
|
@ -976,13 +976,13 @@ class MailClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
*/
|
||||
protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bSubscribe) : self
|
||||
{
|
||||
if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName)) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$oSubscribedFolders = array();
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ class Email implements \JsonSerializable
|
|||
private string $sDkimStatus = Enumerations\DkimStatus::NONE;
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
*/
|
||||
function __construct(string $sEmail, string $sDisplayName = '')
|
||||
{
|
||||
if (!\strlen(\trim($sEmail)) && !\strlen(\trim($sDisplayName))) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
|
||||
|
|
@ -39,13 +39,13 @@ class Email implements \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
*/
|
||||
public static function Parse(string $sEmailAddress) : self
|
||||
{
|
||||
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
|
||||
if (!\strlen(\trim($sEmailAddress))) {
|
||||
throw new \InvalidArgumentException;
|
||||
throw new \ValueError;
|
||||
}
|
||||
|
||||
$sName = '';
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class EmailCollection extends \MailSo\Base\Collection
|
|||
|
||||
$iEmailStartPos = $iCurrentPos + 1;
|
||||
}
|
||||
catch (\InvalidArgumentException $oException)
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ class EmailCollection extends \MailSo\Base\Collection
|
|||
Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
|
||||
);
|
||||
}
|
||||
catch (\InvalidArgumentException $oException) {}
|
||||
catch (\Throwable $oException) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ abstract class NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
* @throws \MailSo\RuntimeException
|
||||
* @throws \MailSo\Net\Exceptions\SocketAlreadyConnectedException
|
||||
* @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException
|
||||
|
|
@ -80,7 +80,7 @@ abstract class NetClient
|
|||
{
|
||||
$oSettings->host = \trim($oSettings->host);
|
||||
if (!\strlen($oSettings->host) || 0 > $oSettings->port || 65535 < $oSettings->port) {
|
||||
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
|
||||
$this->writeLogException(new \ValueError, \LOG_ERR);
|
||||
}
|
||||
|
||||
if ($this->IsConnected()) {
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ class SieveClient extends \MailSo\Net\NetClient
|
|||
$this->StartTLS();
|
||||
return $this->Login($oSettings);
|
||||
}
|
||||
// $this->writeLogException(new \UnexpectedValueException('No supported SASL mechanism found'), \LOG_ERR);
|
||||
$this->writeLogException(new \MailSo\Sieve\Exceptions\LoginException, \LOG_ERR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -772,7 +772,7 @@ class PdoAddressBook
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \ValueError
|
||||
*/
|
||||
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array
|
||||
{
|
||||
|
|
@ -782,7 +782,7 @@ class PdoAddressBook
|
|||
|
||||
$sSearch = \trim($sSearch);
|
||||
if (!\strlen($sSearch)) {
|
||||
throw new \InvalidArgumentException('Empty Search argument');
|
||||
throw new \ValueError('Empty Search argument');
|
||||
}
|
||||
|
||||
$sTypes = \implode(',', static::$aSearchInFields);
|
||||
|
|
@ -936,6 +936,9 @@ class PdoAddressBook
|
|||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ValueError
|
||||
*/
|
||||
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool
|
||||
{
|
||||
if (1 > $this->iUserID) {
|
||||
|
|
@ -959,7 +962,7 @@ class PdoAddressBook
|
|||
});
|
||||
|
||||
if (!\count($aEmailsObjects)) {
|
||||
throw new \InvalidArgumentException('Empty Emails argument');
|
||||
throw new \ValueError('Empty Emails argument');
|
||||
}
|
||||
|
||||
$aExists = array();
|
||||
|
|
@ -1302,13 +1305,16 @@ SQLITEINITIAL;
|
|||
return $this->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ValueError
|
||||
*/
|
||||
protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int
|
||||
{
|
||||
static $aCache = array();
|
||||
|
||||
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
|
||||
if (empty($sEmail)) {
|
||||
throw new \InvalidArgumentException('Empty Email argument');
|
||||
throw new \ValueError('Empty Email argument');
|
||||
}
|
||||
|
||||
if ($bCache && isset($aCache[$sEmail])) {
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ abstract class Crypt
|
|||
) /* : string|false */
|
||||
{
|
||||
if (!$data || !$iv) {
|
||||
throw new \InvalidArgumentException('$data or $iv is empty string');
|
||||
throw new \ValueError('$data or $iv is empty string');
|
||||
}
|
||||
if (!\is_callable('openssl_decrypt')) {
|
||||
throw new \Exception('openssl_decrypt not callable');
|
||||
|
|
@ -237,7 +237,7 @@ abstract class Crypt
|
|||
) : string
|
||||
{
|
||||
if (!$data || !$iv) {
|
||||
throw new \InvalidArgumentException('$data or $iv is empty string');
|
||||
throw new \ValueError('$data or $iv is empty string');
|
||||
}
|
||||
if (!\is_callable('openssl_encrypt')) {
|
||||
throw new \Exception('openssl_encrypt not callable');
|
||||
|
|
@ -265,7 +265,7 @@ abstract class Crypt
|
|||
) /* : mixed */
|
||||
{
|
||||
if (!$data || !$salt) {
|
||||
throw new \InvalidArgumentException('$data or $salt is empty string');
|
||||
throw new \ValueError('$data or $salt is empty string');
|
||||
}
|
||||
$key = $salt . static::Passphrase($key);
|
||||
return \is_callable('xxtea_decrypt')
|
||||
|
|
@ -282,7 +282,7 @@ abstract class Crypt
|
|||
) : string
|
||||
{
|
||||
if (!$data || !$salt) {
|
||||
throw new \InvalidArgumentException('$data or $salt is empty string');
|
||||
throw new \ValueError('$data or $salt is empty string');
|
||||
}
|
||||
$key = $salt . static::Passphrase($key);
|
||||
$result = \is_callable('xxtea_encrypt')
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Client
|
|||
function __construct(array $settings)
|
||||
{
|
||||
if (!isset($settings['baseUri'])) {
|
||||
throw new \InvalidArgumentException('A baseUri must be provided');
|
||||
throw new \ValueError('A baseUri must be provided');
|
||||
}
|
||||
$this->baseUri = $settings['baseUri'];
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ class Client
|
|||
|
||||
foreach ($properties as $property) {
|
||||
if (!\preg_match('/^{([^}]*)}(.*)$/', $property, $match)) {
|
||||
throw new \InvalidArgumentException('\'' . $property . '\' is not a valid clark-notation formatted string');
|
||||
throw new \ValueError('\'' . $property . '\' is not a valid clark-notation formatted string');
|
||||
}
|
||||
if ('DAV:' === $match[1]) {
|
||||
$body .= "<d:{$match[2]}/>";
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ abstract class JWT
|
|||
$timestamp = $timestamp ?: \time();
|
||||
|
||||
if (empty($key)) {
|
||||
throw new \InvalidArgumentException('Key may not be empty');
|
||||
throw new \ValueError('Key may not be empty');
|
||||
}
|
||||
|
||||
$jwt = \explode('.', $jwt);
|
||||
|
|
@ -39,7 +39,6 @@ abstract class JWT
|
|||
throw new \UnexpectedValueException('Wrong number of segments');
|
||||
}
|
||||
try {
|
||||
;
|
||||
$header = static::jsonDecode($jwt[0]);
|
||||
} catch (\Throwable $e) {
|
||||
throw new \UnexpectedValueException("Invalid header encoding ({$e->getMessage()})");
|
||||
|
|
@ -137,13 +136,13 @@ abstract class JWT
|
|||
if ($free_key) {
|
||||
$key = \openssl_pkey_get_private($key, $passphrase);
|
||||
if (!$key) {
|
||||
throw new \InvalidArgumentException('Invalid key, reason: ' . \openssl_error_string());
|
||||
throw new \ValueError('Invalid key, reason: ' . \openssl_error_string());
|
||||
}
|
||||
}
|
||||
try {
|
||||
$details = \openssl_pkey_get_details($key);
|
||||
if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) {
|
||||
throw new \InvalidArgumentException('Key is not compatible with RSA signatures');
|
||||
throw new \ValueError('Key is not compatible with RSA signatures');
|
||||
}
|
||||
$signature = '';
|
||||
if (!\openssl_sign($msg, $signature, $key, 'SHA'.\substr($alg,2))) {
|
||||
|
|
@ -165,7 +164,7 @@ abstract class JWT
|
|||
}
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException("Algorithm '{$alg}' not supported");
|
||||
throw new \ValueError("Algorithm '{$alg}' not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,13 +190,13 @@ abstract class JWT
|
|||
if ($free_key) {
|
||||
$key = \openssl_pkey_get_public($key);
|
||||
if (!$key) {
|
||||
throw new \InvalidArgumentException('Invalid key, reason: ' . openssl_error_string());
|
||||
throw new \ValueError('Invalid key, reason: ' . openssl_error_string());
|
||||
}
|
||||
}
|
||||
try {
|
||||
$details = \openssl_pkey_get_details($key);
|
||||
if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) {
|
||||
throw new \InvalidArgumentException('Key is not compatible with RSA signatures');
|
||||
throw new \ValueError('Key is not compatible with RSA signatures');
|
||||
}
|
||||
$success = \openssl_verify($msg, $signature, $key, 'SHA'.\substr($alg,2));
|
||||
if (-1 == $success) {
|
||||
|
|
@ -223,7 +222,7 @@ abstract class JWT
|
|||
// case 'ES384':
|
||||
// case 'ES512':
|
||||
default:
|
||||
throw new \InvalidArgumentException("Algorithm '{$alg}' not supported");
|
||||
throw new \ValueError("Algorithm '{$alg}' not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ abstract class SASL
|
|||
return new $class($m[2] ?? '');
|
||||
}
|
||||
}
|
||||
throw new \Exception("Unsupported SASL mechanism type: {$type}");
|
||||
throw new \ValueError("Unsupported SASL mechanism type: {$type}");
|
||||
}
|
||||
|
||||
public static function isSupported(string $type) : bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue