[PATCH] refactor!(message): decouple TpmHeader from the build trait
Jarkko Sakkinen <[email protected]> Sun, 31 Aug 2025 19:25:28 +0300
| Newsgroups | dev.linux.lists.tpm-protocol,dev.linux.lists.tpm2 |
|---|---|
| Message-ID | <[email protected]> |
In order to make the command build trait more symmetrical with the parse trait, decouple `TpmHeader` from the trait. Rename the trait as `TpmCommandBuild`. Signed-off-by: Jarkko Sakkinen <[email protected]> --- I think I'll backport this too to the 0.10.x as it by pracical means does not affect the consumed API and user volumes are still low. src/macro/struct.rs | 6 +++--- src/message/build.rs | 4 ++-- src/message/mod.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/macro/struct.rs b/src/macro/struct.rs index 01e2cfb..ad5303f 100644 --- a/src/macro/struct.rs +++ b/src/macro/struct.rs @@ -36,12 +36,12 @@ macro_rules! tpm_struct { impl $crate::TpmBuild for $name { #[allow(unused_variables)] fn build(&self, writer: &mut $crate::TpmWriter) -> $crate::TpmResult<()> { - <Self as $crate::message::TpmHeaderCommand>::build_handles(self, writer)?; - <Self as $crate::message::TpmHeaderCommand>::build_parameters(self, writer) + <Self as $crate::message::TpmCommandBuild>::build_handles(self, writer)?; + <Self as $crate::message::TpmCommandBuild>::build_parameters(self, writer) } } - impl $crate::message::TpmHeaderCommand for $name { + impl $crate::message::TpmCommandBuild for $name { #[allow(unused_variables)] fn build_handles(&self, writer: &mut $crate::TpmWriter) -> $crate::TpmResult<()> { $($crate::TpmBuild::build(&self.$handle_field, writer)?;)* diff --git a/src/message/build.rs b/src/message/build.rs index 4170513..41a7fee 100644 --- a/src/message/build.rs +++ b/src/message/build.rs @@ -4,7 +4,7 @@ use crate::{ data::{TpmRc, TpmSt, TpmsAuthCommand, TpmsAuthResponse}, - message::{TpmHeader, TpmHeaderCommand, TPM_HEADER_SIZE}, + message::{TpmCommandBuild, TpmHeader, TPM_HEADER_SIZE}, TpmBuild, TpmErrorKind, TpmResult, TpmSized, }; use core::mem::size_of; @@ -21,7 +21,7 @@ pub fn tpm_build_command<C>( writer: &mut crate::TpmWriter, ) -> TpmResult<()> where - C: TpmHeaderCommand, + C: TpmHeader + TpmCommandBuild, { match tag { TpmSt::NoSessions => { diff --git a/src/message/mod.rs b/src/message/mod.rs index eb0d3f0..2d02361 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -60,7 +60,7 @@ pub trait TpmHeader: TpmBuild + Debug { } /// A trait for building command bodies in separate handle and parameter sections. -pub trait TpmHeaderCommand: TpmHeader { +pub trait TpmCommandBuild { /// Builds the handle area of the command. /// /// # Errors -- 2.39.5