Skip to content

WIP: Mirrors redesign #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

41 changes: 41 additions & 0 deletions tuf/client_rework/fetcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2021, New York University and the TUF contributors
# SPDX-License-Identifier: MIT OR Apache-2.0

"""Provides an interface for network IO abstraction.
"""

# Imports
import abc


# Classes
class FetcherInterface:
"""Defines an interface for abstract network download.

By providing a concrete implementation of the abstract interface,
users of the framework can plug-in their preferred/customized
network stack.
"""

__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def fetch(self, url, required_length):
"""Fetches the contents of HTTP/HTTPS url from a remote server.

Ensures the length of the downloaded data is up to 'required_length'.

Arguments:
url: A URL string that represents a file location.
required_length: An integer value representing the file length in
bytes.

Raises:
tuf.exceptions.SlowRetrievalError: A timeout occurs while receiving
data.
tuf.exceptions.FetcherHTTPError: An HTTP error code is received.

Returns:
A bytes iterator
"""
raise NotImplementedError # pragma: no cover
8 changes: 4 additions & 4 deletions tuf/client_rework/metadata_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from securesystemslib.keys import format_metadata_to_key

import tuf.exceptions
from tuf import exceptions, formats
from tuf.api import metadata


Expand Down Expand Up @@ -64,7 +64,7 @@ def verify(self, keys, threshold):
verified += 1

if verified < threshold:
raise tuf.exceptions.InsufficientKeysError
raise exceptions.InsufficientKeysError

def persist(self, filename):
"""
Expand All @@ -77,13 +77,13 @@ def expires(self, reference_time=None):
TODO
"""
if reference_time is None:
expires_timestamp = tuf.formats.datetime_to_unix_timestamp(
expires_timestamp = formats.datetime_to_unix_timestamp(
self._meta.signed.expires
)
reference_time = int(time.time())

if expires_timestamp < reference_time:
raise tuf.exceptions.ExpiredMetadataError
raise exceptions.ExpiredMetadataError


class RootWrapper(MetadataWrapper):
Expand Down
Loading