Refactor AddressBookRevokeSignature and ContactManager to remove UUID validation and improve error handling
https://github.com/nosial/Socialbox-PHP/issues/36
This commit is contained in:
parent
50c638b534
commit
eadf1cd3a4
2 changed files with 12 additions and 12 deletions
|
@ -14,7 +14,6 @@
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\PeerAddress;
|
use Socialbox\Objects\PeerAddress;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
use Symfony\Component\Uid\Uuid;
|
|
||||||
|
|
||||||
class AddressBookRevokeSignature extends Method
|
class AddressBookRevokeSignature extends Method
|
||||||
{
|
{
|
||||||
|
@ -43,20 +42,10 @@
|
||||||
throw new MissingRpcArgumentException('signature_uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$signatureUuid = Uuid::fromString($rpcRequest->getParameter('signature_uuid'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('signature_uuid', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
$peer = $request->getPeer();
|
$contact = ContactManager::getContact($request->getPeer(), $address);
|
||||||
$contact = ContactManager::getContact($peer, $address);
|
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +59,7 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
if(!ContactManager::contactSigningKeyUuidExists($contact, $signatureUuid))
|
if(!ContactManager::contactSigningKeyUuidExists($contact, $signatureUuid))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
use ncc\ThirdParty\Symfony\Uid\UuidV4;
|
use ncc\ThirdParty\Symfony\Uid\UuidV4;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
use Socialbox\Classes\Validator;
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\Types\ContactRelationshipType;
|
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||||
|
@ -424,6 +425,15 @@
|
||||||
{
|
{
|
||||||
$contactUuid = $contactUuid->getUuid();
|
$contactUuid = $contactUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact 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
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue