Made message signing in Cryptography use SHA512 as the message content for... #1
1 changed files with 51 additions and 0 deletions
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\ContactManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\PeerAddress;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
use Socialbox\Socialbox;
|
||||||
|
|
||||||
|
class AddressBookContactExists extends Method
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns True if the contact exists in the address book, False otherwise.
|
||||||
|
*
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('peer'))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required peer parameter');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
|
}
|
||||||
|
catch(InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$peer = $request->getPeer();
|
||||||
|
return $rpcRequest->produceResponse(ContactManager::isContact($peer, $address));
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Failed to check if the contact exists', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue