Completed
Push — master ( f20e30...a2c18f )
by Jonathan
04:47
created

EncryptedValue::getInitializationVector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Jeskew\Cache;
3
4
use JsonSerializable;
5
use Serializable;
6
7
abstract class EncryptedValue implements JsonSerializable, Serializable
8
{
9
    /** @var string */
10
    private $cipherText;
11
    /** @var string */
12
    private $method;
13
    /** @var string */
14
    private $initializationVector;
15
16 228
    public function __construct($cipherText, $method, $iv)
17
    {
18 228
        $this->cipherText = $cipherText;
19 228
        $this->method = $method;
20 228
        $this->initializationVector = $iv;
21 228
    }
22
23 6
    public function jsonSerialize()
24
    {
25
        return [
26 6
            'cipherText' => $this->cipherText,
27 6
            'method' => $this->method,
28 6
            'iv' => base64_encode($this->initializationVector),
29 6
        ];
30
    }
31
32 6
    public function serialize()
33
    {
34 6
        return json_encode($this->jsonSerialize());
35
    }
36
37 6
    public function unserialize($serialized)
38
    {
39 6
        $data = json_decode($serialized);
40
41 6
        $this->cipherText = $data->cipherText;
42 6
        $this->method = $data->method;
43 6
        $this->initializationVector = base64_decode($data->iv);
44 6
    }
45
46
    /**
47
     * @return string
48
     */
49 162
    public function getCipherText()
50
    {
51 162
        return $this->cipherText;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 112
    public function getMethod()
58
    {
59 112
        return $this->method;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 112
    public function getInitializationVector()
66
    {
67 112
        return $this->initializationVector;
68
    }
69
}
70