Allow chaining of key set functions for encryption

This commit is contained in:
Clemens Schwaighofer
2024-12-20 15:13:22 +09:00
parent 7f9a4dc04f
commit 7248906da7
2 changed files with 6 additions and 3 deletions

View File

@@ -262,7 +262,7 @@ class AsymmetricAnonymousEncryption
public function setKeyPair(
#[\SensitiveParameter]
string $key_pair
) {
): AsymmetricAnonymousEncryption {
if (empty($key_pair)) {
throw new \UnexpectedValueException('Key pair cannot be empty');
}
@@ -277,6 +277,7 @@ class AsymmetricAnonymousEncryption
// check if valid
$this->createPublicKey($this->public_key);
}
return $this;
}
/**
@@ -311,7 +312,7 @@ class AsymmetricAnonymousEncryption
* @return void
* @throws \UnexpectedValueException public key empty
*/
public function setPublicKey(string $public_key)
public function setPublicKey(string $public_key): AsymmetricAnonymousEncryption
{
if (empty($public_key)) {
throw new \UnexpectedValueException('Public key cannot be empty');
@@ -320,6 +321,7 @@ class AsymmetricAnonymousEncryption
$this->createPublicKey($public_key);
$this->public_key = $public_key;
sodium_memzero($public_key);
return $this;
}
/**

View File

@@ -215,7 +215,7 @@ class SymmetricEncryption
public function setKey(
#[\SensitiveParameter]
string $key
) {
): SymmetricEncryption {
if (empty($key)) {
throw new \UnexpectedValueException('Key cannot be empty');
}
@@ -224,6 +224,7 @@ class SymmetricEncryption
// set key
$this->key = $key;
sodium_memzero($key);
return $this;
}
/**