Skip to content

Commit c6d30e6

Browse files
committed
Replace UnsupportedAlgorithmError with ValueError
UnsupportedAlgorithmError is a securesystemslib exception that is reexported inside tuf/api/exceptions.py It's only used once inside "Targetfile.from_data()" and there it's used to denote that there is a problem with the given argument. That's why this error can be replaced with "ValueError" and we can stop reexporting it from securesystemslib. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 5e682a0 commit c6d30e6

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def test_targetfile_from_file(self) -> None:
614614

615615
# Test with an unsupported algorithm
616616
file_path = os.path.join(self.repo_dir, Targets.type, "file1.txt")
617-
with self.assertRaises(exceptions.UnsupportedAlgorithmError):
617+
with self.assertRaises(ValueError):
618618
TargetFile.from_file(file_path, file_path, ["123"])
619619

620620
def test_targetfile_from_data(self) -> None:

tuf/api/exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
"""
99

1010

11-
#### General errors ####
12-
13-
# Reexport securesystemslib exceptions so that users of code that throws them
14-
# doesn't have to import securesystemslib to handle them.
15-
# pylint: disable=unused-import
16-
from securesystemslib.exceptions import UnsupportedAlgorithmError
17-
1811
#### MetadataError errors ####
1912

2013

tuf/api/metadata.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,8 @@ def from_file(
13161316
specified the securesystemslib default hash algorithm is used.
13171317
Raises:
13181318
FileNotFoundError: The file doesn't exist.
1319-
UnsupportedAlgorithmError: The hash algorithms list
1320-
contains an unsupported algorithm.
1319+
ValueError: The hash algorithms list contains an unsupported
1320+
algorithm.
13211321
"""
13221322
with open(local_path, "rb") as file:
13231323
return cls.from_data(target_file_path, file, hash_algorithms)
@@ -1339,8 +1339,8 @@ def from_data(
13391339
specified the securesystemslib default hash algorithm is used.
13401340
13411341
Raises:
1342-
UnsupportedAlgorithmError: The hash algorithms list
1343-
contains an unsupported algorithm.
1342+
ValueError: The hash algorithms list contains an unsupported
1343+
algorithm.
13441344
"""
13451345
if isinstance(data, bytes):
13461346
length = len(data)
@@ -1366,9 +1366,7 @@ def from_data(
13661366
sslib_exceptions.UnsupportedAlgorithmError,
13671367
sslib_exceptions.FormatError,
13681368
) as e:
1369-
raise exceptions.UnsupportedAlgorithmError(
1370-
f"Unsupported algorithm '{algorithm}'"
1371-
) from e
1369+
raise ValueError(f"Unsupported algorithm '{algorithm}'") from e
13721370

13731371
hashes[algorithm] = digest_object.hexdigest()
13741372

0 commit comments

Comments
 (0)