Passed
Pull Request — master (#6)
by Chris
05:44
created

LegacyEncryptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Carnage\EncryptedColumn\Encryptor;
4
5
use Carnage\EncryptedColumn\Exception\PopArtPenguinException;
6
use Carnage\EncryptedColumn\ValueObject\EncryptorIdentity;
7
use Carnage\EncryptedColumn\ValueObject\IdentityInterface;
8
use Carnage\EncryptedColumn\ValueObject\Key;
9
use phpseclib\Crypt\Base;
10
use phpseclib\Crypt\Rijndael;
11
12
class LegacyEncryptor implements EncryptorInterface
13
{
14
    const IDENTITY = 'legacy';
15
16
    public function encrypt($data, Key $key)
17
    {
18
        throw new PopArtPenguinException();
19
    }
20
21 1
    public function decrypt($data, Key $key)
22
    {
23 1
        $cipher = new Rijndael(Base::MODE_ECB);
24 1
        $cipher->setBlockLength(256);
25 1
        $cipher->setKey($key->getKeyInfo());
26 1
        $cipher->padding = false;
27
28 1
        return trim($cipher->decrypt(base64_decode($data)));
29
    }
30
31 1
    public function getIdentifier(): IdentityInterface
32
    {
33 1
        return new EncryptorIdentity(self::IDENTITY);
34
    }
35
}