2021-12-13 16:20:26 +00:00
|
|
|
# Copyright New York University and the TUF contributors
|
|
|
|
|
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Define TUF exceptions used inside the new modern implementation.
|
|
|
|
|
The names chosen for TUF Exception classes should end in 'Error' except where
|
|
|
|
|
there is a good reason not to, and provide that reason in those cases.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Repository errors ####
|
|
|
|
|
|
2024-02-20 20:19:33 +00:00
|
|
|
from securesystemslib.exceptions import StorageError # noqa: F401
|
2022-01-26 17:57:59 +00:00
|
|
|
|
2021-12-13 16:20:26 +00:00
|
|
|
|
2021-12-13 16:28:53 +00:00
|
|
|
class RepositoryError(Exception):
|
2022-01-12 16:08:46 +00:00
|
|
|
"""An error with a repository's state, such as a missing file.
|
2023-01-26 15:35:19 +00:00
|
|
|
|
2022-01-12 16:08:46 +00:00
|
|
|
It covers all exceptions that come from the repository side when
|
2023-01-26 15:35:19 +00:00
|
|
|
looking from the perspective of users of metadata API or ngclient.
|
|
|
|
|
"""
|
2021-12-13 16:20:26 +00:00
|
|
|
|
|
|
|
|
|
2021-12-13 16:28:53 +00:00
|
|
|
class UnsignedMetadataError(RepositoryError):
|
2024-02-20 05:34:47 +00:00
|
|
|
"""An error about metadata object with insufficient threshold of
|
|
|
|
|
signatures.
|
|
|
|
|
"""
|
2021-12-13 16:20:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class BadVersionNumberError(RepositoryError):
|
|
|
|
|
"""An error for metadata that contains an invalid version number."""
|
|
|
|
|
|
|
|
|
|
|
2022-06-13 19:52:02 +00:00
|
|
|
class EqualVersionNumberError(BadVersionNumberError):
|
|
|
|
|
"""An error for metadata containing a previously verified version number."""
|
|
|
|
|
|
|
|
|
|
|
2021-12-13 16:20:26 +00:00
|
|
|
class ExpiredMetadataError(RepositoryError):
|
|
|
|
|
"""Indicate that a TUF Metadata file has expired."""
|
|
|
|
|
|
|
|
|
|
|
2022-01-12 16:04:57 +00:00
|
|
|
class LengthOrHashMismatchError(RepositoryError):
|
|
|
|
|
"""An error while checking the length and hash values of an object."""
|
|
|
|
|
|
|
|
|
|
|
2021-12-13 16:20:26 +00:00
|
|
|
#### Download Errors ####
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DownloadError(Exception):
|
|
|
|
|
"""An error occurred while attempting to download a file."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DownloadLengthMismatchError(DownloadError):
|
|
|
|
|
"""Indicate that a mismatch of lengths was seen while downloading a file."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SlowRetrievalError(DownloadError):
|
2021-12-13 16:28:53 +00:00
|
|
|
"""Indicate that downloading a file took an unreasonably long time."""
|
2021-12-16 16:58:57 +00:00
|
|
|
|
|
|
|
|
|
2022-01-31 11:56:46 +00:00
|
|
|
class DownloadHTTPError(DownloadError):
|
2021-12-16 16:58:57 +00:00
|
|
|
"""
|
|
|
|
|
Returned by FetcherInterface implementations for HTTP errors.
|
|
|
|
|
|
|
|
|
|
Args:
|
2025-03-10 20:48:43 +00:00
|
|
|
message: The HTTP error message
|
2021-12-16 16:58:57 +00:00
|
|
|
status_code: The HTTP status code
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, message: str, status_code: int):
|
|
|
|
|
super().__init__(message)
|
|
|
|
|
self.status_code = status_code
|