Skip to content

Commit 25e5f30

Browse files
author
Jussi Kukkonen
authored
Merge pull request #1430 from MVrachev/spec_version-validation
New metadata API: spec_version attribute validation
2 parents 2a5bfb9 + 41afb1e commit 25e5f30

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tuf/api/metadata.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
# and currently, we are above 1000 lines by a small margin.
3939
# pylint: disable=C0302
4040

41+
# We aim to support SPECIFICATION_VERSION and require the input metadata
42+
# files to have the same major version (the first number) as ours.
43+
SPECIFICATION_VERSION = ["1", "0", "19"]
44+
4145

4246
class Metadata:
4347
"""A container for signed TUF metadata.
@@ -295,10 +299,19 @@ def __init__(
295299
expires: datetime,
296300
unrecognized_fields: Optional[Mapping[str, Any]] = None,
297301
) -> None:
302+
spec_list = spec_version.split(".")
303+
if (
304+
len(spec_list) != 3
305+
or not all(el.isdigit() for el in spec_list)
306+
or spec_list[0] != SPECIFICATION_VERSION[0]
307+
):
308+
raise ValueError(
309+
f"Unsupported spec_version, got {spec_list}, "
310+
f"supported {'.'.join(SPECIFICATION_VERSION)}"
311+
)
298312
self.spec_version = spec_version
299313
self.expires = expires
300314

301-
# TODO: Should we separate data validation from constructor?
302315
if version <= 0:
303316
raise ValueError(f"version must be > 0, got {version}")
304317
self.version = version

0 commit comments

Comments
 (0)