File tree Expand file tree Collapse file tree 3 files changed +36
-5
lines changed
tests/integration_tests/structures_tests/buffers_tests Expand file tree Collapse file tree 3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ fn main() {
38
38
println ! ( "cargo:rustc-cfg=has_tss_base_rc_values_52_to_53" )
39
39
}
40
40
41
+ let has_tpmu_sensitive_create_req = VersionReq :: parse ( ">=4.0.0" ) . unwrap ( ) ;
42
+ if has_tpmu_sensitive_create_req. matches ( & tss_version) {
43
+ println ! ( "cargo:rustc-cfg=has_tpmu_sensitive_create" )
44
+ }
45
+
41
46
#[ cfg( feature = "generate-bindings" ) ]
42
47
{
43
48
let has_esys_tr_get_tpm_handle_req = VersionReq :: parse ( ">=2.4.0" ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -354,11 +354,28 @@ pub mod public_key_rsa {
354
354
}
355
355
356
356
pub mod sensitive_data {
357
- buffer_type ! (
358
- SensitiveData ,
359
- :: std:: mem:: size_of:: <TPM2B_SENSITIVE_DATA >( ) ,
360
- TPM2B_SENSITIVE_DATA
361
- ) ;
357
+ // The specification says that the size of the buffer should be the size
358
+ // TPMU_SENSITIVE_CREATE structure. This does not exist in all the
359
+ // versions of tpm2-tss supported by the crate so the fall back is to
360
+ // calculate the max size by removing the size of the size parameter(UINT16)
361
+ // from the total size of the buffer type.
362
+ cfg_if:: cfg_if! {
363
+ if #[ cfg( has_tpmu_sensitive_create) ] {
364
+ use crate :: tss2_esys:: TPMU_SENSITIVE_CREATE ;
365
+ buffer_type!(
366
+ SensitiveData ,
367
+ :: std:: mem:: size_of:: <TPMU_SENSITIVE_CREATE >( ) ,
368
+ TPM2B_SENSITIVE_DATA
369
+ ) ;
370
+ } else {
371
+ use crate :: tss2_esys:: UINT16 ;
372
+ buffer_type!(
373
+ SensitiveData ,
374
+ std:: mem:: size_of:: <TPM2B_SENSITIVE_DATA >( ) - std:: mem:: size_of:: <UINT16 >( ) ,
375
+ TPM2B_SENSITIVE_DATA
376
+ ) ;
377
+ }
378
+ }
362
379
}
363
380
364
381
pub mod symmetric_key {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use tss_esapi::{
6
6
tss2_esys:: TPM2B_SENSITIVE_CREATE ,
7
7
Error , WrapperErrorKind ,
8
8
} ;
9
+ use tss_esapi_sys:: TPM2B_SENSITIVE_DATA ;
9
10
10
11
// TPM2B_AUTH = TPM2B_DIGEST = u16 + [u8;64] = 2 + 64 = 66
11
12
// TPM2B_SENSITIVE_DATA = u16 + [u8; 256] = 2 + 256 = 258
@@ -124,3 +125,11 @@ fn test_marshall_unmarshall() {
124
125
"SensitiveCreate converted from SensitiveCreateBuffer did not contain the expected values"
125
126
) ;
126
127
}
128
+
129
+ #[ test]
130
+ fn test_conversion_from_max_size_buffer ( ) {
131
+ let data = vec ! [ 1u8 ; SensitiveData :: MAX_SIZE ] ;
132
+ let sensitive_data = SensitiveData :: try_from ( data)
133
+ . expect ( "It should be possible to convert maximum amount of data into SensitiveData." ) ;
134
+ let _ = TPM2B_SENSITIVE_DATA :: from ( sensitive_data) ;
135
+ }
You can’t perform that action at this time.
0 commit comments