public inbox for tpm-protocol@lists.linux.dev
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: tpm-protocol@lists.linux.dev
Cc: tpm2@lists.linux.dev
Subject: Re: [PATCH] refactor!(message): decouple TpmHeader from the build trait
Date: Sun, 31 Aug 2025 19:29:51 +0300	[thread overview]
Message-ID: <aLR4f8oHe4h-M7aw@kernel.org> (raw)
In-Reply-To: <20250831162528.482704-1-jarkko@kernel.org>

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

      reply	other threads:[~2025-08-31 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-31 16:25 [PATCH] refactor!(message): decouple TpmHeader from the build trait Jarkko Sakkinen
2025-08-31 16:29 ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aLR4f8oHe4h-M7aw@kernel.org \
    --to=jarkko@kernel.org \
    --cc=tpm-protocol@lists.linux.dev \
    --cc=tpm2@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox