summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/appinfo/app.php4
-rw-r--r--apps/files_encryption/lib/crypt.php2
-rw-r--r--apps/files_encryption/lib/cryptstream.php8
-rw-r--r--apps/files_encryption/lib/proxy.php18
-rw-r--r--apps/files_encryption/settings.php10
-rw-r--r--apps/files_encryption/tests/encryption.php60
-rw-r--r--apps/files_encryption/tests/stream.php44
7 files changed, 73 insertions, 73 deletions
diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php
index bb130a366be..3f76e910a52 100644
--- a/apps/files_encryption/appinfo/app.php
+++ b/apps/files_encryption/appinfo/app.php
@@ -6,9 +6,9 @@ OC::$CLASSPATH['OC_FileProxy_Encryption'] = 'apps/files_encryption/lib/proxy.php
OC_FileProxy::register(new OC_FileProxy_Encryption());
-OCP\Util::connectHook('OC_User','post_login','OC_Crypt','loginListener');
+OCP\Util::connectHook('OC_User', 'post_login', 'OC_Crypt', 'loginListener');
-stream_wrapper_register('crypt','OC_CryptStream');
+stream_wrapper_register('crypt', 'OC_CryptStream');
if(!isset($_SESSION['enckey']) and OCP\User::isLoggedIn()) {//force the user to re-loggin if the encryption key isn't unlocked (happens when a user is logged in before the encryption app is enabled)
OCP\User::logout();
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index 8b566e0aa09..9f2d6852a2c 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\Files\View('/');
if(!$view->file_exists('/'.$login)) {
$view->mkdir('/'.$login);
diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php
index 340caee3fb6..ff81bd20fc2 100644
--- a/apps/files_encryption/lib/cryptstream.php
+++ b/apps/files_encryption/lib/cryptstream.php
@@ -23,7 +23,7 @@
/**
* transparently encrypted filestream
*
- * you can use it as wrapper around an existing stream by setting OC_CryptStream::$sourceStreams['foo']=array('path'=>$path,'stream'=>$stream)
+ * you can use it as wrapper around an existing stream by setting OC_CryptStream::$sourceStreams['foo']=array('path'=>$path, 'stream'=>$stream)
* and then fopen('crypt://streams/foo');
*/
@@ -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;
@@ -123,11 +123,11 @@ class OC_CryptStream{
$data=substr($data, 8192);
}
}
- $this->size=max($this->size,$currentPos+$length);
+ $this->size=max($this->size, $currentPos+$length);
return $length;
}
- public function stream_set_option($option,$arg1,$arg2) {
+ public function stream_set_option($option, $arg1, $arg2) {
switch($option) {
case STREAM_OPTION_BLOCKING:
stream_set_blocking($this->source, $arg1);
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 49fb30ac291..8300c8ab7e9 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @return bool
*/
private static function isEncrypted($path) {
- $metadata=\OC\Files\Filesystem::getFileInfo($path,'');
+ $metadata=\OC\Files\Filesystem::getFileInfo($path, '');
return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
}
@@ -68,15 +68,15 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
if (!is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($data);
$data=OC_Crypt::blockEncrypt($data);
- \OC\Files\Filesystem::putFileInfo($path, array('encrypted'=>true,'size'=>$size),'');
+ \OC\Files\Filesystem::putFileInfo($path, array('encrypted'=>true, 'size'=>$size), '');
}
}
}
public function postFile_get_contents($path,$data) {
if(self::isEncrypted($path)) {
- $cached=\OC\Files\Filesystem::getFileInfo($path,'');
- $data=OC_Crypt::blockDecrypt($data,'',$cached['size']);
+ $cached=\OC\Files\Filesystem::getFileInfo($path, '');
+ $data=OC_Crypt::blockDecrypt($data, '', $cached['size']);
}
return $data;
}
@@ -90,13 +90,13 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
fclose($result);
$result=fopen('crypt://'.$path,$meta['mode']);
}elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') {
- if(\OC\Files\Filesystem::file_exists($path) and \OC\Files\Filesystem::filesize($path)>0) {
+ 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);
+ OCP\Util::writeLog('files_encryption', 'Decrypting ' . $path . ' before writing', OCP\Util::DEBUG);
$tmp=fopen('php://temp', 'w+');
OCP\Files::streamCopy($result,$tmp);
fclose($result);
- \OC\Files\Filesystem::file_put_contents($path,$tmp);
+ \OC\Files\Filesystem::file_put_contents($path, $tmp);
fclose($tmp);
}
$result=fopen('crypt://'.$path,$meta['mode']);
@@ -113,7 +113,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postStat($path,$data) {
if(self::isEncrypted($path)) {
- $cached=\OC\Files\Filesystem::getFileInfo($path,'');
+ $cached=\OC\Files\Filesystem::getFileInfo($path, '');
$data['size']=$cached['size'];
}
return $data;
@@ -121,7 +121,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
public function postFileSize($path,$size) {
if(self::isEncrypted($path)) {
- $cached=\OC\Files\Filesystem::getFileInfo($path,'');
+ $cached=\OC\Files\Filesystem::getFileInfo($path, '');
return $cached['size'];
}else{
return $size;
diff --git a/apps/files_encryption/settings.php b/apps/files_encryption/settings.php
index 168124a8d22..ae28b088cd6 100644
--- a/apps/files_encryption/settings.php
+++ b/apps/files_encryption/settings.php
@@ -8,11 +8,11 @@
$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);
+$enabled=(OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true')=='true');
+$tmpl->assign('blacklist', $blackList);
+$tmpl->assign('encryption_enabled', $enabled);
-OCP\Util::addscript('files_encryption','settings');
-OCP\Util::addscript('core','multiselect');
+OCP\Util::addscript('files_encryption', 'settings');
+OCP\Util::addscript('core', 'multiselect');
return $tmpl->fetchPage();
diff --git a/apps/files_encryption/tests/encryption.php b/apps/files_encryption/tests/encryption.php
index a7bc2df0e12..0e119f55bea 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/stream.php b/apps/files_encryption/tests/stream.php
index 5ea0da48017..67b5e98ae67 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -10,27 +10,27 @@ class Test_CryptStream extends UnitTestCase {
private $tmpFiles=array();
function testStream() {
- $stream=$this->getStream('test1','w', strlen('foobar'));
- fwrite($stream,'foobar');
+ $stream=$this->getStream('test1', 'w', strlen('foobar'));
+ fwrite($stream, 'foobar');
fclose($stream);
- $stream=$this->getStream('test1','r', strlen('foobar'));
- $data=fread($stream,6);
+ $stream=$this->getStream('test1', 'r', strlen('foobar'));
+ $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);
+ $source=fopen($file, 'r');
+ $target=$this->getStream('test2', 'w', 0);
+ OCP\Files::streamCopy($source, $target);
fclose($target);
fclose($source);
- $stream=$this->getStream('test2','r', filesize($file));
+ $stream=$this->getStream('test2', 'r', filesize($file));
$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,36 +50,36 @@ class Test_CryptStream extends UnitTestCase {
}else{
$file=$this->tmpFiles[$id];
}
- $stream=fopen($file,$mode);
- OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size);
- return fopen('crypt://streams/'.$id,$mode);
+ $stream=fopen($file, $mode);
+ OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id, 'stream'=>$stream, 'size'=>$size);
+ return fopen('crypt://streams/'.$id, $mode);
}
function testBinary() {
$file=__DIR__.'/binary';
$source=file_get_contents($file);
- $stream=$this->getStream('test','w', strlen($source));
- fwrite($stream,$source);
+ $stream=$this->getStream('test', 'w', strlen($source));
+ fwrite($stream, $source);
fclose($stream);
- $stream=$this->getStream('test','r', strlen($source));
+ $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);
+ $stream=$this->getStream('test2', 'w', strlen($source));
+ fwrite($stream, $source);
fclose($stream);
- $stream=$this->getStream('test2','r', strlen($source));
+ $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);
}
}