diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-02 14:44:58 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:30 +0200 |
commit | 104d11ec4c5d359c54985e01c171ba1845537632 (patch) | |
tree | 2cd51e73fab86bef8a4cd86af08d615643f402aa /lib/private | |
parent | d9c41b00ab4271b401ed838ccc0b19a9a0f67a76 (diff) | |
download | nextcloud-server-104d11ec4c5d359c54985e01c171ba1845537632.tar.gz nextcloud-server-104d11ec4c5d359c54985e01c171ba1845537632.zip |
Fixing encryption storage wrapper tests
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/encryption/exceptions/encryptionheadertolargeexception.php | 2 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 69 |
2 files changed, 67 insertions, 4 deletions
diff --git a/lib/private/encryption/exceptions/encryptionheadertolargeexception.php b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php index 94a130d792d..cdb5f940800 100644 --- a/lib/private/encryption/exceptions/encryptionheadertolargeexception.php +++ b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php @@ -26,7 +26,7 @@ use OCP\Encryption\Exceptions\GenericEncryptionException; class EncryptionHeaderToLargeException extends GenericEncryptionException { - public function __construct($key) { + public function __construct() { parent::__construct('max header size exceeded'); } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 7cc488aa914..58d963613aa 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -24,9 +24,12 @@ namespace OC\Files\Storage\Wrapper; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; +use OC\Files\Storage\LocalTempFileTrait; class Encryption extends Wrapper { + use LocalTempFileTrait; + /** @var string */ private $mountPoint; @@ -156,8 +159,8 @@ class Encryption extends Wrapper { $encryptionModule = $this->getEncryptionModule($path); if ($encryptionModule) { - $keyStorage = \OC::$server->getEncryptionKeyStorage($encryptionModule->getId()); - $keyStorage->deleteAllFileKeys($this->getFullPath($path)); + $keyStorage = $this->getKeyStorage($encryptionModule->getId()); + $keyStorage->deleteAllFileKeys($this->getFullPath($path)); } return $this->storage->unlink($path); @@ -184,7 +187,7 @@ class Encryption extends Wrapper { list(, $target) = $this->util->getUidAndFilename($fullPath2); $encryptionModule = $this->getEncryptionModule($path2); if ($encryptionModule) { - $keyStorage = \OC::$server->getEncryptionKeyStorage($encryptionModule->getId()); + $keyStorage = $this->getKeyStorage($encryptionModule->getId()); $keyStorage->renameKeys($source, $target, $owner, $systemWide); } } @@ -270,6 +273,57 @@ class Encryption extends Wrapper { } /** + * get the path to a local version of the file. + * The local version of the file can be temporary and doesn't have to be persistent across requests + * + * @param string $path + * @return string + */ + public function getLocalFile($path) { + return $this->getCachedFile($path); + } + + /** + * Returns the wrapped storage's value for isLocal() + * + * @return bool wrapped storage's isLocal() value + */ + public function isLocal() { + return false; + } + + /** + * see http://php.net/manual/en/function.stat.php + * only the following keys are required in the result: size and mtime + * + * @param string $path + * @return array + */ + public function stat($path) { + $stat = $this->storage->stat($path); + $fileSize = $this->filesize($path); + $stat['size'] = $fileSize; + $stat[7] = $fileSize; + return $stat; + } + + /** + * see http://php.net/manual/en/function.hash.php + * + * @param string $type + * @param string $path + * @param bool $raw + * @return string + */ + public function hash($type, $path, $raw = false) { + $fh = $this->fopen($path, 'rb'); + $ctx = hash_init($type); + hash_update_stream($ctx, $fh); + fclose($fh); + return hash_final($ctx, $raw); + } + + /** * return full path, including mount point * * @param string $path relative to mount point @@ -322,4 +376,13 @@ class Encryption extends Wrapper { $this->unencryptedSize[$path] = $unencryptedSize; } + /** + * @param string $encryptionModule + * @return \OCP\Encryption\Keys\IStorage + */ + protected function getKeyStorage($encryptionModuleId) { + $keyStorage = \OC::$server->getEncryptionKeyStorage($encryptionModuleId); + return $keyStorage; + } + } |