diff --git a/securesystemslib/exceptions.py b/securesystemslib/exceptions.py index 7e4bc892..c1eb8914 100755 --- a/securesystemslib/exceptions.py +++ b/securesystemslib/exceptions.py @@ -22,93 +22,18 @@ class Error(Exception): """Indicate a generic error.""" -class Warning(Warning): # pylint: disable=redefined-builtin - """Generic warning. It is used by the 'warnings' module.""" - - class FormatError(Error): """Indicate an error while validating an object's format.""" -class InvalidMetadataJSONError(FormatError): - """Indicate that a metadata file is not valid JSON.""" - - def __init__(self, exception): # pylint: disable=super-init-not-called - # Store the original exception. - self.exception = exception - - def __str__(self): - # Show the original exception. - return repr(self.exception) - - class UnsupportedAlgorithmError(Error): """Indicate an error while trying to identify a user-specified algorithm.""" -class BadHashError(Error): - """Indicate an error while checking the value a hash object.""" - - def __init__( - self, expected_hash, observed_hash - ): # pylint: disable=super-init-not-called - self.expected_hash = expected_hash - self.observed_hash = observed_hash - - def __str__(self): - return ( - "Observed hash (" - + repr(self.observed_hash) - + ") != expected hash (" - + repr(self.expected_hash) - + ")" - ) - - -class BadPasswordError(Error): - """Indicate an error after encountering an invalid password.""" - - -class CryptoError(Error): - """Indicate any cryptography-related errors.""" - - -class BadSignatureError(CryptoError): - """Indicate that some metadata has a bad signature.""" - - def __init__( - self, metadata_role_name - ): # pylint: disable=super-init-not-called - self.metadata_role_name = metadata_role_name - - def __str__(self): - return repr(self.metadata_role_name) + " metadata has bad signature." - - -class UnknownMethodError(CryptoError): - """Indicate that a user-specified cryptograpthic method is unknown.""" - - class UnsupportedLibraryError(Error): """Indicate that a supported library could not be located or imported.""" -class InvalidNameError(Error): - """Indicate an error while trying to validate any type of named object.""" - - -class NotFoundError(Error): - """If a required configuration or resource is not found.""" - - -class URLMatchesNoPatternError(Error): - """If a URL does not match a user-specified regular expression.""" - - -class InvalidConfigurationError(Error): - """If a configuration object does not match the expected format.""" - - class StorageError(Error): """Indicate an error occured during interaction with an abstracted storage backend.""" @@ -121,11 +46,3 @@ class UnverifiedSignatureError(Error): class VerificationError(UnverifiedSignatureError): """Signature could not be verified because something failed in the process""" - - -class SerializationError(Error): - """Error during serialization.""" - - -class DeserializationError(Error): - """Error during deserialization.""" diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py deleted file mode 100755 index 3f3af413..00000000 --- a/tests/test_exceptions.py +++ /dev/null @@ -1,59 +0,0 @@ -""" - - test_exceptions.py - - - Vladimir Diaz - - - December 20, 2016. - - - See LICENSE for licensing information. - - - Test cases for exceptions.py (mainly the exceptions defined there). -""" - -import logging -import unittest - -import securesystemslib.exceptions - -logger = logging.getLogger(__name__) - - -class TestExceptions( - unittest.TestCase -): # pylint: disable=missing-class-docstring - def setUp(self): - pass - - def tearDown(self): - pass - - def test_bad_signature_error(self): - bad_signature_error = securesystemslib.exceptions.BadSignatureError( - "bad sig" - ) - logger.error(bad_signature_error) - - def test_bad_hash_error(self): - bad_hash_error = securesystemslib.exceptions.BadHashError( - "01234", "56789" - ) - logger.error(bad_hash_error) - - def test_invalid_metadata_json_error(self): - format_error = securesystemslib.exceptions.FormatError( - "Improperly formatted JSON" - ) - invalid_metadata_json_error = ( - securesystemslib.exceptions.InvalidMetadataJSONError(format_error) - ) - logger.error(invalid_metadata_json_error) - - -# Run the unit tests. -if __name__ == "__main__": - unittest.main()