refactor!(message): decouple TpmHeader from the build trait
PATCH 1/1 refactor!(message): decouple TpmHeader from the build trait
In order to make the command build trait more symmetrical with the parse trait, decouple TpmHeader from the trait. Rename the trait as TpmCommandBuild.
---
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(-)
src/macro/struct.rs +3 -3
@@ -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)?;)*
src/message/build.rs +2 -2
@@ -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 => {
src/message/mod.rs +1 -1
@@ -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
Signature · 1 line
2.39.5
Quoted 71 lines · Jarkko Sakkinen
In order to make the command build trait more symmetrical with the parse trait, decouple
TpmHeaderfrom the trait. Rename the trait asTpmCommandBuild.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(-)src/macro/struct.rs +3
-3@@ -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)?;)*src/message/build.rs +2
-2@@ -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 => {src/message/mod.rs +1
-1@@ -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 Signature · 1 line
2.39.5
This also applied (last remaiming low-hanging fruit item in my backlog). It was also backported to 0.10.x given low incompatibility risk factor.
Where main branch API wise now diverges is TpmRc (i.e. no longer is wrapped into a result structure).
BR, Jarkko