diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-04-17 11:32:24 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-04-17 11:32:24 +0200 |
commit | aef6ecdbf1fbe748acb64bcf8d1abdf14ea51e97 (patch) | |
tree | c40489a85da1be3eb66041a2ca2719f38c0298f3 /lib | |
parent | f32d97750c33942db53a56d1deceacb2ed3e779b (diff) | |
parent | 7d4b1b52d08fd4bc8e9f65ca2ccc747de2fc429a (diff) | |
download | nextcloud-server-aef6ecdbf1fbe748acb64bcf8d1abdf14ea51e97.tar.gz nextcloud-server-aef6ecdbf1fbe748acb64bcf8d1abdf14ea51e97.zip |
Merge pull request #15616 from owncloud/enc_stream_copy
always create a new instance of the encryption module
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/encryption/manager.php | 42 | ||||
-rw-r--r-- | lib/public/encryption/imanager.php | 14 |
2 files changed, 27 insertions, 29 deletions
diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php index 89abad4934a..e01054c92a4 100644 --- a/lib/private/encryption/manager.php +++ b/lib/private/encryption/manager.php @@ -87,17 +87,17 @@ class Manager implements IManager { } /** - * Registers an encryption module + * Registers an callback function which must return an encryption module instance * - * @param IEncryptionModule $module + * @param string $id + * @param string $displayName + * @param callable $callback * @throws Exceptions\ModuleAlreadyExistsException */ - public function registerEncryptionModule(IEncryptionModule $module) { - $id = $module->getId(); - $name = $module->getDisplayName(); + public function registerEncryptionModule($id, $displayName, callable $callback) { if (isset($this->encryptionModules[$id])) { - throw new Exceptions\ModuleAlreadyExistsException($id, $name); + throw new Exceptions\ModuleAlreadyExistsException($id, $displayName); } $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); @@ -106,22 +106,26 @@ class Manager implements IManager { $this->setDefaultEncryptionModule($id); } - $this->encryptionModules[$id] = $module; + $this->encryptionModules[$id] = array( + 'id' => $id, + 'displayName' => 'displayName', + 'callback' => $callback + ); } /** * Unregisters an encryption module * - * @param IEncryptionModule $module + * @param string $moduleId */ - public function unregisterEncryptionModule(IEncryptionModule $module) { - unset($this->encryptionModules[$module->getId()]); + public function unregisterEncryptionModule($moduleId) { + unset($this->encryptionModules[$moduleId]); } /** * get a list of all encryption modules * - * @return IEncryptionModule[] + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] */ public function getEncryptionModules() { return $this->encryptionModules; @@ -137,21 +141,13 @@ class Manager implements IManager { public function getEncryptionModule($moduleId = '') { if (!empty($moduleId)) { if (isset($this->encryptionModules[$moduleId])) { - return $this->encryptionModules[$moduleId]; + return call_user_func($this->encryptionModules[$moduleId]['callback']); } else { $message = "Module with id: $moduleId does not exists."; throw new Exceptions\ModuleDoesNotExistsException($message); } - } else { // get default module and return this - // For now we simply return the first module until we have a way - // to enable multiple modules and define a default module - $module = reset($this->encryptionModules); - if ($module) { - return $module; - } else { - $message = 'No encryption module registered'; - throw new Exceptions\ModuleDoesNotExistsException($message); - } + } else { + return $this->getDefaultEncryptionModule(); } } @@ -165,7 +161,7 @@ class Manager implements IManager { $defaultModuleId = $this->getDefaultEncryptionModuleId(); if (!empty($defaultModuleId)) { if (isset($this->encryptionModules[$defaultModuleId])) { - return $this->encryptionModules[$defaultModuleId]; + return call_user_func($this->encryptionModules[$defaultModuleId]['callback']); } else { $message = 'Default encryption module not loaded'; throw new Exceptions\ModuleDoesNotExistsException($message); diff --git a/lib/public/encryption/imanager.php b/lib/public/encryption/imanager.php index badc91c9023..3a370710781 100644 --- a/lib/public/encryption/imanager.php +++ b/lib/public/encryption/imanager.php @@ -40,26 +40,28 @@ interface IManager { function isEnabled(); /** - * Registers an encryption module + * Registers an callback function which must return an encryption module instance * - * @param IEncryptionModule $module + * @param string $id + * @param string $displayName + * @param callable $callback * @throws ModuleAlreadyExistsException * @since 8.1.0 */ - function registerEncryptionModule(IEncryptionModule $module); + function registerEncryptionModule($id, $displayName, callable $callback); /** * Unregisters an encryption module * - * @param IEncryptionModule $module + * @param string $moduleId * @since 8.1.0 */ - function unregisterEncryptionModule(IEncryptionModule $module); + function unregisterEncryptionModule($moduleId); /** * get a list of all encryption modules * - * @return array + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] * @since 8.1.0 */ function getEncryptionModules(); |