Made message signing in Cryptography use SHA512 as the message content for... #1
1 changed files with 68 additions and 0 deletions
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\PeerAddress;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
use Socialbox\Socialbox;
|
||||||
|
use Symfony\Component\Uid\Uuid;
|
||||||
|
|
||||||
|
class ResolvePeerSignature extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
// Check if the required 'peer' parameter is set.
|
||||||
|
if(!$rpcRequest->containsParameter('peer'))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'peer' parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$rpcRequest->containsParameter('uuid'))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'uuid' parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$uuid = Uuid::fromString($rpcRequest->getParameter('uuid'));
|
||||||
|
}
|
||||||
|
catch(InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Invalid UUID', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the peer address
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
|
}
|
||||||
|
catch(InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceResponse(Socialbox::resolvePeerSignature($peerAddress, $uuid->toRfc4122()));
|
||||||
|
}
|
||||||
|
catch(StandardException $e)
|
||||||
|
{
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Failed to resolve peer signature', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue