@@ -4,7 +4,6 @@ mod test_pcr_extend_reset {
44 use crate :: common:: create_ctx_with_session;
55 use std:: convert:: TryFrom ;
66 use tss_esapi:: {
7- abstraction:: pcr:: PcrData ,
87 handles:: PcrHandle ,
98 interface_types:: algorithm:: HashingAlgorithm ,
109 structures:: { Digest , DigestValues , PcrSelectionListBuilder , PcrSlot } ,
@@ -34,6 +33,12 @@ mod test_pcr_extend_reset {
3433 } ) ;
3534
3635 // Needs to have the length of associated with the hashing algorithm
36+ assert_eq ! ( read_pcr_selections. get_selections( ) . len( ) , 2 ) ;
37+ assert_eq ! (
38+ pcr_selection_list. get_selections( ) ,
39+ read_pcr_selections. get_selections( )
40+ ) ;
41+ assert_eq ! ( read_pcr_digests. value( ) . len( ) , 2 ) ;
3742 read_pcr_selections
3843 . get_selections ( )
3944 . iter ( )
@@ -73,8 +78,8 @@ mod test_pcr_extend_reset {
7378 } ) ;
7479
7580 // Read PCR contents
76- let ( _, read_pcr_selections_2 , read_pcr_digests_2 ) =
77- context . execute_without_session ( |ctx| ctx. pcr_read ( pcr_selection_list) . unwrap ( ) ) ;
81+ let ( _, after_extend_read_pcr_selections , after_extend_read_pcr_digests ) = context
82+ . execute_without_session ( |ctx| ctx. pcr_read ( pcr_selection_list. clone ( ) ) . unwrap ( ) ) ;
7883 // Needs to have the length of associated with the hashing algorithm
7984 /*
8085 Right Hand Side determined by:
@@ -87,11 +92,16 @@ mod test_pcr_extend_reset {
8792 >>> res = ["0x"+a+b for a,b in zip(it, it)]
8893 >>> ", ".join(res)
8994 */
90-
91- read_pcr_selections_2
95+ assert_eq ! ( after_extend_read_pcr_selections. get_selections( ) . len( ) , 2 ) ;
96+ assert_eq ! (
97+ pcr_selection_list. get_selections( ) ,
98+ after_extend_read_pcr_selections. get_selections( )
99+ ) ;
100+ assert_eq ! ( after_extend_read_pcr_digests. value( ) . len( ) , 2 ) ;
101+ after_extend_read_pcr_selections
92102 . get_selections ( )
93103 . iter ( )
94- . zip ( read_pcr_digests_2 . value ( ) . iter ( ) )
104+ . zip ( after_extend_read_pcr_digests . value ( ) . iter ( ) )
95105 . for_each ( |( pcr_selection, digest) | {
96106 if pcr_selection. hashing_algorithm ( ) == HashingAlgorithm :: Sha1 {
97107 assert_eq ! ( digest. len( ) , 20 ) ;
@@ -121,28 +131,35 @@ mod test_pcr_extend_reset {
121131 context. execute_with_session ( pcr_ses, |ctx| ctx. pcr_reset ( PcrHandle :: Pcr16 ) . unwrap ( ) ) ;
122132
123133 // Read PCR contents
124- let pcr_selection_list = PcrSelectionListBuilder :: new ( )
125- . with_selection ( HashingAlgorithm :: Sha1 , & [ PcrSlot :: Slot16 ] )
126- . with_selection ( HashingAlgorithm :: Sha256 , & [ PcrSlot :: Slot16 ] )
127- . build ( )
128- . expect ( "Failed to create PcrSelectionList for pcr_read call after pcr_reset" ) ;
129- let pcr_data = context
134+ let ( _, after_reset_read_pcr_selections_out, after_reset_read_pcr_digests) = context
130135 . execute_without_session ( |ctx| {
131- ctx. pcr_read ( pcr_selection_list) . map (
132- |( _, read_pcr_selections, read_pcr_digests) | {
133- PcrData :: create ( & read_pcr_selections, & read_pcr_digests)
134- . expect ( "Failed to create PcrData" )
135- } ,
136- )
137- } )
138- . expect ( "Failed to call pcr_read" ) ;
139- let pcr_sha1_bank = pcr_data. pcr_bank ( HashingAlgorithm :: Sha1 ) . unwrap ( ) ;
140- let pcr_sha256_bank = pcr_data. pcr_bank ( HashingAlgorithm :: Sha256 ) . unwrap ( ) ;
141- let pcr_sha1_value = pcr_sha1_bank. get_digest ( PcrSlot :: Slot16 ) . unwrap ( ) ;
142- let pcr_sha256_value = pcr_sha256_bank. get_digest ( PcrSlot :: Slot16 ) . unwrap ( ) ;
143- // Needs to have the length of associated with the hashing algorithm
144- assert_eq ! ( pcr_sha1_value. as_bytes( ) , [ 0 ; 20 ] ) ;
145- assert_eq ! ( pcr_sha256_value. as_bytes( ) , [ 0 ; 32 ] ) ;
136+ ctx. pcr_read ( pcr_selection_list. clone ( ) )
137+ . expect ( "Failed to call pcr_read" )
138+ } ) ;
139+ assert_eq ! (
140+ after_reset_read_pcr_selections_out. get_selections( ) . len( ) ,
141+ 2
142+ ) ;
143+ assert_eq ! (
144+ pcr_selection_list. get_selections( ) ,
145+ after_reset_read_pcr_selections_out. get_selections( )
146+ ) ;
147+ assert_eq ! ( after_reset_read_pcr_digests. value( ) . len( ) , 2 ) ;
148+ after_reset_read_pcr_selections_out
149+ . get_selections ( )
150+ . iter ( )
151+ . zip ( after_reset_read_pcr_digests. value ( ) . iter ( ) )
152+ . for_each ( |( pcr_selection, digest) | {
153+ if pcr_selection. hashing_algorithm ( ) == HashingAlgorithm :: Sha1 {
154+ assert_eq ! ( digest. len( ) , 20 ) ;
155+ assert_eq ! ( digest. as_bytes( ) , [ 0 ; 20 ] ) ;
156+ } else if pcr_selection. hashing_algorithm ( ) == HashingAlgorithm :: Sha256 {
157+ assert_eq ! ( digest. len( ) , 32 ) ;
158+ assert_eq ! ( digest. as_bytes( ) , [ 0 ; 32 ] ) ;
159+ } else {
160+ panic ! ( "Read pcr selections contained unexpected HashingAlgorithm" ) ;
161+ }
162+ } ) ;
146163 }
147164}
148165
0 commit comments