Conversation

Jarkko Sakkinen

Edited 4 days ago

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>),
    }
}
1
0
0

Jarkko Sakkinen

Edited 4 days ago

And this is how it works:

let (ref, tail) = TpmsClockInfoCast::from_slice(bytes);
let TpmsClockInfoFieldRef::clock(clock) = ref.field(TpmsClockInfoField::clock).unwrap()
0
0
0