aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/keymanager.php
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-07-31 19:28:11 +0100
committerSam Tuke <samtuke@owncloud.com>2012-07-31 19:28:11 +0100
commiteebf76d34457df616d2b739582d9630f58df60b1 (patch)
tree7b26a71004278a63e3b4895a85a476a833f47395 /apps/files_encryption/lib/keymanager.php
parentee15c40b1416507abbe6d0fb568bde77bb94e5f4 (diff)
downloadnextcloud-server-eebf76d34457df616d2b739582d9630f58df60b1.tar.gz
nextcloud-server-eebf76d34457df616d2b739582d9630f58df60b1.zip
Implemented writing of keyfiles and directory hierarchy in proxy class
Added crypt::findFiles() method for finding different types of files, ready for batch encrypting / decrypting Added comments to postFopen in proxy class
Diffstat (limited to 'apps/files_encryption/lib/keymanager.php')
-rw-r--r--apps/files_encryption/lib/keymanager.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index bafe8f1a5f0..0c76bf27a52 100644
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -27,7 +27,7 @@ namespace OCA_Encryption;
*/
class Keymanager {
- # TODO: Try and get rid of username dependencies as these methods need to be used in a proxy class that doesn't have username access
+ # TODO: make all dependencies explicit, such as ocfsview objects, by adding them as method arguments (dependency injection)
/**
* @brief retrieve private key from a user
@@ -60,9 +60,9 @@ class Keymanager {
* @param string user name of the file owner
* @return string file key or false
*/
- public static function getFileKey($userId, $path) {
+ public static function getFileKey( $userId, $path ) {
- $keypath = ltrim($path, '/');
+ $keypath = ltrim( $path, '/' );
$user = $userId;
// update $keypath and $user if path point to a file shared by someone else
@@ -127,29 +127,33 @@ class Keymanager {
* @param string $path relative path of the file, including filename
* @param string $key
* @return bool true/false
- */
+ */
public static function setFileKey( $userId, $path, $key ) {
\OC_FileProxy::$enabled = false;
- $targetpath = ltrim($path, '/');
+ $targetpath = ltrim( $path, '/' );
$user = $userId;
// update $keytarget and $user if key belongs to a file shared by someone else
$query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );
- $result = $query->execute( array ('/'.$userId.'/files/'.$targetpath, $userId));
- if ($row = $result->fetchRow()){
+
+ $result = $query->execute( array ( '/'.$userId.'/files/'.$targetpath, $userId ) );
+
+ if ( $row = $result->fetchRow( ) ) {
$targetpath = $row['source'];
- $targetpath_parts=explode('/',$targetpath);
+ $targetpath_parts=explode( '/',$targetpath );
$user = $targetpath_parts[1];
- $targetpath = str_replace('/'.$user.'/files/', '', $targetpath);
+ $targetpath = str_replace( '/'.$user.'/files/', '', $targetpath );
//TODO: check for write permission on shared file once the new sharing API is in place
}
$view = new \OC_FilesystemView( '/' . $user . '/files_encryption/keyfiles' );
- $path_parts = pathinfo($targetpath);
- if (!$view->file_exists($path_parts['dirname'])) $view->mkdir($path_parts['dirname']);
+ $path_parts = pathinfo( $targetpath );
+
+ if ( !$view->file_exists( $path_parts['dirname'] ) ) $view->mkdir( $path_parts['dirname'] );
+
$result = $view->file_put_contents( '/' . $targetpath . '.key', $key );
\OC_FileProxy::$enabled = true;