Refactor SettingsSignatureExists and SigningKeysManager to improve UUID validation and update parameter naming for clarity
https://github.com/nosial/Socialbox-PHP/issues/67
This commit is contained in:
parent
d47251c251
commit
c3b1ee799a
3 changed files with 22 additions and 23 deletions
|
@ -2,13 +2,9 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\Settings;
|
namespace Socialbox\Classes\StandardMethods\Settings;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use ncc\ThirdParty\Symfony\Uid\Uuid;
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -23,28 +19,20 @@
|
||||||
*/
|
*/
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
if(!$rpcRequest->containsParameter('uuid'))
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$uuid = Uuid::fromString($rpcRequest->getParameter('uuid'));
|
return $rpcRequest->produceResponse(SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $signatureUuid));
|
||||||
}
|
|
||||||
catch(InvalidArgumentException)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('uuid');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $rpcRequest->produceResponse(SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $uuid));
|
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
throw new StandardRpcException('Failed to check the signing key existence', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('Failed to check the signing key existence', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\SigningKeyState;
|
use Socialbox\Enums\SigningKeyState;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
@ -199,16 +200,26 @@
|
||||||
* Checks if a signing key exists in the database using the provided UUID.
|
* Checks if a signing key exists in the database using the provided UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
||||||
* @param string $uuid The UUID of the signing key to check.
|
* @param string $signatureUuid The UUID of the signing key to check.
|
||||||
* @return bool True if the signing key exists, false otherwise.
|
* @return bool True if the signing key exists, false otherwise.
|
||||||
* @throws DatabaseOperationException If a database error occurs during the operation.
|
* @throws DatabaseOperationException If a database error occurs during the operation.
|
||||||
*/
|
*/
|
||||||
public static function signingKeyExists(string $peerUuid, string $uuid): bool
|
public static function signingKeyExists(string $peerUuid, string $signatureUuid): bool
|
||||||
{
|
{
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
||||||
$statement->bindParam(':uuid', $uuid);
|
$statement->bindParam(':uuid', $signatureUuid);
|
||||||
$statement->bindParam(':peer_uuid', $peerUuid);
|
$statement->bindParam(':peer_uuid', $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
|
|
|
@ -1168,15 +1168,15 @@
|
||||||
/**
|
/**
|
||||||
* Checks if a signature exists in the peer's profile, returns True if the signature exists.
|
* Checks if a signature exists in the peer's profile, returns True if the signature exists.
|
||||||
*
|
*
|
||||||
* @param string $uuid The UUID of the signature to check for it's existence
|
* @param string $signatureUuid The UUID of the signature to check for it's existence
|
||||||
* @return bool Returns True if the signature exists, False otherwise
|
* @return bool Returns True if the signature exists, False otherwise
|
||||||
* @throws RpcException Thrown if there was an error with the RPC request
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
*/
|
*/
|
||||||
public function settingsSignatureExists(string $uuid): bool
|
public function settingsSignatureExists(string $signatureUuid): bool
|
||||||
{
|
{
|
||||||
return $this->sendRequest(
|
return $this->sendRequest(
|
||||||
new RpcRequest(StandardMethods::SETTINGS_SIGNATURE_EXISTS, parameters: [
|
new RpcRequest(StandardMethods::SETTINGS_SIGNATURE_EXISTS, parameters: [
|
||||||
'uuid' => $uuid
|
'signature_uuid' => $signatureUuid
|
||||||
])
|
])
|
||||||
)->getResponse()->getResult();
|
)->getResponse()->getResult();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue