Skip to content

Rust bindings #3

Open
josephlr wants to merge 2 commits into
bindingsfrom
rust_bindings
Open

Rust bindings #3
josephlr wants to merge 2 commits into
bindingsfrom
rust_bindings

Conversation

@josephlr
Copy link
Copy Markdown
Member

@josephlr josephlr commented May 15, 2026

This uses 5 extern "C" entrypoint functions and a single Platform trait to bind the the reference C code.

TODO: Add instructions on publishing crate.

@josephlr josephlr requested a review from crocomegan May 15, 2026 21:17
Copy link
Copy Markdown
Collaborator

@crocomegan crocomegan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the changes LGTM. A few architectural thoughts:

  • Since our ultimate goal is to phase out the C FFIs in favor of native Rust functions, we should avoid calling ExecuteCommand() with raw pointers directly in the long term. Instead, we should introduce a Rust dispatcher (shim wrapper). The wrapper will route commands to our Rust logic as it gets implemented while gracefully falling back to the legacy C FFIs for unimplemented paths.
  • Ideally we want more Rust code in tpm-rs. I would recommend adding the Rust dispatcher and these high-level traits defined in platform.rs directly into the tpm-rs repo.
  • In that case, I would also like to see more integration tests added to the tpm-rs repo instead of the tests/basic.rs.

Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr josephlr changed the title WIP: Rust bindings Rust bindings May 21, 2026
@josephlr
Copy link
Copy Markdown
Member Author

Overall, the changes LGTM. A few architectural thoughts:

  • Since our ultimate goal is to phase out the C FFIs in favor of native Rust functions, we should avoid calling ExecuteCommand() with raw pointers directly in the long term. Instead, we should introduce a Rust dispatcher (shim wrapper). The wrapper will route commands to our Rust logic as it gets implemented while gracefully falling back to the legacy C FFIs for unimplemented paths.

Agreed. However, the wrapper should live in tpm2-ref so that we can keep this crate as low-level as possible. The tpm2-ref crate will not expose raw pointers.

  • Ideally we want more Rust code in tpm-rs. I would recommend adding the Rust dispatcher and these high-level traits defined in platform.rs directly into the tpm-rs repo.

Agreed, moved everything into a single Platform trait, without any default impl

  • In that case, I would also like to see more integration tests added to the tpm-rs repo instead of the tests/basic.rs.

Agreed, removed all tests except a linking-based test in src/tests.rs. That just verifies that everything builds and doesn't segfault.

@josephlr josephlr requested a review from crocomegan May 21, 2026 23:16
Signed-off-by: Joe Richey <joerichey@google.com>
Comment thread bindings/rust/src/lib.rs

pub use platform::*;

pub const MAX_RESPONSE_SIZE: u32 = 0x1000 - 0x80;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about how this is calculated. Or we can also extern this value from C (if any).

@josephlr josephlr marked this pull request as ready for review May 22, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants