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() {
3838 println ! ( "cargo:rustc-cfg=has_tss_base_rc_values_52_to_53" )
3939 }
4040
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+
4146 #[ cfg( feature = "generate-bindings" ) ]
4247 {
4348 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 {
354354}
355355
356356pub 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+ }
362379}
363380
364381pub mod symmetric_key {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use tss_esapi::{
66 tss2_esys:: TPM2B_SENSITIVE_CREATE ,
77 Error , WrapperErrorKind ,
88} ;
9+ use tss_esapi_sys:: TPM2B_SENSITIVE_DATA ;
910
1011// TPM2B_AUTH = TPM2B_DIGEST = u16 + [u8;64] = 2 + 64 = 66
1112// TPM2B_SENSITIVE_DATA = u16 + [u8; 256] = 2 + 256 = 258
@@ -124,3 +125,11 @@ fn test_marshall_unmarshall() {
124125 "SensitiveCreate converted from SensitiveCreateBuffer did not contain the expected values"
125126 ) ;
126127}
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