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,73 +15,109 @@ 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
{ {
return $this->a; return $this->a;
} }
/** /**
* @param String $a * @param string $a
*/ */
public function setA(string $a): void public function setA(string $a): void
{ {
$this->a = $a; $this->a = $a;
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getAaaa(): string public function getAaaa(): string
{ {
return $this->aaaa; return $this->aaaa;
} }
/** /**
* @param String $aaaa * @param string $aaaa
*/ */
public function setAaaa(string $aaaa): void public function setAaaa(string $aaaa): void
{ {
$this->aaaa = $aaaa; $this->aaaa = $aaaa;
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getApikey(): string public function getApikey(): string
{ {
return $this->apikey; return $this->apikey;
} }
/** /**
* @param String $apikey * @param string $apikey
*/ */
public function setApikey(string $apikey): void public function setApikey(string $apikey): void
{ {
$this->apikey = $apikey; $this->apikey = $apikey;
} }
/** /**
* @return int * @return int
*/ */
@ -86,7 +126,7 @@ class Nameserver
{ {
return $this->id; return $this->id;
} }
/** /**
* @param int $id * @param int $id
*/ */
@ -94,22 +134,30 @@ class Nameserver
{ {
$this->id = $id; $this->id = $id;
} }
/** /**
* @return String * @return string
*/ */
#[OAT\Property(type: 'string')] #[OAT\Property(type: 'string')]
public function getName(): string public function getName(): string
{ {
return $this->name; return $this->name;
} }
/** /**
* @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;
}
} }