diff --git a/src/Socialbox/Classes/Resources/database/signing_keys.sql b/src/Socialbox/Classes/Resources/database/signing_keys.sql index 9184a57..3853718 100644 --- a/src/Socialbox/Classes/Resources/database/signing_keys.sql +++ b/src/Socialbox/Classes/Resources/database/signing_keys.sql @@ -2,7 +2,7 @@ create table signing_keys ( 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', - 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', 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', diff --git a/src/Socialbox/Managers/SigningKeysManager.php b/src/Socialbox/Managers/SigningKeysManager.php index e1e5cf7..6c4f5ab 100644 --- a/src/Socialbox/Managers/SigningKeysManager.php +++ b/src/Socialbox/Managers/SigningKeysManager.php @@ -55,12 +55,12 @@ * * @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 $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. * @return string The UUID of the newly added signing key. * @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) { @@ -76,14 +76,17 @@ 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) - { - throw new InvalidArgumentException('The name is too long'); + if(strlen($name) > 64) + { + throw new InvalidArgumentException('The name is too long'); + } } if($expires !== null) diff --git a/src/Socialbox/Objects/Database/SigningKeyRecord.php b/src/Socialbox/Objects/Database/SigningKeyRecord.php index c3f100d..d9edd92 100644 --- a/src/Socialbox/Objects/Database/SigningKeyRecord.php +++ b/src/Socialbox/Objects/Database/SigningKeyRecord.php @@ -12,7 +12,7 @@ { private string $peerUuid; private string $uuid; - private string $name; + private ?string $name; private string $publicKey; private SigningKeyState $state; private int $expires; @@ -35,7 +35,7 @@ { $this->peerUuid = $data['peer_uuid']; $this->uuid = $data['uuid']; - $this->name = $data['name']; + $this->name = $data['name'] ?? null; $this->publicKey = $data['public_key']; $this->state = SigningKeyState::tryFrom($data['state']); @@ -115,9 +115,9 @@ /** * 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; } diff --git a/src/Socialbox/Objects/Standard/Signature.php b/src/Socialbox/Objects/Standard/Signature.php index 4092cf6..19566f8 100644 --- a/src/Socialbox/Objects/Standard/Signature.php +++ b/src/Socialbox/Objects/Standard/Signature.php @@ -11,7 +11,7 @@ class Signature implements SerializableInterface { private string $uuid; - private string $name; + private ?string $name; private string $publicKey; private SigningKeyState $state; private int $expires; @@ -35,7 +35,7 @@ public function __construct(array $data) { $this->uuid = $data['uuid']; - $this->name = $data['name']; + $this->name = $data['name'] ?? null; $this->publicKey = $data['public_key']; $this->state = SigningKeyState::from($data['state']);