Made message signing in Cryptography use SHA512 as the message content for... #1

Closed
netkas wants to merge 421 commits from master into dev
2 changed files with 169 additions and 147 deletions
Showing only changes of commit c85ca908f0 - Show all commits

View file

@ -2,6 +2,7 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" /> <excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>

View file

@ -1,168 +1,189 @@
<?php <?php
namespace Socialbox\Objects\Database; namespace Socialbox\Objects\Database;
use DateTime; use DateTime;
use Socialbox\Classes\Configuration; use Socialbox\Classes\Configuration;
use Socialbox\Classes\Logger; use Socialbox\Enums\Flags\PeerFlags;
use Socialbox\Enums\Flags\PeerFlags; use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Interfaces\SerializableInterface; use Socialbox\Objects\Standard\SelfUser;
use Socialbox\Objects\Standard\SelfUser;
class RegisteredPeerRecord implements SerializableInterface class RegisteredPeerRecord implements SerializableInterface
{
private string $uuid;
private string $username;
private ?string $displayName;
/**
* @var PeerFlags[]
*/
private ?array $flags;
private bool $enabled;
private DateTime $created;
/**
* Constructor for initializing class properties from provided data.
*
* @param array $data Array containing initialization data.
* @throws \DateMalformedStringException
*/
public function __construct(array $data)
{ {
$this->uuid = $data['uuid']; private string $uuid;
$this->username = $data['username']; private string $username;
$this->displayName = $data['display_name'] ?? null; private string $server;
private ?string $displayName;
/**
* @var PeerFlags[]
*/
private ?array $flags;
private bool $enabled;
private DateTime $created;
if($data['flags']) /**
* Constructor for initializing class properties from provided data.
*
* @param array $data Array containing initialization data.
* @throws \DateMalformedStringException
*/
public function __construct(array $data)
{ {
$this->flags = PeerFlags::fromString($data['flags']); $this->uuid = $data['uuid'];
} $this->username = $data['username'];
else $this->server = $data['server'];
{ $this->displayName = $data['display_name'] ?? null;
$this->flags = [];
if($data['flags'])
{
$this->flags = PeerFlags::fromString($data['flags']);
}
else
{
$this->flags = [];
}
$this->enabled = $data['enabled'];
if (is_string($data['created']))
{
$this->created = new DateTime($data['created']);
}
else
{
$this->created = $data['created'];
}
} }
$this->enabled = $data['enabled']; /**
* Retrieves the UUID of the current instance.
if (is_string($data['created'])) *
* @return string The UUID.
*/
public function getUuid(): string
{ {
$this->created = new DateTime($data['created']); return $this->uuid;
} }
else
/**
* Retrieves the username.
*
* @return string The username.
*/
public function getUsername(): string
{ {
$this->created = $data['created']; return $this->username;
}
/**
* Retrieves the server.
*
* @return string The server.
*/
public function getServer(): string
{
return $this->server;
}
/**
* Constructs and retrieves the peer address using the current instance's username and the domain from the configuration.
*
* @return string The constructed peer address.
*/
public function getAddress(): string
{
return sprintf("%s@%s", $this->username, Configuration::getInstanceConfiguration()->getDomain());
}
/**
* Retrieves the display name.
*
* @return string|null The display name if set, or null otherwise.
*/
public function getDisplayName(): ?string
{
return $this->displayName;
}
public function getFlags(): array
{
return $this->flags;
}
public function flagExists(PeerFlags $flag): bool
{
return in_array($flag, $this->flags, true);
}
public function removeFlag(PeerFlags $flag): void
{
$key = array_search($flag, $this->flags, true);
if($key !== false)
{
unset($this->flags[$key]);
}
}
/**
* Checks if the current instance is enabled.
*
* @return bool True if enabled, false otherwise.
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Retrieves the creation date and time.
*
* @return DateTime The creation date and time.
*/
public function getCreated(): DateTime
{
return $this->created;
}
/**
* Determines if the server is external.
*
* @return bool True if the server is external, false otherwise.
*/
public function isExternal(): bool
{
return $this->server === 'host';
}
/**
* Converts the current instance to a SelfUser object.
*
* @return SelfUser The SelfUser object.
*/
public function toSelfUser(): SelfUser
{
return new SelfUser($this);
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): object
{
return new self($data);
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'uuid' => $this->uuid,
'username' => $this->username,
'display_name' => $this->displayName,
'flags' => PeerFlags::toString($this->flags),
'enabled' => $this->enabled,
'created' => $this->created
];
} }
} }
/**
* Retrieves the UUID of the current instance.
*
* @return string The UUID.
*/
public function getUuid(): string
{
return $this->uuid;
}
/**
* Retrieves the username.
*
* @return string The username.
*/
public function getUsername(): string
{
return $this->username;
}
/**
* Constructs and retrieves the peer address using the current instance's username and the domain from the configuration.
*
* @return string The constructed peer address.
*/
public function getAddress(): string
{
return sprintf("%s@%s", $this->username, Configuration::getInstanceConfiguration()->getDomain());
}
/**
* Retrieves the display name.
*
* @return string|null The display name if set, or null otherwise.
*/
public function getDisplayName(): ?string
{
return $this->displayName;
}
public function getFlags(): array
{
return $this->flags;
}
public function flagExists(PeerFlags $flag): bool
{
return in_array($flag, $this->flags, true);
}
public function removeFlag(PeerFlags $flag): void
{
$key = array_search($flag, $this->flags, true);
if($key !== false)
{
unset($this->flags[$key]);
}
}
/**
* Checks if the current instance is enabled.
*
* @return bool True if enabled, false otherwise.
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Retrieves the creation date and time.
*
* @return DateTime The creation date and time.
*/
public function getCreated(): DateTime
{
return $this->created;
}
/**
* Converts the current instance to a SelfUser object.
*
* @return SelfUser The SelfUser object.
*/
public function toSelfUser(): SelfUser
{
return new SelfUser($this);
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): object
{
return new self($data);
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'uuid' => $this->uuid,
'username' => $this->username,
'display_name' => $this->displayName,
'flags' => PeerFlags::toString($this->flags),
'enabled' => $this->enabled,
'created' => $this->created
];
}
}