Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dpapi): implement basic RPC structures encoding/decoding #342

Merged
merged 25 commits into from
Jan 15, 2025

Conversation

TheBestTvarynka
Copy link
Collaborator

Hi,
In this PR, I initialized the dpapi crate and implemented basic RPC structure encoding/decoding.

@TheBestTvarynka TheBestTvarynka self-assigned this Jan 9, 2025
@TheBestTvarynka TheBestTvarynka changed the base branch from master to dev/dpapi January 9, 2025 09:50
@TheBestTvarynka TheBestTvarynka marked this pull request as ready for review January 9, 2025 10:06
Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

This is excellent work. Thank you! I left a few informational comments and suggestion that I’ll let you consider for improving the code before we merge (while we wait for picky), but nonetheless, I think you did a great job here.

crates/dpapi/README.md Show resolved Hide resolved
crates/dpapi/src/error.rs Outdated Show resolved Hide resolved
crates/dpapi/src/rpc/bind.rs Outdated Show resolved Hide resolved
crates/dpapi/src/rpc/pdu.rs Outdated Show resolved Hide resolved
crates/dpapi/src/rpc/mod.rs Show resolved Hide resolved
use crate::{DpapiResult, Error};

trait Encode {
fn encode(&self, writer: impl Write) -> DpapiResult<()>;
Copy link
Member

@CBenoit CBenoit Jan 10, 2025

Choose a reason for hiding this comment

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

note: In IronRDP again, the choice was made to not use impl genericity for a few reasons:

I think ideally this kind of library should be sans-I/O / I/O-free: https://sans-io.readthedocs.io/#
The I/O part is driven by a thin layer feeding bytes in and reading bytes out.

This approach is still fine as I/O is not hardcoded either. It’s possible to use Vec and other in-memory buffer to work.
The main benefit is that you don’t need to know the required number of bytes ahead of time because you can just plug the TcpStream and read bytes out of it as you need.

Just information for you to consider, but I won’t impose you to change anything.

Copy link
Collaborator Author

@TheBestTvarynka TheBestTvarynka Jan 13, 2025

Choose a reason for hiding this comment

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

Yes, I agree with your points. Thank you for the additional links ☺️

The main benefit is that you don’t need to know the required number of bytes ahead of time because you can just plug the TcpStream and read bytes out of it as you need.

Yep. And &mut Write/Read also implements Write/Read. It's super convenient ☺️

but I won’t impose you to change anything.

😊

crates/dpapi/src/rpc/pdu.rs Outdated Show resolved Hide resolved
crates/dpapi/src/rpc/pdu.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

note: Most of the changes you made to this file could have been in a separate PR as it seems unrelated to the dpapi feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, yes, you are right. These changes somehow leaked from upcoming PRs 😅 I didn't notice it

crates/dpapi/README.md Outdated Show resolved Hide resolved
@TheBestTvarynka TheBestTvarynka force-pushed the feat/dpapi-rpc-structures branch from 8fb48ec to 5600c83 Compare January 13, 2025 18:06
Comment on lines 5 to 12
#[error("{0:?}")]
#[error("IO error")]
Io(#[from] std::io::Error),

#[error("UUID error: {0:?}")]
#[error("UUID error")]
Uuid(#[from] uuid::Error),

#[error("integer conversion error: {0:?}")]
#[error("integer conversion error")]
IntConversion(#[from] std::num::TryFromIntError),
Copy link
Member

Choose a reason for hiding this comment

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

note: It also occurred to me that thiserror has a error(transparent) attribute for situations where adding an additional message is not relevant.

https://docs.rs/thiserror/latest/thiserror/#details

Also a worthwhile read: https://www.howtocodeit.com/articles/the-definitive-guide-to-rust-error-handling

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

LGTM! Great work. I added a comment, but I’m merging now as there is no reason to block the PR further.

EDIT: Oh, almost forgot about the picky crates. Should be published shortly, I’m looking into a problem with the publish workflow.

@CBenoit
Copy link
Member

CBenoit commented Jan 14, 2025

@TheBestTvarynka Can you switch to the published version? Devolutions/picky-rs#338

Feel free to merge the PR yourself after 🙂

@TheBestTvarynka TheBestTvarynka merged commit 1bcff60 into dev/dpapi Jan 15, 2025
42 checks passed
@TheBestTvarynka TheBestTvarynka deleted the feat/dpapi-rpc-structures branch January 15, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants