Skip to content

refactor(dapapi): encoding/decoding traits #402

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

Merged

Conversation

TheBestTvarynka
Copy link
Collaborator

@TheBestTvarynka TheBestTvarynka commented Mar 18, 2025

Hi,
I rework the encoding/decoding traits. Our goal is to support WASM. I took your past comment (#342 (comment)) into account and tried to make it similar to IronRDP and other projects.

I didn't change any DPAPI-related logic. This PR contains only decoding/encoding refactoring.

…ement encoding/decoding for bind-related structures;
@TheBestTvarynka TheBestTvarynka self-assigned this Mar 18, 2025
@TheBestTvarynka TheBestTvarynka changed the title Refactor/dpapi encoding traits refactor(dapapi): encoding/decoding traits Mar 18, 2025
@TheBestTvarynka TheBestTvarynka marked this pull request as ready for review March 18, 2025 12:55
@TheBestTvarynka TheBestTvarynka requested a review from CBenoit March 18, 2025 12:55
@TheBestTvarynka
Copy link
Collaborator Author

Do not merge it yet :) currently, I'm testing it on my environment after the refactoring

@TheBestTvarynka
Copy link
Collaborator Author

Do not merge it yet :) currently, I'm testing it on my environment after the refactoring

Everything works well 😊

Comment on lines 11 to 12
num-derive.workspace = true
num-traits = { workspace = true, default-features = true }
Copy link
Member

Choose a reason for hiding this comment

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

note: I typically recommend against using num-derive and num-traits crates.

Two main reasons:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Otherwise, it’s typically not worth adding a proc-macro in a core crate. (This also applies to thiserror.)

I just introduced a new crate: dpapi-pdu (#402 (comment)) and moved proc-macros (including thiserror) there.

Copy link
Member

Choose a reason for hiding this comment

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

Note that I still recommend against using num-derive and num-traits crates even in dpapi-pdu. But if you are sure it covers your needs properly, and if it’s really saving you trouble, it’s fine!

Comment on lines 11 to 14
pub mod gkdi;
mod marker;
mod padding;
pub mod rpc;
Copy link
Member

@CBenoit CBenoit Mar 24, 2025

Choose a reason for hiding this comment

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

thought: It seems gkdi and rpc modules are not providing core building blocks, and do not belong to the dpapi-core crate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought about it. I explored the IronRDP crates structure more and decided to move structures encoding and decoding implementations into a separate crate: dpapi-pdu. Moreover, I added an alloc feature to the dpapi-core crate and put the EncodeVec extension trait behind it.

I just pushed a new commit. Can you have a look?
Surprisingly, it was easy to refactor. I think it's a sign of a good architecture 🙃

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!!
It definitely is 😉

@@ -27,11 +29,11 @@ pub fn from_utf16_le(data: &[u8]) -> Result<String> {
/// Encodes str into a UTF-16 encoded byte array.
///
/// *Note*: this function automatically appends a NULL-char.
pub fn encode_utf16_le(data: &str) -> Vec<u8> {
/// *Panic*: panics when cursor's internal buffer doesn't have enough space.
Copy link
Member

@CBenoit CBenoit Mar 25, 2025

Choose a reason for hiding this comment

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

note: Typically this kind of information is specified in a dedicated section. See: https://rust-lang.github.io/api-guidelines/documentation.html#function-docs-include-error-panic-and-safety-considerations-c-failure

praise: But first, let me thank you for documenting properly this kind of things! Too often we forget to do so 😆

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! Excellent work! 💯

Feel free to merge yourself 🙂

@TheBestTvarynka TheBestTvarynka merged commit af36f1c into feat/dpapi-wasm-support Mar 25, 2025
42 checks passed
@TheBestTvarynka TheBestTvarynka deleted the refactor/dpapi-encoding-traits branch March 25, 2025 18:47
TheBestTvarynka added a commit that referenced this pull request Apr 25, 2025
Hi,
I rework the encoding/decoding traits. Our goal is to support WASM. I
took your past comment
(#342 (comment))
into account and tried to make it similar to `IronRDP` and other
projects.

I didn't change any DPAPI-related logic. This PR contains only
decoding/encoding refactoring.
TheBestTvarynka added a commit that referenced this pull request Apr 28, 2025
Hi,
I rework the encoding/decoding traits. Our goal is to support WASM. I
took your past comment
(#342 (comment))
into account and tried to make it similar to `IronRDP` and other
projects.

I didn't change any DPAPI-related logic. This PR contains only
decoding/encoding refactoring.
CBenoit pushed a commit that referenced this pull request Apr 28, 2025
Hi,
I rework the encoding/decoding traits. Our goal is to support WASM. I
took your past comment
(#342 (comment))
into account and tried to make it similar to `IronRDP` and other
projects.

I didn't change any DPAPI-related logic. This PR contains only
decoding/encoding refactoring.
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