Test Setup Failed
Push — master ( 009624...c15db0 )
by Chris
48s
created

HaliteEncryptor::__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\ValueObject\EncryptorIdentity;
6
use Carnage\EncryptedColumn\ValueObject\IdentityInterface;
7
use Carnage\EncryptedColumn\ValueObject\Key;
8
use ParagonIE\Halite\KeyFactory;
9
use ParagonIE\Halite\Symmetric;
10
11
class HaliteEncryptor implements EncryptorInterface
12
{
13
    const IDENTITY = 'halite';
14
15
    public function encrypt($data, Key $key)
16
    {
17
        return Symmetric\Crypto::encrypt($data, $this->loadKey($key));
18
    }
19
20 5
    public function decrypt($data, Key $key)
21
    {
22 5
        return Symmetric\Crypto::decrypt($data, $this->loadKey($key));
23 5
    }
24
25 5
    public function getIdentifier(): IdentityInterface
26
    {
27 5
        return new EncryptorIdentity(self::IDENTITY);
28
    }
29
30 2
    /**
31
     * @return Symmetric\EncryptionKey
32 2
     * @throws \ParagonIE\Halite\Alerts\CannotPerformOperation
33
     */
34
    private function loadKey(Key $key)
35 6
    {
36
        return KeyFactory::loadEncryptionKey($key->getKeyInfo());
37
    }
38
}