great now i have a single data-drive test where test cases translate between legacy (build/parse) and new (zerocopy fat pointers):
# ...
TPM_CC_Startup Response TPM_RC_FAILURE 80010000000a00000101
TPM_CC_Startup Response TPM_RC_CONTEXT_GAP 80010000000a00000901
TPM_CC_PCR_Read Response Success 800100000038000000000000000100000000000000010020dededededededededededededededededededededededededededededededed
# ...
awesome “cast” version of tpm_enum!:
tpm_enum_cast! {
name: TpmRcBaseCast,
repr: TpmUint32,
value_enum: TpmRcBaseEnumCast,
value_repr: u32,
variants: {
(Success, 0x0000, "TPM_RC_SUCCESS"),
(BadTag, 0x001E, "TPM_RC_BAD_TAG"),
(Initialize, TPM_RC_VER1, "TPM_RC_INITIALIZE"),
(Failure, TPM_RC_VER1 | 0x001, "TPM_RC_FAILURE"),
// ...
And this is how it works:
let (ref, tail) = TpmsClockInfoCast::from_slice(bytes);
let TpmsClockInfoFieldRef::clock(clock) = ref.field(TpmsClockInfoField::clock).unwrap()
Cast version TPM structures starts to shape:
use crate::{tpm_struct_cast, TpmUint32, TpmUint64, TpmUint8};
tpm_struct_cast! {
name: TpmsClockInfoCast,
field_enum: TpmsClockInfoField,
field_ref_enum: TpmsClockInfoFieldRef,
fields: {
(pub clock: TpmUint64<'a>),
(pub reset_count: TpmUint32<'a>),
(pub restart_count: TpmUint32<'a>),
(pub safe: TpmUint8<'a>),
}
}
And after migration is completed:
use crate::{tpm_struct_cast, TpmUint32, TpmUint64, TpmUint8};
tpm_struct! {
name: TpmsClockInfo,
field_enum: TpmsClockInfoField,
field_ref_enum: TpmsClockInfoFieldRef,
fields: {
(pub clock: TpmUint64<'a>),
(pub reset_count: TpmUint32<'a>),
(pub restart_count: TpmUint32<'a>),
(pub safe: TpmUint8<'a>),
}
}