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

EnvelopeEncryptedValue::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
namespace Jeskew\Cache;
3
4
class EnvelopeEncryptedValue extends EncryptedValue
5
{
6
    /** @var string */
7
    private $envelopeKey;
8
    /** @var string */
9
    private $signature;
10
11
    /**
12
     * @param string $cipherText
13
     * @param string $method
14
     * @param string $iv
15
     * @param string $key
16
     * @param string $signature
17
     */
18 114
    public function __construct($cipherText, $method, $iv, $key, $signature)
19
    {
20 114
        parent::__construct($cipherText, $method, $iv);
21 114
        $this->envelopeKey = $key;
22 114
        $this->signature = $signature;
23 114
    }
24
25 3
    public function jsonSerialize()
26
    {
27 3
        return parent::jsonSerialize() + [
28 3
            'key' => base64_encode($this->envelopeKey),
29 3
            'signature' => base64_encode($this->signature),
30 3
        ];
31
    }
32
33 3
    public function unserialize($serialized)
34
    {
35 3
        parent::unserialize($serialized);
36
37 3
        $data = json_decode($serialized);
38 3
        $this->envelopeKey = base64_decode($data->key);
39 3
        $this->signature = base64_decode($data->signature);
40 3
    }
41
42
    /**
43
     * @return string
44
     */
45 56
    public function getEnvelopeKey()
46
    {
47 56
        return $this->envelopeKey;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 81
    public function getSignature()
54
    {
55 81
        return $this->signature;
56
    }
57
}
58