added encryption, constructor property promotion

This commit is contained in:
tracer 2022-09-22 18:57:10 +02:00
parent 8ec1a2942d
commit 51b9e67ea9
1 changed files with 81 additions and 33 deletions

View File

@ -2,7 +2,11 @@
namespace App\Entity; namespace App\Entity;
use App\Controller\ConfigController;
use App\Controller\EncryptionController;
use Exception;
use OpenApi\Attributes as OAT; use OpenApi\Attributes as OAT;
use SodiumException;
/** /**
* *
@ -11,24 +15,60 @@ use OpenApi\Attributes as OAT;
class Nameserver class Nameserver
{ {
private int $id; /**
private String $name; * @param string $name
private String $a; * @param int $id
private String $aaaa; * @param string $a
private String $apikey; * @param string $aaaa
* @param string $passphrase
public function __construct(String $name, int $id = 0, String $a = '', String $aaaa = '', String $apikey = '') * @param string $apikey
* @param string $apikeyPrefix
*/
public function __construct(
private string $name,
private int $id = 0,
private string $a = '',
private string $aaaa = '',
private readonly string $passphrase = '',
private string $apikey = '',
private string $apikeyPrefix = '')
{ {
$this->id = $id; if ($this->passphrase) {
$this->name = $name; $configController = new ConfigController();
$this->a = $a; $encryptionController = new EncryptionController();
$this->aaaa = $aaaa;
$this->apikey = $apikey; $encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
}
[$this->apikeyPrefix] = explode(separator: '.', string: $this->passphrase);
try {
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
} catch (Exception|SodiumException $e) {
die($e->getMessage() . PHP_EOL);
}
}
}
/**
* @return string
*/
public function getApikeyPrefix(): string
{
return $this->apikeyPrefix;
}
/**
* @param string $apikeyPrefix
*/
public function setApikeyPrefix(string $apikeyPrefix): void
{
$this->apikeyPrefix = $apikeyPrefix;
}
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getA(): string public function getA(): string
@ -37,7 +77,7 @@ class Nameserver
} }
/** /**
* @param String $a * @param string $a
*/ */
public function setA(string $a): void public function setA(string $a): void
{ {
@ -45,7 +85,7 @@ class Nameserver
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getAaaa(): string public function getAaaa(): string
@ -54,7 +94,7 @@ class Nameserver
} }
/** /**
* @param String $aaaa * @param string $aaaa
*/ */
public function setAaaa(string $aaaa): void public function setAaaa(string $aaaa): void
{ {
@ -62,7 +102,7 @@ class Nameserver
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getApikey(): string public function getApikey(): string
@ -71,7 +111,7 @@ class Nameserver
} }
/** /**
* @param String $apikey * @param string $apikey
*/ */
public function setApikey(string $apikey): void public function setApikey(string $apikey): void
{ {
@ -96,7 +136,7 @@ class Nameserver
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getName(): string public function getName(): string
@ -105,11 +145,19 @@ class Nameserver
} }
/** /**
* @param String $name * @param string $name
*/ */
public function setName(string $name): void public function setName(string $name): void
{ {
$this->name = $name; $this->name = $name;
} }
/**
* @return string
*/
public function getPassphrase(): string
{
return $this->passphrase;
}
} }