diff options
author | Felix Moeller <mail@felixmoeller.de> | 2012-11-02 19:53:02 +0100 |
---|---|---|
committer | Felix Moeller <mail@felixmoeller.de> | 2012-11-02 19:53:02 +0100 |
commit | afadf93d317e27fd848f1e70d5849169f862aed9 (patch) | |
tree | 4a9ed633a7735a1be3cf33fdad31ab981fd64a6b /apps/files_encryption | |
parent | d9e97610999ddf9f3a060b786f22d0abb054521e (diff) | |
download | nextcloud-server-afadf93d317e27fd848f1e70d5849169f862aed9.tar.gz nextcloud-server-afadf93d317e27fd848f1e70d5849169f862aed9.zip |
Checkstyle: many fixes
Diffstat (limited to 'apps/files_encryption')
-rw-r--r-- | apps/files_encryption/lib/crypt.php | 8 | ||||
-rw-r--r-- | apps/files_encryption/lib/cryptstream.php | 2 | ||||
-rw-r--r-- | apps/files_encryption/lib/proxy.php | 16 | ||||
-rw-r--r-- | apps/files_encryption/settings.php | 4 | ||||
-rw-r--r-- | apps/files_encryption/tests/encryption.php | 60 | ||||
-rw-r--r-- | apps/files_encryption/tests/proxy.php | 26 | ||||
-rw-r--r-- | apps/files_encryption/tests/stream.php | 24 |
7 files changed, 70 insertions, 70 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 28bf3c5c93e..d8e7e4d1dd9 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -43,7 +43,7 @@ class OC_Crypt { self::init($params['uid'], $params['password']); } - public static function init($login,$password) { + public static function init($login, $password) { $view=new OC_FilesystemView('/'); if(!$view->file_exists('/'.$login)) { $view->mkdir('/'.$login); @@ -195,7 +195,7 @@ class OC_Crypt { public static function blockEncrypt($data, $key='') { $result=''; while(strlen($data)) { - $result.=self::encrypt(substr($data, 0, 8192),$key); + $result.=self::encrypt(substr($data, 0, 8192), $key); $data=substr($data, 8192); } return $result; @@ -204,10 +204,10 @@ class OC_Crypt { /** * decrypt data in 8192b sized blocks */ - public static function blockDecrypt($data, $key='',$maxLength=0) { + public static function blockDecrypt($data, $key='', $maxLength=0) { $result=''; while(strlen($data)) { - $result.=self::decrypt(substr($data, 0, 8192),$key); + $result.=self::decrypt(substr($data, 0, 8192), $key); $data=substr($data, 8192); } if($maxLength>0) { diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index 0dd2d4b7b1e..3170cff366c 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -106,7 +106,7 @@ class OC_CryptStream{ if($currentPos%8192!=0) { //make sure we always start on a block start fseek($this->source, -($currentPos%8192), SEEK_CUR); - $encryptedBlock=fread($this->source,8192); + $encryptedBlock=fread($this->source, 8192); fseek($this->source, -($currentPos%8192), SEEK_CUR); $block=OC_Crypt::decrypt($encryptedBlock); $data=substr($block, 0, $currentPos%8192).$data; diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 61b87ab5463..fed6acaf91b 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -76,7 +76,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ public function postFile_get_contents($path,$data) { if(self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path,''); - $data=OC_Crypt::blockDecrypt($data,'',$cached['size']); + $data=OC_Crypt::blockDecrypt($data, '', $cached['size']); } return $data; } @@ -88,30 +88,30 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ $meta=stream_get_meta_data($result); if(self::isEncrypted($path)) { fclose($result); - $result=fopen('crypt://'.$path,$meta['mode']); + $result=fopen('crypt://'.$path, $meta['mode']); }elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') { if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0) { //first encrypt the target file so we don't end up with a half encrypted file OCP\Util::writeLog('files_encryption','Decrypting '.$path.' before writing',OCP\Util::DEBUG); $tmp=fopen('php://temp'); - OCP\Files::streamCopy($result,$tmp); + OCP\Files::streamCopy($result, $tmp); fclose($result); - OC_Filesystem::file_put_contents($path,$tmp); + OC_Filesystem::file_put_contents($path, $tmp); fclose($tmp); } - $result=fopen('crypt://'.$path,$meta['mode']); + $result=fopen('crypt://'.$path, $meta['mode']); } return $result; } - public function postGetMimeType($path,$mime) { + public function postGetMimeType($path, $mime) { if(self::isEncrypted($path)) { $mime=OCP\Files::getMimeType('crypt://'.$path,'w'); } return $mime; } - public function postStat($path,$data) { + public function postStat($path, $data) { if(self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path,''); $data['size']=$cached['size']; @@ -119,7 +119,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ return $data; } - public function postFileSize($path,$size) { + public function postFileSize($path, $size) { if(self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path,''); return $cached['size']; diff --git a/apps/files_encryption/settings.php b/apps/files_encryption/settings.php index 168124a8d22..ab9324dee44 100644 --- a/apps/files_encryption/settings.php +++ b/apps/files_encryption/settings.php @@ -9,8 +9,8 @@ $tmpl = new OCP\Template( 'files_encryption', 'settings'); $blackList=explode(',', OCP\Config::getAppValue('files_encryption', 'type_blacklist', 'jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); $enabled=(OCP\Config::getAppValue('files_encryption','enable_encryption','true')=='true'); -$tmpl->assign('blacklist',$blackList); -$tmpl->assign('encryption_enabled',$enabled); +$tmpl->assign('blacklist', $blackList); +$tmpl->assign('encryption_enabled', $enabled); OCP\Util::addscript('files_encryption','settings'); OCP\Util::addscript('core','multiselect'); diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php index a7bc2df0e12..b714b00b8f2 100644 --- a/apps/files_encryption/tests/encryption.php +++ b/apps/files_encryption/tests/encryption.php @@ -11,46 +11,46 @@ class Test_Encryption extends UnitTestCase { $key=uniqid(); $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; $source=file_get_contents($file); //nice large text file - $encrypted=OC_Crypt::encrypt($source,$key); - $decrypted=OC_Crypt::decrypt($encrypted,$key); + $encrypted=OC_Crypt::encrypt($source, $key); + $decrypted=OC_Crypt::decrypt($encrypted, $key); $decrypted=rtrim($decrypted, "\0"); - $this->assertNotEqual($encrypted,$source); - $this->assertEqual($decrypted,$source); + $this->assertNotEqual($encrypted, $source); + $this->assertEqual($decrypted, $source); - $chunk=substr($source,0,8192); - $encrypted=OC_Crypt::encrypt($chunk,$key); + $chunk=substr($source,0, 8192); + $encrypted=OC_Crypt::encrypt($chunk, $key); $this->assertEqual(strlen($chunk), strlen($encrypted)); - $decrypted=OC_Crypt::decrypt($encrypted,$key); + $decrypted=OC_Crypt::decrypt($encrypted, $key); $decrypted=rtrim($decrypted, "\0"); - $this->assertEqual($decrypted,$chunk); + $this->assertEqual($decrypted, $chunk); - $encrypted=OC_Crypt::blockEncrypt($source,$key); - $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); - $this->assertNotEqual($encrypted,$source); - $this->assertEqual($decrypted,$source); + $encrypted=OC_Crypt::blockEncrypt($source, $key); + $decrypted=OC_Crypt::blockDecrypt($encrypted, $key); + $this->assertNotEqual($encrypted, $source); + $this->assertEqual($decrypted, $source); $tmpFileEncrypted=OCP\Files::tmpFile(); - OC_Crypt::encryptfile($file,$tmpFileEncrypted,$key); + OC_Crypt::encryptfile($file,$tmpFileEncrypted, $key); $encrypted=file_get_contents($tmpFileEncrypted); - $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); - $this->assertNotEqual($encrypted,$source); - $this->assertEqual($decrypted,$source); + $decrypted=OC_Crypt::blockDecrypt($encrypted, $key); + $this->assertNotEqual($encrypted, $source); + $this->assertEqual($decrypted, $source); $tmpFileDecrypted=OCP\Files::tmpFile(); - OC_Crypt::decryptfile($tmpFileEncrypted,$tmpFileDecrypted,$key); + OC_Crypt::decryptfile($tmpFileEncrypted,$tmpFileDecrypted, $key); $decrypted=file_get_contents($tmpFileDecrypted); - $this->assertEqual($decrypted,$source); + $this->assertEqual($decrypted, $source); $file=OC::$SERVERROOT.'/core/img/weather-clear.png'; $source=file_get_contents($file); //binary file - $encrypted=OC_Crypt::encrypt($source,$key); - $decrypted=OC_Crypt::decrypt($encrypted,$key); + $encrypted=OC_Crypt::encrypt($source, $key); + $decrypted=OC_Crypt::decrypt($encrypted, $key); $decrypted=rtrim($decrypted, "\0"); - $this->assertEqual($decrypted,$source); + $this->assertEqual($decrypted, $source); - $encrypted=OC_Crypt::blockEncrypt($source,$key); - $decrypted=OC_Crypt::blockDecrypt($encrypted,$key); - $this->assertEqual($decrypted,$source); + $encrypted=OC_Crypt::blockEncrypt($source, $key); + $decrypted=OC_Crypt::blockDecrypt($encrypted, $key); + $this->assertEqual($decrypted, $source); } @@ -59,14 +59,14 @@ class Test_Encryption extends UnitTestCase { $file=__DIR__.'/binary'; $source=file_get_contents($file); //binary file - $encrypted=OC_Crypt::encrypt($source,$key); - $decrypted=OC_Crypt::decrypt($encrypted,$key); + $encrypted=OC_Crypt::encrypt($source, $key); + $decrypted=OC_Crypt::decrypt($encrypted, $key); $decrypted=rtrim($decrypted, "\0"); - $this->assertEqual($decrypted,$source); + $this->assertEqual($decrypted, $source); - $encrypted=OC_Crypt::blockEncrypt($source,$key); - $decrypted=OC_Crypt::blockDecrypt($encrypted,$key, strlen($source)); - $this->assertEqual($decrypted,$source); + $encrypted=OC_Crypt::blockEncrypt($source, $key); + $decrypted=OC_Crypt::blockDecrypt($encrypted, $key, strlen($source)); + $this->assertEqual($decrypted, $source); } } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index c3c8f4a2db0..25427ff4b97 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -41,7 +41,7 @@ class Test_CryptProxy extends UnitTestCase { } public function tearDown() { - OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig); + OCP\Config::setAppValue('files_encryption', 'enable_encryption', $this->oldConfig); if(!is_null($this->oldKey)) { $_SESSION['enckey']=$this->oldKey; } @@ -51,16 +51,16 @@ class Test_CryptProxy extends UnitTestCase { $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; $original=file_get_contents($file); - OC_Filesystem::file_put_contents('/file',$original); + OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled=false; $stored=OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled=true; $fromFile=OC_Filesystem::file_get_contents('/file'); - $this->assertNotEqual($original,$stored); + $this->assertNotEqual($original, $stored); $this->assertEqual(strlen($original), strlen($fromFile)); - $this->assertEqual($original,$fromFile); + $this->assertEqual($original, $fromFile); } @@ -72,46 +72,46 @@ class Test_CryptProxy extends UnitTestCase { $view=new OC_FilesystemView('/'.OC_User::getUser()); $userDir='/'.OC_User::getUser().'/files'; - $rootView->file_put_contents($userDir.'/file',$original); + $rootView->file_put_contents($userDir.'/file', $original); OC_FileProxy::$enabled=false; $stored=$rootView->file_get_contents($userDir.'/file'); OC_FileProxy::$enabled=true; - $this->assertNotEqual($original,$stored); + $this->assertNotEqual($original, $stored); $fromFile=$rootView->file_get_contents($userDir.'/file'); - $this->assertEqual($original,$fromFile); + $this->assertEqual($original, $fromFile); $fromFile=$view->file_get_contents('files/file'); - $this->assertEqual($original,$fromFile); + $this->assertEqual($original, $fromFile); } public function testBinary() { $file=__DIR__.'/binary'; $original=file_get_contents($file); - OC_Filesystem::file_put_contents('/file',$original); + OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled=false; $stored=OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled=true; $fromFile=OC_Filesystem::file_get_contents('/file'); - $this->assertNotEqual($original,$stored); + $this->assertNotEqual($original, $stored); $this->assertEqual(strlen($original), strlen($fromFile)); - $this->assertEqual($original,$fromFile); + $this->assertEqual($original, $fromFile); $file=__DIR__.'/zeros'; $original=file_get_contents($file); - OC_Filesystem::file_put_contents('/file',$original); + OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled=false; $stored=OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled=true; $fromFile=OC_Filesystem::file_get_contents('/file'); - $this->assertNotEqual($original,$stored); + $this->assertNotEqual($original, $stored); $this->assertEqual(strlen($original), strlen($fromFile)); } } diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 5ea0da48017..2caebf912ed 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -15,14 +15,14 @@ class Test_CryptStream extends UnitTestCase { fclose($stream); $stream=$this->getStream('test1','r', strlen('foobar')); - $data=fread($stream,6); + $data=fread($stream, 6); fclose($stream); - $this->assertEqual('foobar',$data); + $this->assertEqual('foobar', $data); $file=OC::$SERVERROOT.'/3rdparty/MDB2.php'; $source=fopen($file,'r'); - $target=$this->getStream('test2','w',0); - OCP\Files::streamCopy($source,$target); + $target=$this->getStream('test2', 'w', 0); + OCP\Files::streamCopy($source, $target); fclose($target); fclose($source); @@ -30,7 +30,7 @@ class Test_CryptStream extends UnitTestCase { $data=stream_get_contents($stream); $original=file_get_contents($file); $this->assertEqual(strlen($original), strlen($data)); - $this->assertEqual($original,$data); + $this->assertEqual($original, $data); } /** @@ -40,7 +40,7 @@ class Test_CryptStream extends UnitTestCase { * @param int size * @return resource */ - function getStream($id,$mode,$size) { + function getStream($id, $mode, $size) { if($id==='') { $id=uniqid(); } @@ -50,9 +50,9 @@ class Test_CryptStream extends UnitTestCase { }else{ $file=$this->tmpFiles[$id]; } - $stream=fopen($file,$mode); + $stream=fopen($file, $mode); OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size); - return fopen('crypt://streams/'.$id,$mode); + return fopen('crypt://streams/'.$id, $mode); } function testBinary() { @@ -60,26 +60,26 @@ class Test_CryptStream extends UnitTestCase { $source=file_get_contents($file); $stream=$this->getStream('test','w', strlen($source)); - fwrite($stream,$source); + fwrite($stream, $source); fclose($stream); $stream=$this->getStream('test','r', strlen($source)); $data=stream_get_contents($stream); fclose($stream); $this->assertEqual(strlen($data), strlen($source)); - $this->assertEqual($source,$data); + $this->assertEqual($source, $data); $file=__DIR__.'/zeros'; $source=file_get_contents($file); $stream=$this->getStream('test2','w', strlen($source)); - fwrite($stream,$source); + fwrite($stream, $source); fclose($stream); $stream=$this->getStream('test2','r', strlen($source)); $data=stream_get_contents($stream); fclose($stream); $this->assertEqual(strlen($data), strlen($source)); - $this->assertEqual($source,$data); + $this->assertEqual($source, $data); } } |