1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * @copyright 2018 Mautic, Inc. All rights reserved |
||
7 | * @author Mautic, Inc. |
||
8 | * |
||
9 | * @link https://mautic.com |
||
10 | * |
||
11 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
12 | */ |
||
13 | |||
14 | namespace Mautic\IntegrationsBundle\Facade; |
||
15 | |||
16 | use Mautic\CoreBundle\Helper\EncryptionHelper; |
||
17 | |||
18 | class EncryptionService |
||
19 | { |
||
20 | /** |
||
21 | * @var EncryptionHelper |
||
22 | */ |
||
23 | private $encryptionHelper; |
||
24 | |||
25 | /** |
||
26 | * EncryptionService constructor. |
||
27 | */ |
||
28 | public function __construct(EncryptionHelper $encryptionHelper) |
||
29 | { |
||
30 | $this->encryptionHelper = $encryptionHelper; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param mixed $keys |
||
35 | * |
||
36 | * @return array|string |
||
37 | */ |
||
38 | public function encrypt($keys) |
||
39 | { |
||
40 | if (!is_array($keys)) { |
||
41 | return $this->encryptionHelper->encrypt($keys); |
||
42 | } |
||
43 | |||
44 | foreach ($keys as $name => $key) { |
||
45 | $keys[$name] = $this->encryptionHelper->encrypt($key); |
||
46 | } |
||
47 | |||
48 | return $keys; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param $keys |
||
53 | * @param bool $onlyPrimaryCipher |
||
54 | * |
||
55 | * @return array|string |
||
56 | */ |
||
57 | public function decrypt($keys, $onlyPrimaryCipher = false) |
||
58 | { |
||
59 | if (!is_array($keys)) { |
||
60 | return $this->encryptionHelper->decrypt($keys, $onlyPrimaryCipher); |
||
0 ignored issues
–
show
|
|||
61 | } |
||
62 | |||
63 | foreach ($keys as $name => $key) { |
||
64 | $keys[$name] = $this->encryptionHelper->decrypt($key, $onlyPrimaryCipher); |
||
65 | } |
||
66 | |||
67 | return $keys; |
||
68 | } |
||
69 | } |
||
70 |
If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.