Skip to content

feat: add rust bindings#30

Draft
hseuschek wants to merge 1 commit intosiemens:masterfrom
hseuschek:hs/rust-bindings
Draft

feat: add rust bindings#30
hseuschek wants to merge 1 commit intosiemens:masterfrom
hseuschek:hs/rust-bindings

Conversation

@hseuschek
Copy link
Collaborator

@hseuschek hseuschek commented Dec 2, 2025

This contribution provides a Rust wrapper
implemented in the crate libuta_rust, along with example usage in the
examples crate.

Note: what is still missing is automatic testing of the code in the pipeline.

@taz-mcrae taz-mcrae self-requested a review December 8, 2025 08:39
Copy link
Collaborator

@taz-mcrae taz-mcrae left a comment

Choose a reason for hiding this comment

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

Overall a really nice Rust wrapper of the C library. The code is simple and clear as the right wrapper should be. It contains also detailed documentation , only rustdoc for public methods is missing.


```
cargo build
cargo run
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a minor thing, you have 2 separate rust projects (two Cargo.toml files) rather than a single project with examples. If you have a single rust project, there is a standard approach to run examples #cargo run --example <example_name>. But a separate example project is easier to take and integrate by the user.

counterintuitive, it reflects the fact that the object’s internal state changes
frequently, particularly when managing context, such as acquiring or releasing
locks. This behavior is mandated by the underlying C library interface, and
therefore cannot be avoided.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a remark: in your use-case the mutable reference to self makes more sense, but there is also a way how to avoid a mutable reference in every method: RWLock.

└── src
├── lib.rs
├── bindings.h
└── bindings.rc
Copy link
Collaborator

Choose a reason for hiding this comment

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

bindings.rs maybe?

direct use in Rust applications. Instead, it serves as the foundation for the
higher-level wrapper located in the lib.rs file.

**Note:** The Rust compiler emits warnings regarding the use of 128-bit integers
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's great that you explain why you suppress some warnings 👍

Ok(UtaApiV1{api, context: vec![0u8; context_size]})
}

pub fn derive_key(&mut self, len_key: usize, dv: &[u8], key_slot: u8) -> Result<Vec<u8>, UtaError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even though these library functions are pretty clear, it would be nice to add to each of them at least a basic rustdoc description (you can use LLM for that) to get a nice cargo doc documentation of the library.

}
}

#[cfg(test)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is great to have a unit test for each public function 👍

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