Passed
Pull Request — master (#5)
by Chris
02:42
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 phpseclib\Crypt\Base;
9
use phpseclib\Crypt\Rijndael;
10
11
class LegacyEncryptor implements EncryptorInterface
12
{
13
    const IDENTITY = 'legacy';
14
    /**
15
     * @var string
16
     */
17
    private $secret;
18
19 1
    public function __construct($secret)
20
    {
21 1
        $this->secret = $secret;
22 1
    }
23
24
    public function encrypt($data)
25
    {
26
        throw new PopArtPenguinException();
27
    }
28
29 1
    public function decrypt($data)
30
    {
31 1
        $cipher = new Rijndael(Base::MODE_ECB);
32 1
        $cipher->setBlockLength(256);
33 1
        $cipher->setKey($this->secret);
34 1
        $cipher->padding = false;
35
36 1
        return trim($cipher->decrypt(base64_decode($data)));
37
    }
38
39 1
    public function getIdentifier(): IdentityInterface
40
    {
41 1
        return new EncryptorIdentity(self::IDENTITY);
42
    }
43
}