@@ -44,8 +44,8 @@ def __init__(self, consistent_snapshot: bool = True, expiration: relativedelta =
4444 # And you would use this method to populate it from a file.
4545 def read_from_json (self , filename : str ) -> None :
4646 signable = load_json_file (filename )
47+ tuf .formats .SIGNABLE_SCHEMA .check_match (signable )
4748
48- # TODO: use some basic schema checks
4949 self .signatures = signable ['signatures' ]
5050 self .signed = signable ['signed' ]
5151
@@ -130,6 +130,10 @@ class Timestamp(Metadata):
130130 def __init__ (self , consistent_snapshot : bool = True , expiration : relativedelta = relativedelta (days = 1 ), keyring : KeyRing = None , version : int = 1 ):
131131 super ().__init__ (consistent_snapshot , expiration , keyring , version )
132132
133+ def read_from_json (self , filename : str ) -> None :
134+ super ().read_from_json (filename )
135+ tuf .formats .TIMESTAMP_SCHEMA .check_match (self .signed )
136+
133137 def signable (self ):
134138 expires = self .expiration .replace (tzinfo = None ).isoformat ()+ 'Z'
135139 filedict = self .signed ['meta' ]
@@ -151,6 +155,8 @@ def __init__(self, consistent_snapshot: bool = True, expiration: relativedelta =
151155
152156 def read_from_json (self , filename : str ) -> None :
153157 super ().read_from_json (filename )
158+ tuf .formats .SNAPSHOT_SCHEMA .check_match (self .signed )
159+
154160 meta = self .signed ['meta' ]
155161 for target_role in meta :
156162 version = meta [target_role ]['version' ]
@@ -175,13 +181,13 @@ def __init__(self, consistent_snapshot: bool = True, expiration: relativedelta =
175181 self .targets = {}
176182 self .delegations = {}
177183
178-
179184 def read_from_json (self , filename : str ) -> None :
180185 super ().read_from_json (filename )
186+ tuf .formats .TARGETS_SCHEMA .check_match (self .signed )
187+
181188 self .targets = self .signed ['targets' ]
182189 self .delegations = self .signed .get ('delegations' , None )
183190
184- # FIXME
185191 def signable (self ):
186192 # TODO: probably want to generalise this, a @property.getter in Metadata?
187193 expires = self .expiration .replace (tzinfo = None ).isoformat ()+ 'Z'
0 commit comments