Allow method chaining in Session and encryption class

For session set/unset/auto write close flag

In the encryption classes for setting keys
This commit is contained in:
Clemens Schwaighofer
2024-12-23 11:35:44 +09:00
parent 9f8a86b4b0
commit b7d5a79c3a
3 changed files with 19 additions and 13 deletions

View File

@@ -256,13 +256,13 @@ class AsymmetricAnonymousEncryption
* sets the private key for encryption
*
* @param string $key_pair Key pair in hex
* @return void
* @return AsymmetricAnonymousEncryption
* @throws \UnexpectedValueException key pair empty
*/
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;
}
/**
@@ -308,10 +309,10 @@ class AsymmetricAnonymousEncryption
* extract the public key from the key pair
*
* @param string $public_key Public Key in hex
* @return void
* @return AsymmetricAnonymousEncryption
* @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;
}
/**