Passed
Push — master ( 5e985c...318d55 )
by Christoph
17:43 queued 04:53
created
lib/private/Template/Base.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
 		if (array_key_exists($key, $this->vars)) {
118 118
 			$this->vars[$key][] = $value;
119 119
 		} else {
120
-			$this->vars[$key] = [ $value ];
120
+			$this->vars[$key] = [$value];
121 121
 		}
122 122
 	}
123 123
 
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -33,157 +33,157 @@
 block discarded – undo
33 33
 use OCP\Defaults;
34 34
 
35 35
 class Base {
36
-	private $template; // The template
37
-	private $vars; // Vars
38
-
39
-	/** @var \OCP\IL10N */
40
-	private $l10n;
41
-
42
-	/** @var Defaults */
43
-	private $theme;
44
-
45
-	/**
46
-	 * @param string $template
47
-	 * @param string $requestToken
48
-	 * @param \OCP\IL10N $l10n
49
-	 * @param Defaults $theme
50
-	 */
51
-	public function __construct($template, $requestToken, $l10n, $theme) {
52
-		$this->vars = [];
53
-		$this->vars['requesttoken'] = $requestToken;
54
-		$this->l10n = $l10n;
55
-		$this->template = $template;
56
-		$this->theme = $theme;
57
-	}
58
-
59
-	/**
60
-	 * @param string $serverRoot
61
-	 * @param string|false $app_dir
62
-	 * @param string $theme
63
-	 * @param string $app
64
-	 * @return string[]
65
-	 */
66
-	protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
67
-		// Check if the app is in the app folder or in the root
68
-		if (file_exists($app_dir.'/templates/')) {
69
-			return [
70
-				$serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
71
-				$app_dir.'/templates/',
72
-			];
73
-		}
74
-		return [
75
-			$serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
76
-			$serverRoot.'/'.$app.'/templates/',
77
-		];
78
-	}
79
-
80
-	/**
81
-	 * @param string $serverRoot
82
-	 * @param string $theme
83
-	 * @return string[]
84
-	 */
85
-	protected function getCoreTemplateDirs($theme, $serverRoot) {
86
-		return [
87
-			$serverRoot.'/themes/'.$theme.'/core/templates/',
88
-			$serverRoot.'/core/templates/',
89
-		];
90
-	}
91
-
92
-	/**
93
-	 * Assign variables
94
-	 * @param string $key key
95
-	 * @param array|bool|integer|string $value value
96
-	 * @return bool
97
-	 *
98
-	 * This function assigns a variable. It can be accessed via $_[$key] in
99
-	 * the template.
100
-	 *
101
-	 * If the key existed before, it will be overwritten
102
-	 */
103
-	public function assign($key, $value) {
104
-		$this->vars[$key] = $value;
105
-		return true;
106
-	}
107
-
108
-	/**
109
-	 * Appends a variable
110
-	 * @param string $key key
111
-	 * @param mixed $value value
112
-	 *
113
-	 * This function assigns a variable in an array context. If the key already
114
-	 * exists, the value will be appended. It can be accessed via
115
-	 * $_[$key][$position] in the template.
116
-	 */
117
-	public function append($key, $value) {
118
-		if (array_key_exists($key, $this->vars)) {
119
-			$this->vars[$key][] = $value;
120
-		} else {
121
-			$this->vars[$key] = [ $value ];
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Prints the proceeded template
127
-	 * @return bool
128
-	 *
129
-	 * This function proceeds the template and prints its output.
130
-	 */
131
-	public function printPage() {
132
-		$data = $this->fetchPage();
133
-		if ($data === false) {
134
-			return false;
135
-		} else {
136
-			print $data;
137
-			return true;
138
-		}
139
-	}
140
-
141
-	/**
142
-	 * Process the template
143
-	 *
144
-	 * @param array|null $additionalParams
145
-	 * @return string This function processes the template.
146
-	 *
147
-	 * This function processes the template.
148
-	 */
149
-	public function fetchPage($additionalParams = null) {
150
-		return $this->load($this->template, $additionalParams);
151
-	}
152
-
153
-	/**
154
-	 * doing the actual work
155
-	 *
156
-	 * @param string $file
157
-	 * @param array|null $additionalParams
158
-	 * @return string content
159
-	 *
160
-	 * Includes the template file, fetches its output
161
-	 */
162
-	protected function load($file, $additionalParams = null) {
163
-		// Register the variables
164
-		$_ = $this->vars;
165
-		$l = $this->l10n;
166
-		$theme = $this->theme;
167
-
168
-		if (!is_null($additionalParams)) {
169
-			$_ = array_merge($additionalParams, $this->vars);
170
-			foreach ($_ as $var => $value) {
171
-				${$var} = $value;
172
-			}
173
-		}
174
-
175
-		// Include
176
-		ob_start();
177
-		try {
178
-			include $file;
179
-			$data = ob_get_contents();
180
-		} catch (\Exception $e) {
181
-			@ob_end_clean();
182
-			throw $e;
183
-		}
184
-		@ob_end_clean();
185
-
186
-		// Return data
187
-		return $data;
188
-	}
36
+    private $template; // The template
37
+    private $vars; // Vars
38
+
39
+    /** @var \OCP\IL10N */
40
+    private $l10n;
41
+
42
+    /** @var Defaults */
43
+    private $theme;
44
+
45
+    /**
46
+     * @param string $template
47
+     * @param string $requestToken
48
+     * @param \OCP\IL10N $l10n
49
+     * @param Defaults $theme
50
+     */
51
+    public function __construct($template, $requestToken, $l10n, $theme) {
52
+        $this->vars = [];
53
+        $this->vars['requesttoken'] = $requestToken;
54
+        $this->l10n = $l10n;
55
+        $this->template = $template;
56
+        $this->theme = $theme;
57
+    }
58
+
59
+    /**
60
+     * @param string $serverRoot
61
+     * @param string|false $app_dir
62
+     * @param string $theme
63
+     * @param string $app
64
+     * @return string[]
65
+     */
66
+    protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
67
+        // Check if the app is in the app folder or in the root
68
+        if (file_exists($app_dir.'/templates/')) {
69
+            return [
70
+                $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
71
+                $app_dir.'/templates/',
72
+            ];
73
+        }
74
+        return [
75
+            $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
76
+            $serverRoot.'/'.$app.'/templates/',
77
+        ];
78
+    }
79
+
80
+    /**
81
+     * @param string $serverRoot
82
+     * @param string $theme
83
+     * @return string[]
84
+     */
85
+    protected function getCoreTemplateDirs($theme, $serverRoot) {
86
+        return [
87
+            $serverRoot.'/themes/'.$theme.'/core/templates/',
88
+            $serverRoot.'/core/templates/',
89
+        ];
90
+    }
91
+
92
+    /**
93
+     * Assign variables
94
+     * @param string $key key
95
+     * @param array|bool|integer|string $value value
96
+     * @return bool
97
+     *
98
+     * This function assigns a variable. It can be accessed via $_[$key] in
99
+     * the template.
100
+     *
101
+     * If the key existed before, it will be overwritten
102
+     */
103
+    public function assign($key, $value) {
104
+        $this->vars[$key] = $value;
105
+        return true;
106
+    }
107
+
108
+    /**
109
+     * Appends a variable
110
+     * @param string $key key
111
+     * @param mixed $value value
112
+     *
113
+     * This function assigns a variable in an array context. If the key already
114
+     * exists, the value will be appended. It can be accessed via
115
+     * $_[$key][$position] in the template.
116
+     */
117
+    public function append($key, $value) {
118
+        if (array_key_exists($key, $this->vars)) {
119
+            $this->vars[$key][] = $value;
120
+        } else {
121
+            $this->vars[$key] = [ $value ];
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Prints the proceeded template
127
+     * @return bool
128
+     *
129
+     * This function proceeds the template and prints its output.
130
+     */
131
+    public function printPage() {
132
+        $data = $this->fetchPage();
133
+        if ($data === false) {
134
+            return false;
135
+        } else {
136
+            print $data;
137
+            return true;
138
+        }
139
+    }
140
+
141
+    /**
142
+     * Process the template
143
+     *
144
+     * @param array|null $additionalParams
145
+     * @return string This function processes the template.
146
+     *
147
+     * This function processes the template.
148
+     */
149
+    public function fetchPage($additionalParams = null) {
150
+        return $this->load($this->template, $additionalParams);
151
+    }
152
+
153
+    /**
154
+     * doing the actual work
155
+     *
156
+     * @param string $file
157
+     * @param array|null $additionalParams
158
+     * @return string content
159
+     *
160
+     * Includes the template file, fetches its output
161
+     */
162
+    protected function load($file, $additionalParams = null) {
163
+        // Register the variables
164
+        $_ = $this->vars;
165
+        $l = $this->l10n;
166
+        $theme = $this->theme;
167
+
168
+        if (!is_null($additionalParams)) {
169
+            $_ = array_merge($additionalParams, $this->vars);
170
+            foreach ($_ as $var => $value) {
171
+                ${$var} = $value;
172
+            }
173
+        }
174
+
175
+        // Include
176
+        ob_start();
177
+        try {
178
+            include $file;
179
+            $data = ob_get_contents();
180
+        } catch (\Exception $e) {
181
+            @ob_end_clean();
182
+            throw $e;
183
+        }
184
+        @ob_end_clean();
185
+
186
+        // Return data
187
+        return $data;
188
+    }
189 189
 }
Please login to merge, or discard this patch.
lib/private/Diagnostics/EventLogger.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -28,56 +28,56 @@
 block discarded – undo
28 28
 use OCP\Diagnostics\IEventLogger;
29 29
 
30 30
 class EventLogger implements IEventLogger {
31
-	/**
32
-	 * @var \OC\Diagnostics\Event[]
33
-	 */
34
-	private $events = [];
31
+    /**
32
+     * @var \OC\Diagnostics\Event[]
33
+     */
34
+    private $events = [];
35 35
 	
36
-	/**
37
-	 * @var bool - Module needs to be activated by some app
38
-	 */
39
-	private $activated = false;
36
+    /**
37
+     * @var bool - Module needs to be activated by some app
38
+     */
39
+    private $activated = false;
40 40
 
41
-	/**
42
-	 * @inheritdoc
43
-	 */
44
-	public function start($id, $description) {
45
-		if ($this->activated) {
46
-			$this->events[$id] = new Event($id, $description, microtime(true));
47
-		}
48
-	}
41
+    /**
42
+     * @inheritdoc
43
+     */
44
+    public function start($id, $description) {
45
+        if ($this->activated) {
46
+            $this->events[$id] = new Event($id, $description, microtime(true));
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function end($id) {
54
-		if ($this->activated && isset($this->events[$id])) {
55
-			$timing = $this->events[$id];
56
-			$timing->end(microtime(true));
57
-		}
58
-	}
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function end($id) {
54
+        if ($this->activated && isset($this->events[$id])) {
55
+            $timing = $this->events[$id];
56
+            $timing->end(microtime(true));
57
+        }
58
+    }
59 59
 
60
-	/**
61
-	 * @inheritdoc
62
-	 */
63
-	public function log($id, $description, $start, $end) {
64
-		if ($this->activated) {
65
-			$this->events[$id] = new Event($id, $description, $start);
66
-			$this->events[$id]->end($end);
67
-		}
68
-	}
60
+    /**
61
+     * @inheritdoc
62
+     */
63
+    public function log($id, $description, $start, $end) {
64
+        if ($this->activated) {
65
+            $this->events[$id] = new Event($id, $description, $start);
66
+            $this->events[$id]->end($end);
67
+        }
68
+    }
69 69
 
70
-	/**
71
-	 * @inheritdoc
72
-	 */
73
-	public function getEvents() {
74
-		return $this->events;
75
-	}
70
+    /**
71
+     * @inheritdoc
72
+     */
73
+    public function getEvents() {
74
+        return $this->events;
75
+    }
76 76
 	
77
-	/**
78
-	 * @inheritdoc
79
-	 */
80
-	public function activate() {
81
-		$this->activated = true;
82
-	}
77
+    /**
78
+     * @inheritdoc
79
+     */
80
+    public function activate() {
81
+        $this->activated = true;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
lib/private/Cache/CappedMemoryCache.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -30,66 +30,66 @@
 block discarded – undo
30 30
  * Uses a simple FIFO expiry mechanism
31 31
  */
32 32
 class CappedMemoryCache implements ICache, \ArrayAccess {
33
-	private $capacity;
34
-	private $cache = [];
35
-
36
-	public function __construct($capacity = 512) {
37
-		$this->capacity = $capacity;
38
-	}
39
-
40
-	public function hasKey($key) {
41
-		return isset($this->cache[$key]);
42
-	}
43
-
44
-	public function get($key) {
45
-		return isset($this->cache[$key]) ? $this->cache[$key] : null;
46
-	}
47
-
48
-	public function set($key, $value, $ttl = 0) {
49
-		if (is_null($key)) {
50
-			$this->cache[] = $value;
51
-		} else {
52
-			$this->cache[$key] = $value;
53
-		}
54
-		$this->garbageCollect();
55
-	}
56
-
57
-	public function remove($key) {
58
-		unset($this->cache[$key]);
59
-		return true;
60
-	}
61
-
62
-	public function clear($prefix = '') {
63
-		$this->cache = [];
64
-		return true;
65
-	}
66
-
67
-	public function offsetExists($offset) {
68
-		return $this->hasKey($offset);
69
-	}
70
-
71
-	public function &offsetGet($offset) {
72
-		return $this->cache[$offset];
73
-	}
74
-
75
-	public function offsetSet($offset, $value) {
76
-		$this->set($offset, $value);
77
-	}
78
-
79
-	public function offsetUnset($offset) {
80
-		$this->remove($offset);
81
-	}
82
-
83
-	public function getData() {
84
-		return $this->cache;
85
-	}
86
-
87
-
88
-	private function garbageCollect() {
89
-		while (count($this->cache) > $this->capacity) {
90
-			reset($this->cache);
91
-			$key = key($this->cache);
92
-			$this->remove($key);
93
-		}
94
-	}
33
+    private $capacity;
34
+    private $cache = [];
35
+
36
+    public function __construct($capacity = 512) {
37
+        $this->capacity = $capacity;
38
+    }
39
+
40
+    public function hasKey($key) {
41
+        return isset($this->cache[$key]);
42
+    }
43
+
44
+    public function get($key) {
45
+        return isset($this->cache[$key]) ? $this->cache[$key] : null;
46
+    }
47
+
48
+    public function set($key, $value, $ttl = 0) {
49
+        if (is_null($key)) {
50
+            $this->cache[] = $value;
51
+        } else {
52
+            $this->cache[$key] = $value;
53
+        }
54
+        $this->garbageCollect();
55
+    }
56
+
57
+    public function remove($key) {
58
+        unset($this->cache[$key]);
59
+        return true;
60
+    }
61
+
62
+    public function clear($prefix = '') {
63
+        $this->cache = [];
64
+        return true;
65
+    }
66
+
67
+    public function offsetExists($offset) {
68
+        return $this->hasKey($offset);
69
+    }
70
+
71
+    public function &offsetGet($offset) {
72
+        return $this->cache[$offset];
73
+    }
74
+
75
+    public function offsetSet($offset, $value) {
76
+        $this->set($offset, $value);
77
+    }
78
+
79
+    public function offsetUnset($offset) {
80
+        $this->remove($offset);
81
+    }
82
+
83
+    public function getData() {
84
+        return $this->cache;
85
+    }
86
+
87
+
88
+    private function garbageCollect() {
89
+        while (count($this->cache) > $this->capacity) {
90
+            reset($this->cache);
91
+            $key = key($this->cache);
92
+            $this->remove($key);
93
+        }
94
+    }
95 95
 }
Please login to merge, or discard this patch.
lib/private/Search.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		$results = [];
62 62
 		foreach ($this->providers as $provider) {
63 63
 			/** @var $provider Provider */
64
-			if (! $provider->providesResultsFor($inApps)) {
64
+			if (!$provider->providesResultsFor($inApps)) {
65 65
 				continue;
66 66
 			}
67 67
 			if ($provider instanceof PagedProvider) {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	public function removeProvider($provider) {
97 97
 		$this->registeredProviders = array_filter(
98 98
 			$this->registeredProviders,
99
-			function ($element) use ($provider) {
99
+			function($element) use ($provider) {
100 100
 				return ($element['class'] != $provider);
101 101
 			}
102 102
 		);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * Create instances of all the registered search providers
118 118
 	 */
119 119
 	private function initProviders() {
120
-		if (! empty($this->providers)) {
120
+		if (!empty($this->providers)) {
121 121
 			return;
122 122
 		}
123 123
 		foreach ($this->registeredProviders as $provider) {
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -36,85 +36,85 @@
 block discarded – undo
36 36
  * Provide an interface to all search providers
37 37
  */
38 38
 class Search implements ISearch {
39
-	private $providers = [];
40
-	private $registeredProviders = [];
39
+    private $providers = [];
40
+    private $registeredProviders = [];
41 41
 
42
-	/**
43
-	 * Search all providers for $query
44
-	 * @param string $query
45
-	 * @param string[] $inApps optionally limit results to the given apps
46
-	 * @param int $page pages start at page 1
47
-	 * @param int $size, 0 = all
48
-	 * @return array An array of OC\Search\Result's
49
-	 */
50
-	public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) {
51
-		$this->initProviders();
52
-		$results = [];
53
-		foreach ($this->providers as $provider) {
54
-			/** @var $provider Provider */
55
-			if (! $provider->providesResultsFor($inApps)) {
56
-				continue;
57
-			}
58
-			if ($provider instanceof PagedProvider) {
59
-				$results = array_merge($results, $provider->searchPaged($query, $page, $size));
60
-			} elseif ($provider instanceof Provider) {
61
-				$providerResults = $provider->search($query);
62
-				if ($size > 0) {
63
-					$slicedResults = array_slice($providerResults, ($page - 1) * $size, $size);
64
-					$results = array_merge($results, $slicedResults);
65
-				} else {
66
-					$results = array_merge($results, $providerResults);
67
-				}
68
-			} else {
69
-				\OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]);
70
-			}
71
-		}
72
-		return $results;
73
-	}
42
+    /**
43
+     * Search all providers for $query
44
+     * @param string $query
45
+     * @param string[] $inApps optionally limit results to the given apps
46
+     * @param int $page pages start at page 1
47
+     * @param int $size, 0 = all
48
+     * @return array An array of OC\Search\Result's
49
+     */
50
+    public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) {
51
+        $this->initProviders();
52
+        $results = [];
53
+        foreach ($this->providers as $provider) {
54
+            /** @var $provider Provider */
55
+            if (! $provider->providesResultsFor($inApps)) {
56
+                continue;
57
+            }
58
+            if ($provider instanceof PagedProvider) {
59
+                $results = array_merge($results, $provider->searchPaged($query, $page, $size));
60
+            } elseif ($provider instanceof Provider) {
61
+                $providerResults = $provider->search($query);
62
+                if ($size > 0) {
63
+                    $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size);
64
+                    $results = array_merge($results, $slicedResults);
65
+                } else {
66
+                    $results = array_merge($results, $providerResults);
67
+                }
68
+            } else {
69
+                \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]);
70
+            }
71
+        }
72
+        return $results;
73
+    }
74 74
 
75
-	/**
76
-	 * Remove all registered search providers
77
-	 */
78
-	public function clearProviders() {
79
-		$this->providers = [];
80
-		$this->registeredProviders = [];
81
-	}
75
+    /**
76
+     * Remove all registered search providers
77
+     */
78
+    public function clearProviders() {
79
+        $this->providers = [];
80
+        $this->registeredProviders = [];
81
+    }
82 82
 
83
-	/**
84
-	 * Remove one existing search provider
85
-	 * @param string $provider class name of a OC\Search\Provider
86
-	 */
87
-	public function removeProvider($provider) {
88
-		$this->registeredProviders = array_filter(
89
-			$this->registeredProviders,
90
-			function ($element) use ($provider) {
91
-				return ($element['class'] != $provider);
92
-			}
93
-		);
94
-		// force regeneration of providers on next search
95
-		$this->providers = [];
96
-	}
83
+    /**
84
+     * Remove one existing search provider
85
+     * @param string $provider class name of a OC\Search\Provider
86
+     */
87
+    public function removeProvider($provider) {
88
+        $this->registeredProviders = array_filter(
89
+            $this->registeredProviders,
90
+            function ($element) use ($provider) {
91
+                return ($element['class'] != $provider);
92
+            }
93
+        );
94
+        // force regeneration of providers on next search
95
+        $this->providers = [];
96
+    }
97 97
 
98
-	/**
99
-	 * Register a new search provider to search with
100
-	 * @param string $class class name of a OC\Search\Provider
101
-	 * @param array $options optional
102
-	 */
103
-	public function registerProvider($class, array $options = []) {
104
-		$this->registeredProviders[] = ['class' => $class, 'options' => $options];
105
-	}
98
+    /**
99
+     * Register a new search provider to search with
100
+     * @param string $class class name of a OC\Search\Provider
101
+     * @param array $options optional
102
+     */
103
+    public function registerProvider($class, array $options = []) {
104
+        $this->registeredProviders[] = ['class' => $class, 'options' => $options];
105
+    }
106 106
 
107
-	/**
108
-	 * Create instances of all the registered search providers
109
-	 */
110
-	private function initProviders() {
111
-		if (! empty($this->providers)) {
112
-			return;
113
-		}
114
-		foreach ($this->registeredProviders as $provider) {
115
-			$class = $provider['class'];
116
-			$options = $provider['options'];
117
-			$this->providers[] = new $class($options);
118
-		}
119
-	}
107
+    /**
108
+     * Create instances of all the registered search providers
109
+     */
110
+    private function initProviders() {
111
+        if (! empty($this->providers)) {
112
+            return;
113
+        }
114
+        foreach ($this->registeredProviders as $provider) {
115
+            $class = $provider['class'];
116
+            $options = $provider['options'];
117
+            $this->providers[] = new $class($options);
118
+        }
119
+    }
120 120
 }
Please login to merge, or discard this patch.
lib/private/Security/Certificate.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -27,104 +27,104 @@
 block discarded – undo
27 27
 use OCP\ICertificate;
28 28
 
29 29
 class Certificate implements ICertificate {
30
-	protected $name;
31
-
32
-	protected $commonName;
33
-
34
-	protected $organization;
35
-
36
-	protected $serial;
37
-
38
-	protected $issueDate;
39
-
40
-	protected $expireDate;
41
-
42
-	protected $issuerName;
43
-
44
-	protected $issuerOrganization;
45
-
46
-	/**
47
-	 * @param string $data base64 encoded certificate
48
-	 * @param string $name
49
-	 * @throws \Exception If the certificate could not get parsed
50
-	 */
51
-	public function __construct($data, $name) {
52
-		$this->name = $name;
53
-		$gmt = new \DateTimeZone('GMT');
54
-
55
-		// If string starts with "file://" ignore the certificate
56
-		$query = 'file://';
57
-		if (strtolower(substr($data, 0, strlen($query))) === $query) {
58
-			throw new \Exception('Certificate could not get parsed.');
59
-		}
60
-
61
-		$info = openssl_x509_parse($data);
62
-		if (!is_array($info)) {
63
-			throw new \Exception('Certificate could not get parsed.');
64
-		}
65
-
66
-		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
-		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
-		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
-		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
-	}
73
-
74
-	/**
75
-	 * @return string
76
-	 */
77
-	public function getName() {
78
-		return $this->name;
79
-	}
80
-
81
-	/**
82
-	 * @return string|null
83
-	 */
84
-	public function getCommonName() {
85
-		return $this->commonName;
86
-	}
87
-
88
-	/**
89
-	 * @return string
90
-	 */
91
-	public function getOrganization() {
92
-		return $this->organization;
93
-	}
94
-
95
-	/**
96
-	 * @return \DateTime
97
-	 */
98
-	public function getIssueDate() {
99
-		return $this->issueDate;
100
-	}
101
-
102
-	/**
103
-	 * @return \DateTime
104
-	 */
105
-	public function getExpireDate() {
106
-		return $this->expireDate;
107
-	}
108
-
109
-	/**
110
-	 * @return bool
111
-	 */
112
-	public function isExpired() {
113
-		$now = new \DateTime();
114
-		return $this->issueDate > $now or $now > $this->expireDate;
115
-	}
116
-
117
-	/**
118
-	 * @return string|null
119
-	 */
120
-	public function getIssuerName() {
121
-		return $this->issuerName;
122
-	}
123
-
124
-	/**
125
-	 * @return string|null
126
-	 */
127
-	public function getIssuerOrganization() {
128
-		return $this->issuerOrganization;
129
-	}
30
+    protected $name;
31
+
32
+    protected $commonName;
33
+
34
+    protected $organization;
35
+
36
+    protected $serial;
37
+
38
+    protected $issueDate;
39
+
40
+    protected $expireDate;
41
+
42
+    protected $issuerName;
43
+
44
+    protected $issuerOrganization;
45
+
46
+    /**
47
+     * @param string $data base64 encoded certificate
48
+     * @param string $name
49
+     * @throws \Exception If the certificate could not get parsed
50
+     */
51
+    public function __construct($data, $name) {
52
+        $this->name = $name;
53
+        $gmt = new \DateTimeZone('GMT');
54
+
55
+        // If string starts with "file://" ignore the certificate
56
+        $query = 'file://';
57
+        if (strtolower(substr($data, 0, strlen($query))) === $query) {
58
+            throw new \Exception('Certificate could not get parsed.');
59
+        }
60
+
61
+        $info = openssl_x509_parse($data);
62
+        if (!is_array($info)) {
63
+            throw new \Exception('Certificate could not get parsed.');
64
+        }
65
+
66
+        $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67
+        $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
+        $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
+        $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
70
+        $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71
+        $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72
+    }
73
+
74
+    /**
75
+     * @return string
76
+     */
77
+    public function getName() {
78
+        return $this->name;
79
+    }
80
+
81
+    /**
82
+     * @return string|null
83
+     */
84
+    public function getCommonName() {
85
+        return $this->commonName;
86
+    }
87
+
88
+    /**
89
+     * @return string
90
+     */
91
+    public function getOrganization() {
92
+        return $this->organization;
93
+    }
94
+
95
+    /**
96
+     * @return \DateTime
97
+     */
98
+    public function getIssueDate() {
99
+        return $this->issueDate;
100
+    }
101
+
102
+    /**
103
+     * @return \DateTime
104
+     */
105
+    public function getExpireDate() {
106
+        return $this->expireDate;
107
+    }
108
+
109
+    /**
110
+     * @return bool
111
+     */
112
+    public function isExpired() {
113
+        $now = new \DateTime();
114
+        return $this->issueDate > $now or $now > $this->expireDate;
115
+    }
116
+
117
+    /**
118
+     * @return string|null
119
+     */
120
+    public function getIssuerName() {
121
+        return $this->issuerName;
122
+    }
123
+
124
+    /**
125
+     * @return string|null
126
+     */
127
+    public function getIssuerOrganization() {
128
+        return $this->issuerOrganization;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@
 block discarded – undo
65 65
 
66 66
 		$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
67 67
 		$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
68
-		$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
69
-		$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
68
+		$this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt);
69
+		$this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt);
70 70
 		$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
71 71
 		$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
72 72
 	}
Please login to merge, or discard this patch.
lib/private/Security/IdentityProof/Signer.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
 			$user = $this->userManager->get($userId);
90 90
 			if ($user !== null) {
91 91
 				$key = $this->keyManager->getKey($user);
92
-				return (bool)openssl_verify(
92
+				return (bool) openssl_verify(
93 93
 					json_encode($data['message']),
94 94
 					base64_decode($data['signature']),
95 95
 					$key->getPublic(),
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -32,76 +32,76 @@
 block discarded – undo
32 32
 use OCP\IUserManager;
33 33
 
34 34
 class Signer {
35
-	/** @var Manager */
36
-	private $keyManager;
37
-	/** @var ITimeFactory */
38
-	private $timeFactory;
39
-	/** @var IUserManager */
40
-	private $userManager;
35
+    /** @var Manager */
36
+    private $keyManager;
37
+    /** @var ITimeFactory */
38
+    private $timeFactory;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/**
43
-	 * @param Manager $keyManager
44
-	 * @param ITimeFactory $timeFactory
45
-	 * @param IUserManager $userManager
46
-	 */
47
-	public function __construct(Manager $keyManager,
48
-								ITimeFactory $timeFactory,
49
-								IUserManager $userManager) {
50
-		$this->keyManager = $keyManager;
51
-		$this->timeFactory = $timeFactory;
52
-		$this->userManager = $userManager;
53
-	}
42
+    /**
43
+     * @param Manager $keyManager
44
+     * @param ITimeFactory $timeFactory
45
+     * @param IUserManager $userManager
46
+     */
47
+    public function __construct(Manager $keyManager,
48
+                                ITimeFactory $timeFactory,
49
+                                IUserManager $userManager) {
50
+        $this->keyManager = $keyManager;
51
+        $this->timeFactory = $timeFactory;
52
+        $this->userManager = $userManager;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns a signed blob for $data
57
-	 *
58
-	 * @param string $type
59
-	 * @param array $data
60
-	 * @param IUser $user
61
-	 * @return array ['message', 'signature']
62
-	 */
63
-	public function sign(string $type, array $data, IUser $user): array {
64
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
65
-		$data = [
66
-			'data' => $data,
67
-			'type' => $type,
68
-			'signer' => $user->getCloudId(),
69
-			'timestamp' => $this->timeFactory->getTime(),
70
-		];
71
-		openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512);
55
+    /**
56
+     * Returns a signed blob for $data
57
+     *
58
+     * @param string $type
59
+     * @param array $data
60
+     * @param IUser $user
61
+     * @return array ['message', 'signature']
62
+     */
63
+    public function sign(string $type, array $data, IUser $user): array {
64
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
65
+        $data = [
66
+            'data' => $data,
67
+            'type' => $type,
68
+            'signer' => $user->getCloudId(),
69
+            'timestamp' => $this->timeFactory->getTime(),
70
+        ];
71
+        openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512);
72 72
 
73
-		return [
74
-			'message' => $data,
75
-			'signature' => base64_encode($signature),
76
-		];
77
-	}
73
+        return [
74
+            'message' => $data,
75
+            'signature' => base64_encode($signature),
76
+        ];
77
+    }
78 78
 
79
-	/**
80
-	 * Whether the data is signed properly
81
-	 *
82
-	 * @param array $data
83
-	 * @return bool
84
-	 */
85
-	public function verify(array $data): bool {
86
-		if (isset($data['message'])
87
-			&& isset($data['signature'])
88
-			&& isset($data['message']['signer'])
89
-		) {
90
-			$location = strrpos($data['message']['signer'], '@');
91
-			$userId = substr($data['message']['signer'], 0, $location);
79
+    /**
80
+     * Whether the data is signed properly
81
+     *
82
+     * @param array $data
83
+     * @return bool
84
+     */
85
+    public function verify(array $data): bool {
86
+        if (isset($data['message'])
87
+            && isset($data['signature'])
88
+            && isset($data['message']['signer'])
89
+        ) {
90
+            $location = strrpos($data['message']['signer'], '@');
91
+            $userId = substr($data['message']['signer'], 0, $location);
92 92
 
93
-			$user = $this->userManager->get($userId);
94
-			if ($user !== null) {
95
-				$key = $this->keyManager->getKey($user);
96
-				return (bool)openssl_verify(
97
-					json_encode($data['message']),
98
-					base64_decode($data['signature']),
99
-					$key->getPublic(),
100
-					OPENSSL_ALGO_SHA512
101
-				);
102
-			}
103
-		}
93
+            $user = $this->userManager->get($userId);
94
+            if ($user !== null) {
95
+                $key = $this->keyManager->getKey($user);
96
+                return (bool)openssl_verify(
97
+                    json_encode($data['message']),
98
+                    base64_decode($data['signature']),
99
+                    $key->getPublic(),
100
+                    OPENSSL_ALGO_SHA512
101
+                );
102
+            }
103
+        }
104 104
 
105
-		return false;
106
-	}
105
+        return false;
106
+    }
107 107
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Exceptions/EncryptionHeaderToLargeException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 use OCP\Encryption\Exceptions\GenericEncryptionException;
28 28
 
29 29
 class EncryptionHeaderToLargeException extends GenericEncryptionException {
30
-	public function __construct() {
31
-		parent::__construct('max header size exceeded');
32
-	}
30
+    public function __construct() {
31
+        parent::__construct('max header size exceeded');
32
+    }
33 33
 }
Please login to merge, or discard this patch.
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -33,95 +33,95 @@
 block discarded – undo
33 33
 
34 34
 class File implements \OCP\Encryption\IFile {
35 35
 
36
-	/** @var Util */
37
-	protected $util;
38
-
39
-	/** @var IRootFolder */
40
-	private $rootFolder;
41
-
42
-	/** @var IManager */
43
-	private $shareManager;
44
-
45
-	/**
46
-	 * cache results of already checked folders
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $cache;
51
-
52
-	public function __construct(Util $util,
53
-								IRootFolder $rootFolder,
54
-								IManager $shareManager) {
55
-		$this->util = $util;
56
-		$this->cache = new CappedMemoryCache();
57
-		$this->rootFolder = $rootFolder;
58
-		$this->shareManager = $shareManager;
59
-	}
60
-
61
-
62
-	/**
63
-	 * get list of users with access to the file
64
-	 *
65
-	 * @param string $path to the file
66
-	 * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
-	 */
68
-	public function getAccessList($path) {
69
-
70
-		// Make sure that a share key is generated for the owner too
71
-		list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
-
73
-		// always add owner to the list of users with access to the file
74
-		$userIds = [$owner];
75
-
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
-			return ['users' => $userIds, 'public' => false];
78
-		}
79
-
80
-		$ownerPath = substr($ownerPath, strlen('/files'));
81
-		$userFolder = $this->rootFolder->getUserFolder($owner);
82
-		try {
83
-			$file = $userFolder->get($ownerPath);
84
-		} catch (NotFoundException $e) {
85
-			$file = null;
86
-		}
87
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
-
89
-		// first get the shares for the parent and cache the result so that we don't
90
-		// need to check all parents for every file
91
-		$parent = dirname($ownerPath);
92
-		$parentNode = $userFolder->get($parent);
93
-		if (isset($this->cache[$parent])) {
94
-			$resultForParents = $this->cache[$parent];
95
-		} else {
96
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
97
-			$this->cache[$parent] = $resultForParents;
98
-		}
99
-		$userIds = array_merge($userIds, $resultForParents['users']);
100
-		$public = $resultForParents['public'] || $resultForParents['remote'];
101
-
102
-
103
-		// Find out who, if anyone, is sharing the file
104
-		if ($file !== null) {
105
-			$resultForFile = $this->shareManager->getAccessList($file, false);
106
-			$userIds = array_merge($userIds, $resultForFile['users']);
107
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
-		}
109
-
110
-		// check if it is a group mount
111
-		if (\OCP\App::isEnabled("files_external")) {
112
-			$mounts = \OC_Mount_Config::getSystemMountPoints();
113
-			foreach ($mounts as $mount) {
114
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
-					$userIds = array_merge($userIds, $mountedFor);
117
-				}
118
-			}
119
-		}
120
-
121
-		// Remove duplicate UIDs
122
-		$uniqueUserIds = array_unique($userIds);
123
-
124
-		return ['users' => $uniqueUserIds, 'public' => $public];
125
-	}
36
+    /** @var Util */
37
+    protected $util;
38
+
39
+    /** @var IRootFolder */
40
+    private $rootFolder;
41
+
42
+    /** @var IManager */
43
+    private $shareManager;
44
+
45
+    /**
46
+     * cache results of already checked folders
47
+     *
48
+     * @var array
49
+     */
50
+    protected $cache;
51
+
52
+    public function __construct(Util $util,
53
+                                IRootFolder $rootFolder,
54
+                                IManager $shareManager) {
55
+        $this->util = $util;
56
+        $this->cache = new CappedMemoryCache();
57
+        $this->rootFolder = $rootFolder;
58
+        $this->shareManager = $shareManager;
59
+    }
60
+
61
+
62
+    /**
63
+     * get list of users with access to the file
64
+     *
65
+     * @param string $path to the file
66
+     * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
+     */
68
+    public function getAccessList($path) {
69
+
70
+        // Make sure that a share key is generated for the owner too
71
+        list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
+
73
+        // always add owner to the list of users with access to the file
74
+        $userIds = [$owner];
75
+
76
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
+            return ['users' => $userIds, 'public' => false];
78
+        }
79
+
80
+        $ownerPath = substr($ownerPath, strlen('/files'));
81
+        $userFolder = $this->rootFolder->getUserFolder($owner);
82
+        try {
83
+            $file = $userFolder->get($ownerPath);
84
+        } catch (NotFoundException $e) {
85
+            $file = null;
86
+        }
87
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
+
89
+        // first get the shares for the parent and cache the result so that we don't
90
+        // need to check all parents for every file
91
+        $parent = dirname($ownerPath);
92
+        $parentNode = $userFolder->get($parent);
93
+        if (isset($this->cache[$parent])) {
94
+            $resultForParents = $this->cache[$parent];
95
+        } else {
96
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
97
+            $this->cache[$parent] = $resultForParents;
98
+        }
99
+        $userIds = array_merge($userIds, $resultForParents['users']);
100
+        $public = $resultForParents['public'] || $resultForParents['remote'];
101
+
102
+
103
+        // Find out who, if anyone, is sharing the file
104
+        if ($file !== null) {
105
+            $resultForFile = $this->shareManager->getAccessList($file, false);
106
+            $userIds = array_merge($userIds, $resultForFile['users']);
107
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
+        }
109
+
110
+        // check if it is a group mount
111
+        if (\OCP\App::isEnabled("files_external")) {
112
+            $mounts = \OC_Mount_Config::getSystemMountPoints();
113
+            foreach ($mounts as $mount) {
114
+                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
+                    $userIds = array_merge($userIds, $mountedFor);
117
+                }
118
+            }
119
+        }
120
+
121
+        // Remove duplicate UIDs
122
+        $uniqueUserIds = array_unique($userIds);
123
+
124
+        return ['users' => $uniqueUserIds, 'public' => $public];
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Update.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,159 +33,159 @@
 block discarded – undo
33 33
  */
34 34
 class Update {
35 35
 
36
-	/** @var \OC\Files\View */
37
-	protected $view;
38
-
39
-	/** @var \OC\Encryption\Util */
40
-	protected $util;
41
-
42
-	/** @var \OC\Files\Mount\Manager */
43
-	protected $mountManager;
44
-
45
-	/** @var \OC\Encryption\Manager */
46
-	protected $encryptionManager;
47
-
48
-	/** @var string */
49
-	protected $uid;
50
-
51
-	/** @var \OC\Encryption\File */
52
-	protected $file;
53
-
54
-	/**
55
-	 *
56
-	 * @param \OC\Files\View $view
57
-	 * @param \OC\Encryption\Util $util
58
-	 * @param \OC\Files\Mount\Manager $mountManager
59
-	 * @param \OC\Encryption\Manager $encryptionManager
60
-	 * @param \OC\Encryption\File $file
61
-	 * @param string $uid
62
-	 */
63
-	public function __construct(
64
-			View $view,
65
-			Util $util,
66
-			Mount\Manager $mountManager,
67
-			Manager $encryptionManager,
68
-			File $file,
69
-			$uid
70
-		) {
71
-		$this->view = $view;
72
-		$this->util = $util;
73
-		$this->mountManager = $mountManager;
74
-		$this->encryptionManager = $encryptionManager;
75
-		$this->file = $file;
76
-		$this->uid = $uid;
77
-	}
78
-
79
-	/**
80
-	 * hook after file was shared
81
-	 *
82
-	 * @param array $params
83
-	 */
84
-	public function postShared($params) {
85
-		if ($this->encryptionManager->isEnabled()) {
86
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
-				$path = Filesystem::getPath($params['fileSource']);
88
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
90
-				$this->update($absPath);
91
-			}
92
-		}
93
-	}
94
-
95
-	/**
96
-	 * hook after file was unshared
97
-	 *
98
-	 * @param array $params
99
-	 */
100
-	public function postUnshared($params) {
101
-		if ($this->encryptionManager->isEnabled()) {
102
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
-				$path = Filesystem::getPath($params['fileSource']);
104
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
106
-				$this->update($absPath);
107
-			}
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * inform encryption module that a file was restored from the trash bin,
113
-	 * e.g. to update the encryption keys
114
-	 *
115
-	 * @param array $params
116
-	 */
117
-	public function postRestore($params) {
118
-		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
-			$this->update($path);
121
-		}
122
-	}
123
-
124
-	/**
125
-	 * inform encryption module that a file was renamed,
126
-	 * e.g. to update the encryption keys
127
-	 *
128
-	 * @param array $params
129
-	 */
130
-	public function postRename($params) {
131
-		$source = $params['oldpath'];
132
-		$target = $params['newpath'];
133
-		if (
134
-			$this->encryptionManager->isEnabled() &&
135
-			dirname($source) !== dirname($target)
136
-		) {
137
-			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
139
-			$this->update($absPath);
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * get owner and path relative to data/<owner>/files
145
-	 *
146
-	 * @param string $path path to file for current user
147
-	 * @return array ['owner' => $owner, 'path' => $path]
148
-	 * @throw \InvalidArgumentException
149
-	 */
150
-	protected function getOwnerPath($path) {
151
-		$info = Filesystem::getFileInfo($path);
152
-		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
154
-		$path = $view->getPath($info->getId());
155
-		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
-		}
158
-
159
-		return [$owner, $path];
160
-	}
161
-
162
-	/**
163
-	 * notify encryption module about added/removed users from a file/folder
164
-	 *
165
-	 * @param string $path relative to data/
166
-	 * @throws Exceptions\ModuleDoesNotExistsException
167
-	 */
168
-	public function update($path) {
169
-		$encryptionModule = $this->encryptionManager->getEncryptionModule();
170
-
171
-		// if the encryption module doesn't encrypt the files on a per-user basis
172
-		// we have nothing to do here.
173
-		if ($encryptionModule->needDetailedAccessList() === false) {
174
-			return;
175
-		}
176
-
177
-		// if a folder was shared, get a list of all (sub-)folders
178
-		if ($this->view->is_dir($path)) {
179
-			$allFiles = $this->util->getAllFiles($path);
180
-		} else {
181
-			$allFiles = [$path];
182
-		}
183
-
184
-
185
-
186
-		foreach ($allFiles as $file) {
187
-			$usersSharing = $this->file->getAccessList($file);
188
-			$encryptionModule->update($file, $this->uid, $usersSharing);
189
-		}
190
-	}
36
+    /** @var \OC\Files\View */
37
+    protected $view;
38
+
39
+    /** @var \OC\Encryption\Util */
40
+    protected $util;
41
+
42
+    /** @var \OC\Files\Mount\Manager */
43
+    protected $mountManager;
44
+
45
+    /** @var \OC\Encryption\Manager */
46
+    protected $encryptionManager;
47
+
48
+    /** @var string */
49
+    protected $uid;
50
+
51
+    /** @var \OC\Encryption\File */
52
+    protected $file;
53
+
54
+    /**
55
+     *
56
+     * @param \OC\Files\View $view
57
+     * @param \OC\Encryption\Util $util
58
+     * @param \OC\Files\Mount\Manager $mountManager
59
+     * @param \OC\Encryption\Manager $encryptionManager
60
+     * @param \OC\Encryption\File $file
61
+     * @param string $uid
62
+     */
63
+    public function __construct(
64
+            View $view,
65
+            Util $util,
66
+            Mount\Manager $mountManager,
67
+            Manager $encryptionManager,
68
+            File $file,
69
+            $uid
70
+        ) {
71
+        $this->view = $view;
72
+        $this->util = $util;
73
+        $this->mountManager = $mountManager;
74
+        $this->encryptionManager = $encryptionManager;
75
+        $this->file = $file;
76
+        $this->uid = $uid;
77
+    }
78
+
79
+    /**
80
+     * hook after file was shared
81
+     *
82
+     * @param array $params
83
+     */
84
+    public function postShared($params) {
85
+        if ($this->encryptionManager->isEnabled()) {
86
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
+                $path = Filesystem::getPath($params['fileSource']);
88
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
89
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
90
+                $this->update($absPath);
91
+            }
92
+        }
93
+    }
94
+
95
+    /**
96
+     * hook after file was unshared
97
+     *
98
+     * @param array $params
99
+     */
100
+    public function postUnshared($params) {
101
+        if ($this->encryptionManager->isEnabled()) {
102
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
+                $path = Filesystem::getPath($params['fileSource']);
104
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
105
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
106
+                $this->update($absPath);
107
+            }
108
+        }
109
+    }
110
+
111
+    /**
112
+     * inform encryption module that a file was restored from the trash bin,
113
+     * e.g. to update the encryption keys
114
+     *
115
+     * @param array $params
116
+     */
117
+    public function postRestore($params) {
118
+        if ($this->encryptionManager->isEnabled()) {
119
+            $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
+            $this->update($path);
121
+        }
122
+    }
123
+
124
+    /**
125
+     * inform encryption module that a file was renamed,
126
+     * e.g. to update the encryption keys
127
+     *
128
+     * @param array $params
129
+     */
130
+    public function postRename($params) {
131
+        $source = $params['oldpath'];
132
+        $target = $params['newpath'];
133
+        if (
134
+            $this->encryptionManager->isEnabled() &&
135
+            dirname($source) !== dirname($target)
136
+        ) {
137
+            list($owner, $ownerPath) = $this->getOwnerPath($target);
138
+            $absPath = '/' . $owner . '/files/' . $ownerPath;
139
+            $this->update($absPath);
140
+        }
141
+    }
142
+
143
+    /**
144
+     * get owner and path relative to data/<owner>/files
145
+     *
146
+     * @param string $path path to file for current user
147
+     * @return array ['owner' => $owner, 'path' => $path]
148
+     * @throw \InvalidArgumentException
149
+     */
150
+    protected function getOwnerPath($path) {
151
+        $info = Filesystem::getFileInfo($path);
152
+        $owner = Filesystem::getOwner($path);
153
+        $view = new View('/' . $owner . '/files');
154
+        $path = $view->getPath($info->getId());
155
+        if ($path === null) {
156
+            throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
+        }
158
+
159
+        return [$owner, $path];
160
+    }
161
+
162
+    /**
163
+     * notify encryption module about added/removed users from a file/folder
164
+     *
165
+     * @param string $path relative to data/
166
+     * @throws Exceptions\ModuleDoesNotExistsException
167
+     */
168
+    public function update($path) {
169
+        $encryptionModule = $this->encryptionManager->getEncryptionModule();
170
+
171
+        // if the encryption module doesn't encrypt the files on a per-user basis
172
+        // we have nothing to do here.
173
+        if ($encryptionModule->needDetailedAccessList() === false) {
174
+            return;
175
+        }
176
+
177
+        // if a folder was shared, get a list of all (sub-)folders
178
+        if ($this->view->is_dir($path)) {
179
+            $allFiles = $this->util->getAllFiles($path);
180
+        } else {
181
+            $allFiles = [$path];
182
+        }
183
+
184
+
185
+
186
+        foreach ($allFiles as $file) {
187
+            $usersSharing = $this->file->getAccessList($file);
188
+            $encryptionModule->update($file, $this->uid, $usersSharing);
189
+        }
190
+    }
191 191
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87 87
 				$path = Filesystem::getPath($params['fileSource']);
88 88
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
89
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
90 90
 				$this->update($absPath);
91 91
 			}
92 92
 		}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103 103
 				$path = Filesystem::getPath($params['fileSource']);
104 104
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
105
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
106 106
 				$this->update($absPath);
107 107
 			}
108 108
 		}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public function postRestore($params) {
118 118
 		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
119
+			$path = Filesystem::normalizePath('/'.$this->uid.'/files/'.$params['filePath']);
120 120
 			$this->update($path);
121 121
 		}
122 122
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 			dirname($source) !== dirname($target)
136 136
 		) {
137 137
 			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
138
+			$absPath = '/'.$owner.'/files/'.$ownerPath;
139 139
 			$this->update($absPath);
140 140
 		}
141 141
 	}
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 	protected function getOwnerPath($path) {
151 151
 		$info = Filesystem::getFileInfo($path);
152 152
 		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
153
+		$view = new View('/'.$owner.'/files');
154 154
 		$path = $view->getPath($info->getId());
155 155
 		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
156
+			throw new \InvalidArgumentException('No file found for '.$info->getId());
157 157
 		}
158 158
 
159 159
 		return [$owner, $path];
Please login to merge, or discard this patch.