forked from ecotoneframework/ecotone-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataProtectionConfiguration.php
More file actions
49 lines (38 loc) · 1.07 KB
/
DataProtectionConfiguration.php
File metadata and controls
49 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* licence Enterprise
*/
namespace Ecotone\DataProtection\Configuration;
use Ecotone\DataProtection\Encryption\Key;
use Ecotone\Messaging\Support\Assert;
class DataProtectionConfiguration
{
/**
* @param array<string, Key> $keys
*/
private function __construct(private array $keys, private string $defaultKey)
{
}
public static function create(string $name, Key $key): self
{
return new self(keys: [$name => $key], defaultKey: $name);
}
public function withKey(string $name, Key $key, bool $asDefault = false): self
{
Assert::keyNotExists($this->keys, $name, sprintf('Encryption key name `%s` already exists', $name));
$config = clone $this;
$config->keys[$name] = $key;
if ($asDefault) {
$config->defaultKey = $name;
}
return $config;
}
public function keyName(?string $name): string
{
return array_key_exists($name, $this->keys) ? $name : $this->defaultKey;
}
public function keys(): array
{
return $this->keys;
}
}