Completed
Push — master ( 23cd7e...7877b2 )
by Francesco
02:54
created

EncryptionWrapper::encryptFileWithKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
/*
4
 * This file is part of the MesCryptoBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mes\Security\CryptoBundle;
13
14
use Defuse\Crypto\Exception\CryptoException as BaseCryptoException;
15
use Defuse\Crypto\Exception\EnvironmentIsBrokenException;
16
use Mes\Security\CryptoBundle\Exception\CryptoException;
17
use Mes\Security\CryptoBundle\Model\KeyInterface;
18
19
/**
20
 * Class EncryptionWrapper.
21
 */
22
final class EncryptionWrapper implements EncryptionInterface
23
{
24
    /**
25
     * @var EncryptionInterface
26
     */
27
    private $encryption;
28
29 8
    public function __construct(EncryptionInterface $encryption)
30
    {
31 8
        $this->encryption = $encryption;
32 8
    }
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @throw CryptoException
38
     */
39 2
    public function encryptWithKey($plaintext, KeyInterface $key)
40
    {
41
        try {
42 2
            return $this->encryption->encryptWithKey($plaintext, $key);
43 1
        } catch (EnvironmentIsBrokenException $ex) {
44 1
            throw new CryptoException($ex->getMessage());
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     *
51
     * @throw CryptoException
52
     */
53 2
    public function decryptWithKey($ciphertext, KeyInterface $key)
54
    {
55
        try {
56 2
            return $this->encryption->decryptWithKey($ciphertext, $key);
57 1
        } catch (BaseCryptoException $ex) {
58 1
            throw new CryptoException($ex->getMessage());
59
        }
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     *
65
     * @throw CryptoException
66
     */
67 2
    public function encryptFileWithKey($inputFilename, $outputFilename, KeyInterface $key)
68
    {
69
        try {
70 2
            $this->encryption->encryptFileWithKey($inputFilename, $outputFilename, $key);
71 2
        } catch (BaseCryptoException $ex) {
72 1
            throw new CryptoException($ex->getMessage());
73
        }
74 1
    }
75
76
    /**
77
     * {@inheritdoc}
78
     *
79
     * @throw CryptoException
80
     */
81 2
    public function decryptFileWithKey($inputFilename, $outputFilename, KeyInterface $key)
82
    {
83
        try {
84 2
            $this->encryption->decryptFileWithKey($inputFilename, $outputFilename, $key);
85 2
        } catch (BaseCryptoException $ex) {
86 1
            throw new CryptoException($ex->getMessage());
87
        }
88 1
    }
89
}
90