Made message signing in Cryptography use SHA512 as the message content for... #1
4 changed files with 62 additions and 8 deletions
|
@ -24,7 +24,7 @@
|
|||
{
|
||||
if(!$rpcRequest->containsParameter('peer'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required \'peer\' parameter');
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required peer parameter');
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\StandardError;
|
||||
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;
|
||||
|
||||
class AddressBookGetContact extends Method
|
||||
{
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
if(!ContactManager::isContact($request->getPeer(), $address))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
||||
}
|
||||
|
||||
$contact = ContactManager::getContact($request->getPeer(), $address);
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException('Failed to get contact', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse($contact->toStandard());
|
||||
}
|
||||
}
|
|
@ -52,12 +52,7 @@
|
|||
throw new StandardException('Failed to get contacts', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
foreach($contacts as $contact)
|
||||
{
|
||||
$results[] = $contact->toStandard();
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse($results);
|
||||
return $rpcRequest->produceResponse(array_map(function($contact) {return $contact->toStandard();}, $contacts));
|
||||
}
|
||||
}
|
|
@ -761,10 +761,11 @@
|
|||
* Resolves an external peer based on the given peer address or string identifier.
|
||||
*
|
||||
* @param PeerAddress|string $peerAddress The external peer address or string identifier to be resolved.
|
||||
* @param PeerAddress|string|null $identifiedAs Optional. The peer address or string identifier by which the caller is identified
|
||||
* @return Peer The resolved external peer after synchronization.
|
||||
* @throws StandardException Thrown if there was an error with the resolution process
|
||||
*/
|
||||
public static function resolvePeer(PeerAddress|string $peerAddress): Peer
|
||||
public static function resolvePeer(PeerAddress|string $peerAddress, null|PeerAddress|string $identifiedAs=null): Peer
|
||||
{
|
||||
if(is_string($peerAddress))
|
||||
{
|
||||
|
@ -844,6 +845,11 @@
|
|||
return $registeredPeer;
|
||||
}
|
||||
|
||||
private static function localResolvePeer(PeerAddress|string $peerAddress, null|PeerAddress|string $identifiedAs=null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the server information by assembling data from the configuration settings.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue