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

HaliteEncryptor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 4 1
A loadKey() 0 4 1
A encrypt() 0 4 1
A decrypt() 0 4 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
}