Skip to content

Commit fc65e20

Browse files
author
Jussi Kukkonen
committed
exceptions: Make more errors RepositoryErrors
Try to make errors derive from RepositoryError if they can be the result of malicious or malfunctioning remote repository: The idea here is that client can handle just RepositoryError instead of individual errors (as it cannot do anything about any of them). Also improve variable naming. This is backwards compatible. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent e6f743b commit fc65e20

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

tuf/exceptions.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ class UnsupportedAlgorithmError(Error):
6868
class LengthOrHashMismatchError(Error):
6969
"""Indicate an error while checking the length and hash values of an object"""
7070

71-
class BadHashError(Error):
71+
class RepositoryError(Error):
72+
"""Indicate an error with a repository's state, such as a missing file."""
73+
74+
75+
class BadHashError(RepositoryError):
7276
"""Indicate an error while checking the value of a hash object."""
7377

7478
def __init__(self, expected_hash, observed_hash):
@@ -90,9 +94,6 @@ def __repr__(self):
9094
# self.__class__.__name__ + '(' + repr(self.expected_hash) + ', ' +
9195
# repr(self.observed_hash) + ')')
9296

93-
class BadVersionNumberError(Error):
94-
"""Indicate an error for metadata that contains an invalid version number."""
95-
9697

9798
class BadPasswordError(Error):
9899
"""Indicate an error after encountering an invalid password."""
@@ -102,8 +103,8 @@ class UnknownKeyError(Error):
102103
"""Indicate an error while verifying key-like objects (e.g., keyids)."""
103104

104105

105-
class RepositoryError(Error):
106-
"""Indicate an error with a repository's state, such as a missing file."""
106+
class BadVersionNumberError(RepositoryError):
107+
"""Indicate an error for metadata that contains an invalid version number."""
107108

108109

109110
class MissingLocalRepositoryError(RepositoryError):
@@ -118,36 +119,29 @@ class ForbiddenTargetError(RepositoryError):
118119
"""Indicate that a role signed for a target that it was not delegated to."""
119120

120121

121-
class ExpiredMetadataError(Error):
122+
class ExpiredMetadataError(RepositoryError):
122123
"""Indicate that a TUF Metadata file has expired."""
123124

124125

125126
class ReplayedMetadataError(RepositoryError):
126127
"""Indicate that some metadata has been replayed to the client."""
127128

128-
def __init__(self, metadata_role, previous_version, current_version):
129+
def __init__(self, metadata_role, downloaded_version, current_version):
129130
super(ReplayedMetadataError, self).__init__()
130131

131132
self.metadata_role = metadata_role
132-
self.previous_version = previous_version
133+
self.downloaded_version = downloaded_version
133134
self.current_version = current_version
134135

135-
136136
def __str__(self):
137137
return (
138138
'Downloaded ' + repr(self.metadata_role) + ' is older (' +
139-
repr(self.previous_version) + ') than the version currently '
139+
repr(self.downloaded_version) + ') than the version currently '
140140
'installed (' + repr(self.current_version) + ').')
141141

142142
def __repr__(self):
143143
return self.__class__.__name__ + ' : ' + str(self)
144144

145-
# # Directly instance-reproducing:
146-
# return (
147-
# self.__class__.__name__ + '(' + repr(self.metadata_role) + ', ' +
148-
# repr(self.previous_version) + ', ' + repr(self.current_version) + ')')
149-
150-
151145

152146
class CryptoError(Error):
153147
"""Indicate any cryptography-related errors."""
@@ -249,7 +243,7 @@ class InvalidNameError(Error):
249243
"""Indicate an error while trying to validate any type of named object."""
250244

251245

252-
class UnsignedMetadataError(Error):
246+
class UnsignedMetadataError(RepositoryError):
253247
"""Indicate metadata object with insufficient threshold of signatures."""
254248

255249
def __init__(self, message, signable):

0 commit comments

Comments
 (0)