diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-01 16:36:08 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:30 +0200 |
commit | 664b2bb7af2c8253aa0bbade42531ad4a3ef6bab (patch) | |
tree | 1f6da0f4a10dbc9345a8dd1716986c16c237f3d9 /lib/private/encryption | |
parent | c9d6ed3d7d04412b721745f61402ff1400c59aeb (diff) | |
download | nextcloud-server-664b2bb7af2c8253aa0bbade42531ad4a3ef6bab.tar.gz nextcloud-server-664b2bb7af2c8253aa0bbade42531ad4a3ef6bab.zip |
cleaning up exception mess
Diffstat (limited to 'lib/private/encryption')
15 files changed, 37 insertions, 125 deletions
diff --git a/lib/private/encryption/exceptions/decryptionfailedexception.php b/lib/private/encryption/exceptions/decryptionfailedexception.php index 43fea90fed8..f8b4fdf07fa 100644 --- a/lib/private/encryption/exceptions/decryptionfailedexception.php +++ b/lib/private/encryption/exceptions/decryptionfailedexception.php @@ -22,6 +22,7 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; class DecryptionFailedException extends GenericEncryptionException { diff --git a/lib/private/encryption/exceptions/emptyencryptiondataexception.php b/lib/private/encryption/exceptions/emptyencryptiondataexception.php index ea181809856..d3dc9230047 100644 --- a/lib/private/encryption/exceptions/emptyencryptiondataexception.php +++ b/lib/private/encryption/exceptions/emptyencryptiondataexception.php @@ -22,6 +22,7 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; class EmptyEncryptionDataException extends GenericEncryptionException{ diff --git a/lib/private/encryption/exceptions/encryptionfailedexception.php b/lib/private/encryption/exceptions/encryptionfailedexception.php index 9e6648f7bf5..ac489c73254 100644 --- a/lib/private/encryption/exceptions/encryptionfailedexception.php +++ b/lib/private/encryption/exceptions/encryptionfailedexception.php @@ -22,6 +22,7 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; class EncryptionFailedException extends GenericEncryptionException{ diff --git a/lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php b/lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php index 23103b90c4f..5e8e48efd78 100644 --- a/lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php +++ b/lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php @@ -23,11 +23,14 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; -class EncryptionHeaderKeyExistsException extends \Exception { - -} - -class EncryptionHeaderToLargeException extends \Exception { +class EncryptionHeaderKeyExistsException extends GenericEncryptionException { + /** + * @param string $key + */ + public function __construct($key) { + parent::__construct('header key "'. $key . '" already reserved by ownCloud'); + } } diff --git a/lib/private/encryption/exceptions/encryptionheadertolargeexception.php b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php index cc980aa4beb..94a130d792d 100644 --- a/lib/private/encryption/exceptions/encryptionheadertolargeexception.php +++ b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php @@ -22,7 +22,12 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; class EncryptionHeaderToLargeException extends GenericEncryptionException { + public function __construct($key) { + parent::__construct('max header size exceeded'); + } + } diff --git a/lib/private/encryption/exceptions/genericencryptionexception.php b/lib/private/encryption/exceptions/genericencryptionexception.php deleted file mode 100644 index 608e5e6010a..00000000000 --- a/lib/private/encryption/exceptions/genericencryptionexception.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - /** - * @author Clark Tomlinson <clark@owncloud.com> - * @since 2/25/15, 9:30 AM - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Encryption\Exceptions; - - -class GenericEncryptionException extends \Exception { - -} diff --git a/lib/private/encryption/exceptions/modulealreadyexistsexception.php b/lib/private/encryption/exceptions/modulealreadyexistsexception.php index 41fc0188e24..fa1e70a5c36 100644 --- a/lib/private/encryption/exceptions/modulealreadyexistsexception.php +++ b/lib/private/encryption/exceptions/modulealreadyexistsexception.php @@ -23,6 +23,16 @@ namespace OC\Encryption\Exceptions; -class ModuleAlreadyExistsException extends \Exception { +use OCP\Encryption\Exceptions\GenericEncryptionException; + +class ModuleAlreadyExistsException extends GenericEncryptionException { + + /** + * @param string $id + * @param string $name + */ + public function __construct($id, $name) { + parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); + } } diff --git a/lib/private/encryption/exceptions/moduledoesnotexistsexception.php b/lib/private/encryption/exceptions/moduledoesnotexistsexception.php index 5507bd03dab..2c699e8dc2d 100644 --- a/lib/private/encryption/exceptions/moduledoesnotexistsexception.php +++ b/lib/private/encryption/exceptions/moduledoesnotexistsexception.php @@ -23,6 +23,8 @@ namespace OC\Encryption\Exceptions; -class ModuleDoesNotExistsException extends \Exception { +use OCP\Encryption\Exceptions\GenericEncryptionException; + +class ModuleDoesNotExistsException extends GenericEncryptionException { } diff --git a/lib/private/encryption/exceptions/publickeymissingexception.php b/lib/private/encryption/exceptions/publickeymissingexception.php deleted file mode 100644 index d5f2aae42cc..00000000000 --- a/lib/private/encryption/exceptions/publickeymissingexception.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** - * @author Clark Tomlinson <clark@owncloud.com> - * @since 2/25/15, 9:39 AM - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - - -namespace OC\Encryption\Exceptions; - - -class PublicKeyMissingException extends GenericEncryptionException { - -} diff --git a/lib/private/encryption/exceptions/unexpectedblocksizeexception.php b/lib/private/encryption/exceptions/unexpectedblocksizeexception.php deleted file mode 100644 index 799d08e6bab..00000000000 --- a/lib/private/encryption/exceptions/unexpectedblocksizeexception.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - /** - * @author Clark Tomlinson <clark@owncloud.com> - * @since 2/25/15, 9:35 AM - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - - -namespace OC\Encryption\Exceptions; - - -interface UnexpectedBlockSize { - -} diff --git a/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php b/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php deleted file mode 100644 index 04f65cf7626..00000000000 --- a/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - /** - * @author Clark Tomlinson <clark@owncloud.com> - * @since 2/25/15, 9:34 AM - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - - -namespace OC\Encryption\Exceptions; - - -class UnexpectedEndOfEncryptionHeaderException extends GenericEncryptionException { - -} diff --git a/lib/private/encryption/exceptions/unknowncipherexception.php b/lib/private/encryption/exceptions/unknowncipherexception.php index 5177af6106b..188f7403848 100644 --- a/lib/private/encryption/exceptions/unknowncipherexception.php +++ b/lib/private/encryption/exceptions/unknowncipherexception.php @@ -22,7 +22,8 @@ namespace OC\Encryption\Exceptions; +use OCP\Encryption\Exceptions\GenericEncryptionException; -class UnknownCipherException extends GenericEncryptionException{ +class UnknownCipherException extends GenericEncryptionException { } diff --git a/lib/private/encryption/keys/storage.php b/lib/private/encryption/keys/storage.php index 82753df1dc7..e4e3fb084f3 100644 --- a/lib/private/encryption/keys/storage.php +++ b/lib/private/encryption/keys/storage.php @@ -23,9 +23,9 @@ namespace OC\Encryption\Keys; -use OC\Encryption\Exceptions\GenericEncryptionException; use OC\Encryption\Util; use OC\Files\View; +use OCP\Encryption\Exceptions\GenericEncryptionException; class Storage implements \OCP\Encryption\Keys\IStorage { @@ -259,7 +259,7 @@ class Storage implements \OCP\Encryption\Keys\IStorage { private function getFileKeyDir($path) { if ($this->view->is_dir($path)) { - throw new GenericEncryptionException('file was expected but directory was given'); + throw new GenericEncryptionException("file was expected but directory was given: $path"); } list($owner, $filename) = $this->util->getUidAndFilename($path); diff --git a/lib/private/encryption/manager.php b/lib/private/encryption/manager.php index 77f02b0c489..f8ac174479e 100644 --- a/lib/private/encryption/manager.php +++ b/lib/private/encryption/manager.php @@ -70,8 +70,7 @@ class Manager implements \OCP\Encryption\IManager { $name = $module->getDisplayName(); if (isset($this->encryptionModules[$id])) { - $message = 'Id "' . $id . '" already used by encryption module "' . $name . '"'; - throw new Exceptions\ModuleAlreadyExistsException($message); + throw new Exceptions\ModuleAlreadyExistsException($id, $name); } $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); diff --git a/lib/private/encryption/util.php b/lib/private/encryption/util.php index 1183e6622bb..e2c7fa26e66 100644 --- a/lib/private/encryption/util.php +++ b/lib/private/encryption/util.php @@ -147,14 +147,14 @@ class Util { $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; foreach ($headerData as $key => $value) { if (in_array($key, $this->ocHeaderKeys)) { - throw new EncryptionHeaderKeyExistsException('header key "'. $key . '" already reserved by ownCloud'); + throw new EncryptionHeaderKeyExistsException($key); } $header .= $key . ':' . $value . ':'; } $header .= self::HEADER_END; if (strlen($header) > $this->getHeaderSize()) { - throw new EncryptionHeaderToLargeException('max header size exceeded'); + throw new EncryptionHeaderToLargeException(); } $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |