Skip to content

Commit 2236da5

Browse files
authored
Merge pull request #6 from peter279k/issue_#5
Resolved issue #5
2 parents d6e3669 + b7b1800 commit 2236da5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: php
2-
dist: trusty
2+
dist: xenial
33
sudo: true
44
php:
55
- '7.1'

src/Encryption.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace Lablnet;
1818

19+
use InvalidArgumentException;
20+
1921
class Encryption
2022
{
2123
/**
@@ -86,6 +88,10 @@ public function setAdapter($adapter)
8688
*/
8789
public function setKey($key)
8890
{
91+
if ($key === '') {
92+
throw new InvalidArgumentException('The key should not be empty string.');
93+
}
94+
8995
$this->key = $key;
9096

9197
return $this;

tests/EncryptionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace Lablnet\Tests;
1818

19+
use InvalidArgumentException;
1920
use Lablnet\Encryption;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -42,4 +43,11 @@ public function testEncryptAndDecryptWithSodium()
4243
$this->assertSame(112, strlen($encryptedString));
4344
$this->assertSame('plain-text', $decryptedString);
4445
}
46+
47+
public function testEncryptOnEmptyStringKey()
48+
{
49+
$this->expectException(InvalidArgumentException::class);
50+
51+
new Encryption('', 'sodium');
52+
}
4553
}

0 commit comments

Comments
 (0)