Beispiel #1
0
	/**
	 * @dataProvider providesHeaders
	 */
	public function testReadHeader($header, $expected, $moduleId) {
		$expected['oc_encryption_module'] = $moduleId;
		$result = $this->util->readHeader($header);
		$this->assertSameSize($expected, $result);
		foreach ($expected as $key => $value) {
			$this->assertArrayHasKey($key, $result);
			$this->assertSame($value, $result[$key]);
		}
	}
Beispiel #2
0
 /**
  * read header from file
  *
  * @param string $path
  * @return array
  */
 protected function getHeader($path)
 {
     $header = '';
     if ($this->storage->file_exists($path)) {
         $handle = $this->storage->fopen($path, 'r');
         $header = fread($handle, $this->util->getHeaderSize());
         fclose($handle);
     }
     return $this->util->readHeader($header);
 }
Beispiel #3
0
	/**
	 * read encryption module needed to read/write the file located at $path
	 *
	 * @param string $path
	 * @return null|\OCP\Encryption\IEncryptionModule
	 * @throws ModuleDoesNotExistsException
	 * @throws \Exception
	 */
	protected function getEncryptionModule($path) {
		$encryptionModule = null;
		$rawHeader = $this->getHeader($path);
		$header = $this->util->readHeader($rawHeader);
		$encryptionModuleId = $this->util->getEncryptionModuleId($header);
		if (!empty($encryptionModuleId)) {
			try {
				$encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
			} catch (ModuleDoesNotExistsException $e) {
				$this->logger->critical('Encryption module defined in "' . $path . '" not loaded!');
				throw $e;
			}
		}
		return $encryptionModule;
	}