-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInMemoryKeyRing.php
More file actions
40 lines (32 loc) · 939 Bytes
/
InMemoryKeyRing.php
File metadata and controls
40 lines (32 loc) · 939 Bytes
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
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\Vault\KeyRing;
use SensitiveParameter;
/**
* Simple key ring that keeps keys in memory.
*/
class InMemoryKeyRing implements KeyRingInterface
{
/**
* @param array<string, string> $keys Map of key IDs to keys.
* @param string $currentKeyId Identifier of the active key.
*/
public function __construct(private array $keys, private string $currentKeyId) {}
public function getCurrentKeyId(): string
{
return $this->currentKeyId;
}
public function getCurrentKey(): string
{
return $this->keys[$this->currentKeyId];
}
public function getKey(string $keyId): ?string
{
return $this->keys[$keyId] ?? null;
}
public function rotate(string $keyId, #[SensitiveParameter] string $key): void
{
$this->keys[$keyId] = $key;
$this->currentKeyId = $keyId;
}
}