@@ -245,25 +245,21 @@ func (c *Client) updateRoots() error {
245245	// Prepare for 5.3.11: If the timestamp and / or snapshot keys have been rotated, 
246246	// then delete the trusted timestamp and snapshot metadata files. 
247247	getKeyInfo  :=  func (role  string ) KeyInfo  {
248- 		//keyIDs := make([]string, 0, len(c.db.GetRole(role).KeyIDs)) 
249248		keyIDs  :=  make (map [string ]bool )
250249		for  k  :=  range  c .db .GetRole (role ).KeyIDs  {
251- 			//keyIDs = append(keyIDs, k) 
252250			keyIDs [k ] =  true 
253251		}
254- 		//sort.Strings(keyIDs) 
255252		return  KeyInfo {keyIDs , c .db .GetRole (role ).Threshold }
256253	}
257254
258- 	// The manifest  looks like this: 
255+ 	// The nonRootKeyInfo  looks like this: 
259256	// { 
260- 	//	"timestamp": [ "KEYID1", "KEYID2"] , 
261- 	//	"snapshot": [ "KEYID3"] , 
262- 	//	"targets": [ "KEYID4", "KEYID5", "KEYID6"]  
257+ 	//	"timestamp": {KeyIDs={ "KEYID1": true , "KEYID2": true}, Threshold=2} , 
258+ 	//	"snapshot": {KeyIDs={ "KEYID3": true}, Threshold=1} , 
259+ 	//	"targets": {KeyIDs={ "KEYID4": true , "KEYID5": true , "KEYID6": true}, Threshold=1}  
263260	// } 
264261
265262	nonRootKeyInfo  :=  map [string ]KeyInfo {"timestamp" : {}, "snapshot" : {}, "targets" : {}}
266- 	//nonRootThreshold := map[string]int{"timestamp": 1, "snapshot": 1, "targets": 1} 
267263	for  k  :=  range  nonRootKeyInfo  {
268264		nonRootKeyInfo [k ] =  getKeyInfo (k )
269265	}
@@ -299,9 +295,8 @@ func (c *Client) updateRoots() error {
299295			if  _ , ok  :=  err .(ErrMissingRemoteMetadata ); ok  {
300296				// stop when the next root can't be downloaded 
301297				break 
302- 			} else  {
303- 				return  err 
304298			}
299+ 			return  err 
305300		}
306301
307302		// 5.3.4 Check for an arbitrary software attack. 
@@ -369,7 +364,11 @@ func (c *Client) updateRoots() error {
369364	// timestamp -> delete timestamp.json 
370365	// snapshot ->  delete timestamp.json and snapshot.json 
371366	// targets ->   delete snapshot.json and targets.json 
367+ 	// 
368+ 	// nonRootKeyInfo contains the keys and thresholds from root.json 
369+ 	// that were on disk before the root update process begins. 
372370	for  topLevelRolename  :=  range  nonRootKeyInfo  {
371+ 		// ki contains the keys and thresholds from the latest downloaded root.json. 
373372		ki  :=  getKeyInfo (topLevelRolename )
374373		if  countDeleted (nonRootKeyInfo [topLevelRolename ].KeyIDs , ki .KeyIDs ) >=  nonRootKeyInfo [topLevelRolename ].Threshold  {
375374			deleteMeta  :=  map [string ][]string {
@@ -479,6 +478,7 @@ func (c *Client) loadAndVerifyLocalRootMeta() error {
479478		return  err 
480479	}
481480	c .consistentSnapshot  =  root .ConsistentSnapshot 
481+ 	c .rootVer  =  root .Version 
482482	c .db  =  ndb 
483483	return  nil 
484484}
0 commit comments