diff --git a/tuf/api/metadata.py b/tuf/api/metadata.py index 12d294c9f3..9762c4f4c6 100644 --- a/tuf/api/metadata.py +++ b/tuf/api/metadata.py @@ -26,6 +26,7 @@ from securesystemslib.util import persist_temp_file from tuf import exceptions +from tuf.api import SPECIFICATION_VERSION from tuf.api.serialization import ( MetadataDeserializer, MetadataSerializer, @@ -290,6 +291,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