Beispiel #1
0
 /**
  * Decrypt the given output.
  *
  * @param OutputContract     $input
  * @param OutputContract     $output
  * @param SyncOutputContract $console
  */
 public function decrypt(OutputContract $input, OutputContract $output, SyncOutputContract $console = null)
 {
     $files = $input->listContents('', true);
     if ($console) {
         $console->setTotal(count($files));
     }
     foreach ($files as $file) {
         if ($file['type'] == 'dir') {
             if ($console) {
                 $console->out(SyncOutput::ENC_ENCRYPT_FILE, ['file' => $file['path']]);
             }
             continue;
         }
         try {
             $fileContents = $this->crypto->decrypt($input->read($file['path']), $this->key);
             if ($output->has($file['path'])) {
                 $output->update($file['path'], $fileContents);
             } else {
                 $output->write($file['path'], $fileContents);
             }
             unset($fileContents);
             if ($console) {
                 $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path']]);
             }
         } catch (GeneralSecurityException $e) {
             if ($console) {
                 $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path'], 'output' => $e]);
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Read input and output files.
  */
 public function init()
 {
     $this->inputFiles = $this->input->listContents('', true);
     $this->outputFiles = $this->output->listContents('', true);
 }