diff --git a/tuf/api/__init__.py b/tuf/api/__init__.py index a6176da2dc..e69de29bb2 100644 --- a/tuf/api/__init__.py +++ b/tuf/api/__init__.py @@ -1,12 +0,0 @@ -"""TUF new API - -This package contains all modules related to the TUF refactoring effort. - -""" -# This reference implementation produces metadata intended to conform to -# version 1.0.0 of the TUF specification, and is expected to consume metadata -# conforming to version 1.0.0 of the TUF specification. -# All downloaded metadata must be equal to our supported major version of 1. -# For example, "1.4.3" and "1.0.0" are supported. "2.0.0" is not supported. -# See https://github.com/theupdateframework/specification -SPECIFICATION_VERSION = ["1", "0", "0"] diff --git a/tuf/api/metadata.py b/tuf/api/metadata.py index 12d294c9f3..49e6db4b28 100644 --- a/tuf/api/metadata.py +++ b/tuf/api/metadata.py @@ -37,6 +37,10 @@ # and currently, we are above 1000 lines by a small margin. # pylint: disable=C0302 +# We aim to support SPECIFICATION_VERSION and require the input metadata +# files to have the same major version (the first number) as ours. +SPECIFICATION_VERSION = ["1", "0", "19"] + class Metadata: """A container for signed TUF metadata. @@ -290,6 +294,16 @@ def __init__( expires: datetime, unrecognized_fields: Optional[Mapping[str, Any]] = None, ) -> None: + spec_list = spec_version.split(".") + if ( + len(spec_list) != 3 + or not all(el.isdigit() for el in spec_list) + or spec_list[0] != SPECIFICATION_VERSION[0] + ): + raise ValueError( + f"Unsupported spec_version, got {spec_list}, " + f"supported {'.'.join(SPECIFICATION_VERSION)}" + ) self.spec_version = spec_version self.expires = expires