public inbox for tpm2@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] refactor!(message): decouple TpmHeader from the build trait
@ 2025-08-31 16:25 Jarkko Sakkinen
  2025-08-31 16:29 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Jarkko Sakkinen @ 2025-08-31 16:25 UTC (permalink / raw)
  To: tpm-protocol; +Cc: tpm2, Jarkko Sakkinen

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 <jarkko@kernel.org>
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] refactor!(message): decouple TpmHeader from the build trait
  2025-08-31 16:25 [PATCH] refactor!(message): decouple TpmHeader from the build trait Jarkko Sakkinen
@ 2025-08-31 16:29 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2025-08-31 16:29 UTC (permalink / raw)
  To: tpm-protocol; +Cc: tpm2

On Sun, Aug 31, 2025 at 07:25:28PM +0300, Jarkko Sakkinen wrote:
> 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 <jarkko@kernel.org>
> ---
> 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
> 

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-31 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-31 16:25 [PATCH] refactor!(message): decouple TpmHeader from the build trait Jarkko Sakkinen
2025-08-31 16:29 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox