11# Copyright the TUF contributors
22# SPDX-License-Identifier: MIT OR Apache-2.0
33
4- """TUF client bundle-of-metadata
4+ """Trusted collection of client-side TUF Metadata
55
6- MetadataBundle keeps track of current valid set of metadata for the client,
6+ TrustedMetadataSet keeps track of current valid set of metadata for the client,
77and handles almost every step of the "Detailed client workflow" (
88https://theupdateframework.github.io/specification/latest#detailed-client-workflow)
99in the TUF specification: the remaining steps are related to filesystem and
1010network IO which is not handled here.
1111
1212Loaded metadata can be accessed via the index access with rolename as key
13- (bundle ["root"]) or, in the case of top-level metadata using the helper
14- properties (bundle .root).
13+ (trusted_set ["root"]) or, in the case of top-level metadata using the helper
14+ properties (trusted_set .root).
1515
1616The rules for top-level metadata are
1717 * Metadata is loadable only if metadata it depends on is loaded
2626
2727>>> # Load local root (RepositoryErrors here stop the update)
2828>>> with open(root_path, "rb") as f:
29- >>> bundle = MetadataBundle (f.read())
29+ >>> trusted_set = TrustedMetadataSet (f.read())
3030>>>
3131>>> # update root from remote until no more are available
32- >>> with download("root", bundle .root.signed.version + 1) as f:
33- >>> bundle .update_root(f.read())
32+ >>> with download("root", trusted_set .root.signed.version + 1) as f:
33+ >>> trusted_set .update_root(f.read())
3434>>> # ...
35- >>> bundle .root_update_finished()
35+ >>> trusted_set .root_update_finished()
3636>>>
3737>>> # load local timestamp, then update from remote
3838>>> try:
3939>>> with open(timestamp_path, "rb") as f:
40- >>> bundle .update_timestamp(f.read())
40+ >>> trusted_set .update_timestamp(f.read())
4141>>> except (RepositoryError, OSError):
4242>>> pass # failure to load a local file is ok
4343>>>
4444>>> with download("timestamp") as f:
45- >>> bundle .update_timestamp(f.read())
45+ >>> trusted_set .update_timestamp(f.read())
4646>>>
4747>>> # load local snapshot, then update from remote if needed
4848>>> try:
4949>>> with open(snapshot_path, "rb") as f:
50- >>> bundle .update_snapshot(f.read())
50+ >>> trusted_set .update_snapshot(f.read())
5151>>> except (RepositoryError, OSError):
5252>>> # local snapshot is not valid, load from remote
5353>>> # (RepositoryErrors here stop the update)
5454>>> with download("snapshot", version) as f:
55- >>> bundle .update_snapshot(f.read())
55+ >>> trusted_set .update_snapshot(f.read())
5656
5757TODO:
5858 * exceptions are not final: the idea is that client could just handle
@@ -116,27 +116,27 @@ def verify_with_threshold(
116116 return len (unique_keys ) >= role .threshold
117117
118118
119- class MetadataBundle (abc .Mapping ):
120- """Internal class to keep track of valid metadata in Updater
119+ class TrustedMetadataSet (abc .Mapping ):
120+ """Internal class to keep track of trusted metadata in Updater
121121
122- MetadataBundle ensures that the collection of metadata in the bundle is
123- valid. It provides easy ways to update the metadata with the caller making
124- decisions on what is updated.
122+ TrustedMetadataSet ensures that the collection of metadata in it is valid
123+ and trusted through the whole client update workflow. It provides easy ways
124+ to update the metadata with the caller making decisions on what is updated.
125125 """
126126
127127 def __init__ (self , root_data : bytes ):
128- """Initialize bundle by loading trusted root metadata
128+ """Initialize TrustedMetadataSet by loading trusted root metadata
129129
130130 Args:
131131 root_data: Trusted root metadata as bytes. Note that this metadata
132132 will only be verified by itself: it is the source of trust for
133- all metadata in the bundle.
133+ all metadata in the TrustedMetadataSet
134134
135135 Raises:
136136 RepositoryError: Metadata failed to load or verify. The actual
137137 error type and content will contain more details.
138138 """
139- self ._bundle = {} # type: Dict[str: Metadata]
139+ self ._trusted_set = {} # type: Dict[str: Metadata]
140140 self .reference_time = datetime .utcnow ()
141141 self ._root_update_finished = False
142142
@@ -147,36 +147,36 @@ def __init__(self, root_data: bytes):
147147
148148 def __getitem__ (self , role : str ) -> Metadata :
149149 """Returns current Metadata for 'role'"""
150- return self ._bundle [role ]
150+ return self ._trusted_set [role ]
151151
152152 def __len__ (self ) -> int :
153- """Returns number of Metadata objects in bundle """
154- return len (self ._bundle )
153+ """Returns number of Metadata objects in TrustedMetadataSet """
154+ return len (self ._trusted_set )
155155
156156 def __iter__ (self ) -> Iterator [Metadata ]:
157- """Returns iterator over all Metadata objects in bundle """
158- return iter (self ._bundle )
157+ """Returns iterator over all Metadata objects in TrustedMetadataSet """
158+ return iter (self ._trusted_set )
159159
160160 # Helper properties for top level metadata
161161 @property
162162 def root (self ) -> Optional [Metadata ]:
163163 """Current root Metadata or None"""
164- return self ._bundle .get ("root" )
164+ return self ._trusted_set .get ("root" )
165165
166166 @property
167167 def timestamp (self ) -> Optional [Metadata ]:
168168 """Current timestamp Metadata or None"""
169- return self ._bundle .get ("timestamp" )
169+ return self ._trusted_set .get ("timestamp" )
170170
171171 @property
172172 def snapshot (self ) -> Optional [Metadata ]:
173173 """Current snapshot Metadata or None"""
174- return self ._bundle .get ("snapshot" )
174+ return self ._trusted_set .get ("snapshot" )
175175
176176 @property
177177 def targets (self ) -> Optional [Metadata ]:
178178 """Current targets Metadata or None"""
179- return self ._bundle .get ("targets" )
179+ return self ._trusted_set .get ("targets" )
180180
181181 # Methods for updating metadata
182182 def update_root (self , data : bytes ):
@@ -225,7 +225,7 @@ def update_root(self, data: bytes):
225225 "New root is not signed by itself" , new_root .signed
226226 )
227227
228- self ._bundle ["root" ] = new_root
228+ self ._trusted_set ["root" ] = new_root
229229 logger .debug ("Updated root" )
230230
231231 def root_update_finished (self ):
@@ -302,7 +302,7 @@ def update_timestamp(self, data: bytes):
302302 if new_timestamp .signed .is_expired (self .reference_time ):
303303 raise exceptions .ExpiredMetadataError ("New timestamp is expired" )
304304
305- self ._bundle ["timestamp" ] = new_timestamp
305+ self ._trusted_set ["timestamp" ] = new_timestamp
306306 logger .debug ("Updated timestamp" )
307307
308308 # TODO: remove pylint disable once the hash verification is in metadata.py
@@ -381,7 +381,7 @@ def update_snapshot(self, data: bytes): # pylint: disable=too-many-branches
381381 if new_snapshot .signed .is_expired (self .reference_time ):
382382 raise exceptions .ExpiredMetadataError ("New snapshot is expired" )
383383
384- self ._bundle ["snapshot" ] = new_snapshot
384+ self ._trusted_set ["snapshot" ] = new_snapshot
385385 logger .debug ("Updated snapshot" )
386386
387387 def update_targets (self , data : bytes ):
@@ -460,5 +460,5 @@ def update_delegated_targets(
460460 if new_delegate .signed .is_expired (self .reference_time ):
461461 raise exceptions .ExpiredMetadataError (f"New { role_name } is expired" )
462462
463- self ._bundle [role_name ] = new_delegate
463+ self ._trusted_set [role_name ] = new_delegate
464464 logger .debug ("Updated %s delegated by %s" , role_name , delegator_name )
0 commit comments