@@ -4,7 +4,6 @@ mod test_pcr_extend_reset {
4
4
use crate :: common:: create_ctx_with_session;
5
5
use std:: convert:: TryFrom ;
6
6
use tss_esapi:: {
7
- abstraction:: pcr:: PcrData ,
8
7
handles:: PcrHandle ,
9
8
interface_types:: algorithm:: HashingAlgorithm ,
10
9
structures:: { Digest , DigestValues , PcrSelectionListBuilder , PcrSlot } ,
@@ -34,6 +33,12 @@ mod test_pcr_extend_reset {
34
33
} ) ;
35
34
36
35
// 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 ) ;
37
42
read_pcr_selections
38
43
. get_selections ( )
39
44
. iter ( )
@@ -73,8 +78,8 @@ mod test_pcr_extend_reset {
73
78
} ) ;
74
79
75
80
// 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 ( ) ) ;
78
83
// Needs to have the length of associated with the hashing algorithm
79
84
/*
80
85
Right Hand Side determined by:
@@ -87,11 +92,16 @@ mod test_pcr_extend_reset {
87
92
>>> res = ["0x"+a+b for a,b in zip(it, it)]
88
93
>>> ", ".join(res)
89
94
*/
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
92
102
. get_selections ( )
93
103
. iter ( )
94
- . zip ( read_pcr_digests_2 . value ( ) . iter ( ) )
104
+ . zip ( after_extend_read_pcr_digests . value ( ) . iter ( ) )
95
105
. for_each ( |( pcr_selection, digest) | {
96
106
if pcr_selection. hashing_algorithm ( ) == HashingAlgorithm :: Sha1 {
97
107
assert_eq ! ( digest. len( ) , 20 ) ;
@@ -121,28 +131,35 @@ mod test_pcr_extend_reset {
121
131
context. execute_with_session ( pcr_ses, |ctx| ctx. pcr_reset ( PcrHandle :: Pcr16 ) . unwrap ( ) ) ;
122
132
123
133
// 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
130
135
. 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
+ } ) ;
146
163
}
147
164
}
148
165
0 commit comments