Skip to content

Commit ce8a061

Browse files
committed
Add encryption functionality
1 parent dd96653 commit ce8a061

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/UnitTests/Encryption/EncryptionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ public function testCreateFromFiles(): void
120120
$this->validateEncryption($encryption);
121121
}
122122

123+
public function testValidate(): void
124+
{
125+
$this->expectNotToPerformAssertions();
126+
127+
$privateKey = sodium_crypto_box_keypair();
128+
$publicKey = sodium_crypto_box_publickey($privateKey);
129+
130+
$encryption = new Encryption($privateKey, $publicKey, []);
131+
132+
$encryption->validate();
133+
}
134+
135+
public function testValidateFailsWithInvalidPublicKey(): void
136+
{
137+
$privateKey = sodium_crypto_box_keypair();
138+
$publicKey = sodium_crypto_box_publickey(sodium_crypto_box_keypair());
139+
140+
$this->expectException(EncryptionException::class);
141+
$this->expectExceptionMessage('The encryption key is not valid.');
142+
143+
$encryption = new Encryption($privateKey, $publicKey, []);
144+
145+
$encryption->validate();
146+
}
147+
123148
private function validateEncryption(Encryption $encryption): void
124149
{
125150
$data = $encryption->reveal($encryption->seal(self::DATA));

0 commit comments

Comments
 (0)