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\PeerAddress;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
class AddressBookRevokeSignature extends Method
|
||||
{
|
||||
|
@ -43,20 +42,10 @@
|
|||
throw new MissingRpcArgumentException('signature_uuid');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$signatureUuid = Uuid::fromString($rpcRequest->getParameter('signature_uuid'));
|
||||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('signature_uuid', $e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Check if the contact already exists
|
||||
$peer = $request->getPeer();
|
||||
$contact = ContactManager::getContact($peer, $address);
|
||||
$contact = ContactManager::getContact($request->getPeer(), $address);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
|
@ -70,6 +59,7 @@
|
|||
|
||||
try
|
||||
{
|
||||
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||
if(!ContactManager::contactSigningKeyUuidExists($contact, $signatureUuid))
|
||||
{
|
||||
return $rpcRequest->produceResponse(false);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
use ncc\ThirdParty\Symfony\Uid\UuidV4;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Socialbox\Classes\Cryptography;
|
||||
use Socialbox\Classes\Database;
|
||||
use Socialbox\Classes\Validator;
|
||||
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||
|
@ -424,6 +425,15 @@
|
|||
{
|
||||
$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
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue