Skip to content

Commit 55ed3a7

Browse files
committed
feat(encryption): Add previous key initialization in Encryption.php
1 parent 5f45c6f commit 55ed3a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

system/Encryption/Encryption.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ class Encryption
5353
*/
5454
protected $key;
5555

56+
/**
57+
* Whether to fall back to previous keys when decryption fails.
58+
*
59+
* @var bool
60+
*/
61+
protected bool $previousKeysFallbackEnabled = false;
62+
63+
/**
64+
* List of previous keys for fallback decryption.
65+
*
66+
* @var string[]
67+
*/
68+
protected array $previousKeys = [];
69+
5670
/**
5771
* The derived HMAC key
5872
*
@@ -92,6 +106,8 @@ public function __construct(?EncryptionConfig $config = null)
92106
$config ??= new EncryptionConfig();
93107

94108
$this->key = $config->key;
109+
$this->previousKeysFallbackEnabled = $config->previousKeysFallbackEnabled;
110+
$this->previousKeys = $config->previousKeys;
95111
$this->driver = $config->driver;
96112
$this->digest = $config->digest ?? 'SHA512';
97113

@@ -117,6 +133,8 @@ public function initialize(?EncryptionConfig $config = null)
117133
{
118134
if ($config instanceof EncryptionConfig) {
119135
$this->key = $config->key;
136+
$this->previousKeysFallbackEnabled = $config->previousKeysFallbackEnabled ?? false;
137+
$this->previousKeys = $config->previousKeys ?? [];
120138
$this->driver = $config->driver;
121139
$this->digest = $config->digest ?? 'SHA512';
122140
}

0 commit comments

Comments
 (0)