Refactor SettingsDeleteSignature and SigningKeysManager to update parameter names for clarity, enhance UUID validation, and ensure proper type casting for signature UUID

https://github.com/nosial/Socialbox-PHP/issues/58
This commit is contained in:
netkas 2025-03-12 17:43:50 -04:00
parent f3f6cf973f
commit 9a6f37aa05
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 19 additions and 16 deletions

View file

@ -23,28 +23,21 @@
*/ */
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')); if(!SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $signatureUuid))
}
catch(InvalidArgumentException)
{
throw new InvalidRpcArgumentException('uuid');
}
try
{
if(!SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $uuid))
{ {
return $rpcRequest->produceResponse(false); return $rpcRequest->produceResponse(false);
} }
SigningKeysManager::deleteSigningKey($request->getPeer()->getUuid(), $uuid); SigningKeysManager::deleteSigningKey($request->getPeer()->getUuid(), $signatureUuid);
} }
catch(DatabaseOperationException $e) catch(DatabaseOperationException $e)
{ {

View file

@ -235,16 +235,26 @@
* Deletes a signing key from the database using the provided UUID. * Deletes a signing key from 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 delete. * @param string $signatureUuid The UUID of the signing key to delete.
* @return void * @return void
* @throws DatabaseOperationException If a database error occurs during the operation. * @throws DatabaseOperationException If a database error occurs during the operation.
*/ */
public static function deleteSigningKey(string $peerUuid, string $uuid): void public static function deleteSigningKey(string $peerUuid, string $signatureUuid): void
{ {
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("DELETE FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid"); $statement = Database::getConnection()->prepare("DELETE 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();
} }