@@ -6,7 +6,7 @@ use crate::pcrs::{Pcr, compile_pcrs};
66use crate :: tpmevents:: { TPMEvent , TPMEventID } ;
77
88use hex:: decode;
9- use std:: collections:: HashMap ;
9+ use std:: collections:: { HashMap , HashSet } ;
1010
1111#[ test]
1212fn test_tpm_event_id_hashmap ( ) {
@@ -1207,3 +1207,68 @@ fn test_pcr7_enable_secureboot() {
12071207
12081208 assert_eq ! ( res, expected) ;
12091209}
1210+
1211+ #[ test]
1212+ fn test_image_combinations ( ) {
1213+ let shim1 = TPMEvent {
1214+ name : "shim1" . into ( ) ,
1215+ pcr : 4 ,
1216+ hash : decode ( "f6f919856f814f30c2043b567c9434b73b658f2360175f18e49da81112216be0" ) . unwrap ( ) ,
1217+ id : TPMEventID :: Pcr4Shim ,
1218+ } ;
1219+ let shim2 = TPMEvent {
1220+ name : "shim2" . into ( ) ,
1221+ pcr : 4 ,
1222+ hash : decode ( "5921135eb8f625f3050a92d66551ef0a6682b8c393af8ef8379a1332f1f1872f" ) . unwrap ( ) ,
1223+ id : TPMEventID :: Pcr4Shim ,
1224+ } ;
1225+ let kernel1 = TPMEvent {
1226+ name : "kernel1" . into ( ) ,
1227+ pcr : 4 ,
1228+ hash : decode ( "2b1dc59bc61dbbc3db11a6f3b0708c948efd46cceb7f6c8ea2024b8d1b8c829a" ) . unwrap ( ) ,
1229+ id : TPMEventID :: Pcr4Vmlinuz ,
1230+ } ;
1231+ let kernel2 = TPMEvent {
1232+ name : "kernel2" . into ( ) ,
1233+ pcr : 4 ,
1234+ hash : decode ( "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35" ) . unwrap ( ) ,
1235+ id : TPMEventID :: Pcr4Vmlinuz ,
1236+ } ;
1237+ let kernel3 = TPMEvent {
1238+ name : "kernel3" . into ( ) ,
1239+ pcr : 4 ,
1240+ hash : decode ( "4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce" ) . unwrap ( ) ,
1241+ id : TPMEventID :: Pcr4Vmlinuz ,
1242+ } ;
1243+ let kernel4 = TPMEvent {
1244+ name : "kernel4" . into ( ) ,
1245+ pcr : 4 ,
1246+ hash : decode ( "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a" ) . unwrap ( ) ,
1247+ id : TPMEventID :: Pcr4Vmlinuz ,
1248+ } ;
1249+
1250+ let images = vec ! [
1251+ vec![ shim1. clone( ) , kernel1. clone( ) ] ,
1252+ vec![ shim1. clone( ) , kernel2. clone( ) ] ,
1253+ vec![ shim2. clone( ) , kernel3. clone( ) ] ,
1254+ vec![ shim2. clone( ) , kernel4. clone( ) ] ,
1255+ ] ;
1256+
1257+ let res = combine_images ( & images) ;
1258+ let expected: Vec < Vec < Pcr > > = vec ! [
1259+ compile_pcrs( & vec![ shim1. clone( ) , kernel1. clone( ) ] ) ,
1260+ compile_pcrs( & vec![ shim1. clone( ) , kernel2. clone( ) ] ) ,
1261+ compile_pcrs( & vec![ shim1. clone( ) , kernel3. clone( ) ] ) ,
1262+ compile_pcrs( & vec![ shim1. clone( ) , kernel4. clone( ) ] ) ,
1263+ compile_pcrs( & vec![ shim2. clone( ) , kernel1. clone( ) ] ) ,
1264+ compile_pcrs( & vec![ shim2. clone( ) , kernel2. clone( ) ] ) ,
1265+ compile_pcrs( & vec![ shim2. clone( ) , kernel3. clone( ) ] ) ,
1266+ compile_pcrs( & vec![ shim2. clone( ) , kernel4. clone( ) ] ) ,
1267+ ] ;
1268+
1269+ assert_eq ! ( res. len( ) , expected. len( ) ) ;
1270+ assert_eq ! (
1271+ HashSet :: <_>:: from_iter( res. iter( ) . flat_map( |e| e. clone( ) ) ) ,
1272+ HashSet :: <_>:: from_iter( expected. iter( ) . flat_map( |e| e. clone( ) ) ) ,
1273+ ) ;
1274+ }
0 commit comments