1 | <?php |
||
20 | class Gpg extends Abstraction implements Executable |
||
21 | { |
||
22 | use OptionMasker; |
||
23 | |||
24 | public const SUFFIX = 'gpg'; |
||
25 | |||
26 | private const ACTION_ENCRYPT = 'e'; |
||
27 | private const ACTION_DECRYPT = 'd'; |
||
28 | |||
29 | /** |
||
30 | * Current action encrypt|decrypt |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $action; |
||
35 | |||
36 | /** |
||
37 | * Path to source file |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $sourceFile; |
||
42 | |||
43 | /** |
||
44 | * Path to encrypted file |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $targetFile; |
||
49 | |||
50 | /** |
||
51 | * Gpg user |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | private $user; |
||
56 | |||
57 | /** |
||
58 | * Keep the not encrypted file |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | private $deleteSource = true; |
||
63 | |||
64 | /** |
||
65 | * Constructor |
||
66 | * |
||
67 | * @param string $path |
||
68 | */ |
||
69 | 4 | public function __construct(string $path = '') |
|
73 | |||
74 | /** |
||
75 | * Encrypt a file |
||
76 | * |
||
77 | * @param string $file |
||
78 | * @return \phpbu\App\Cli\Executable\Gpg |
||
79 | */ |
||
80 | 3 | public function encryptFile(string $file): Gpg |
|
87 | |||
88 | /** |
||
89 | * Encrypt a file |
||
90 | * |
||
91 | * @param string $file |
||
92 | * @return \phpbu\App\Cli\Executable\Gpg |
||
93 | */ |
||
94 | 1 | public function decryptFile(string $file): Gpg |
|
101 | |||
102 | /** |
||
103 | * Delete the uncrypted data |
||
104 | * |
||
105 | * @param boolean $bool |
||
106 | * @return \phpbu\App\Cli\Executable\Gpg |
||
107 | */ |
||
108 | 4 | public function deleteSource(bool $bool): Gpg |
|
113 | |||
114 | /** |
||
115 | * Password to use for encryption |
||
116 | * |
||
117 | * @param string $user |
||
118 | * @return \phpbu\App\Cli\Executable\Gpg |
||
119 | */ |
||
120 | 4 | public function useUser(string $user): Gpg |
|
125 | |||
126 | /** |
||
127 | * Gpg CommandLine generator |
||
128 | * |
||
129 | * @return \SebastianFeldmann\Cli\CommandLine |
||
130 | * @throws \phpbu\App\Exception |
||
131 | */ |
||
132 | 4 | protected function createCommandLine(): CommandLine |
|
147 | |||
148 | /** |
||
149 | * Add the 'rm' command to remove the uncrypted file |
||
150 | * |
||
151 | * @param \SebastianFeldmann\Cli\CommandLine $process |
||
152 | */ |
||
153 | 4 | protected function addDeleteCommand(CommandLine $process): void |
|
161 | } |
||
162 |