Refactor Signature and SigningKeyRecord classes to allow nullable name property and update related methods
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions

This commit is contained in:
netkas 2025-03-27 15:21:09 -04:00
parent 200b6a7c1f
commit 66ed368d75
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
4 changed files with 18 additions and 15 deletions

View file

@ -2,7 +2,7 @@ create table signing_keys
( (
peer_uuid varchar(36) not null comment 'The UUID of the peer', peer_uuid varchar(36) not null comment 'The UUID of the peer',
uuid varchar(36) default uuid() not null comment 'The UUID of the key record', uuid varchar(36) default uuid() not null comment 'The UUID of the key record',
name varchar(64) not null comment 'Optional. User provided name for the key', name varchar(64) null comment 'Optional. User provided name for the key',
public_key varchar(64) not null comment 'The Public Signature Key', public_key varchar(64) not null comment 'The Public Signature Key',
state enum ('ACTIVE', 'EXPIRED') default 'ACTIVE' not null comment 'The state of the public key', state enum ('ACTIVE', 'EXPIRED') default 'ACTIVE' not null comment 'The state of the public key',
expires timestamp null comment 'The Timestamp for when this key expires, null = Never expires', expires timestamp null comment 'The Timestamp for when this key expires, null = Never expires',

View file

@ -55,12 +55,12 @@
* *
* @param string|PeerDatabaseRecord $peerUuid The unique identifier of the peer associated with the signing key. * @param string|PeerDatabaseRecord $peerUuid The unique identifier of the peer associated with the signing key.
* @param string $publicKey The public signing key to be added. Must be valid according to the Cryptography::validatePublicSigningKey method. * @param string $publicKey The public signing key to be added. Must be valid according to the Cryptography::validatePublicSigningKey method.
* @param string $name Optional name associated with the signing key. Must not exceed 64 characters in length. * @param string|null $name Optional name associated with the signing key. Must not exceed 64 characters in length.
* @param int|null $expires Optional expiration timestamp for the signing key. Can be null if the key does not expire. * @param int|null $expires Optional expiration timestamp for the signing key. Can be null if the key does not expire.
* @return string The UUID of the newly added signing key. * @return string The UUID of the newly added signing key.
* @throws DatabaseOperationException If the operation to add the signing key to the database fails. * @throws DatabaseOperationException If the operation to add the signing key to the database fails.
*/ */
public static function addSigningKey(string|PeerDatabaseRecord $peerUuid, string $publicKey, string $name, ?int $expires=null): string public static function addSigningKey(string|PeerDatabaseRecord $peerUuid, string $publicKey, ?string $name=null, ?int $expires=null): string
{ {
if($peerUuid instanceof PeerDatabaseRecord) if($peerUuid instanceof PeerDatabaseRecord)
{ {
@ -76,14 +76,17 @@
throw new InvalidArgumentException('The public key is invalid'); throw new InvalidArgumentException('The public key is invalid');
} }
if(empty($name)) if($name !== null)
{ {
throw new InvalidArgumentException('The name cannot be empty'); if(empty($name))
} {
throw new InvalidArgumentException('The name cannot be empty');
}
if(strlen($name) > 64) if(strlen($name) > 64)
{ {
throw new InvalidArgumentException('The name is too long'); throw new InvalidArgumentException('The name is too long');
}
} }
if($expires !== null) if($expires !== null)

View file

@ -12,7 +12,7 @@
{ {
private string $peerUuid; private string $peerUuid;
private string $uuid; private string $uuid;
private string $name; private ?string $name;
private string $publicKey; private string $publicKey;
private SigningKeyState $state; private SigningKeyState $state;
private int $expires; private int $expires;
@ -35,7 +35,7 @@
{ {
$this->peerUuid = $data['peer_uuid']; $this->peerUuid = $data['peer_uuid'];
$this->uuid = $data['uuid']; $this->uuid = $data['uuid'];
$this->name = $data['name']; $this->name = $data['name'] ?? null;
$this->publicKey = $data['public_key']; $this->publicKey = $data['public_key'];
$this->state = SigningKeyState::tryFrom($data['state']); $this->state = SigningKeyState::tryFrom($data['state']);
@ -115,9 +115,9 @@
/** /**
* Retrieves the name. * Retrieves the name.
* *
* @return string The name, or null if not set. * @return string|null The name, or null if not set.
*/ */
public function getName(): string public function getName(): ?string
{ {
return $this->name; return $this->name;
} }

View file

@ -11,7 +11,7 @@
class Signature implements SerializableInterface class Signature implements SerializableInterface
{ {
private string $uuid; private string $uuid;
private string $name; private ?string $name;
private string $publicKey; private string $publicKey;
private SigningKeyState $state; private SigningKeyState $state;
private int $expires; private int $expires;
@ -35,7 +35,7 @@
public function __construct(array $data) public function __construct(array $data)
{ {
$this->uuid = $data['uuid']; $this->uuid = $data['uuid'];
$this->name = $data['name']; $this->name = $data['name'] ?? null;
$this->publicKey = $data['public_key']; $this->publicKey = $data['public_key'];
$this->state = SigningKeyState::from($data['state']); $this->state = SigningKeyState::from($data['state']);