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

Refactoring auth data to not use heapless Strings, fixing build #150

Merged
merged 3 commits into from
Sep 6, 2023

Conversation

ryan-summers
Copy link
Member

@ryan-summers ryan-summers commented Sep 5, 2023

This PR updates auth to:

  1. Use the ConfigBuilder struct for specification to align with other start-up behaviors
  2. Uses the buffer from the config to back the memory needed to cache the auth credentials, eliminating the need for heapless::String types (which impose run-time cost on users that don't need auth)
  3. Excludes auth serialization without the expected feature flag to prevent accidentally providing insecure credentials.

CC @cnmozzie

@ryan-summers ryan-summers changed the title Refactoring auth data to not use heapless Strings Refactoring auth data to not use heapless Strings, fixing build Sep 5, 2023
Copy link
Member

@jordens jordens left a comment

Choose a reason for hiding this comment

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

LGTM

In practice, is it easy to keep the username and password alive long enough to meet the borrowing lifetime requirement?

@cnmozzie
Copy link
Contributor

cnmozzie commented Sep 6, 2023

When I run cargo build --features "unsecure" it shows the error message:

Compiling minimq v0.7.0 (D:\code\rust\minimq)
error[E0308]: mismatched types
  --> src\config.rs:93:13
   |
93 |             user_name,
   |             ^^^^^^^^^ expected `&str`, found `&mut [u8]`
   |
   = note:      expected reference `&str`
           found mutable reference `&mut [u8]`

error[E0308]: mismatched types
  --> src\config.rs:94:13
   |
94 |             password,
   |             ^^^^^^^^ expected `&str`, found `&mut [u8]`
   |
   = note:      expected reference `&str`
           found mutable reference `&mut [u8]`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `minimq` (lib) due to 2 previous errors

@ryan-summers
Copy link
Member Author

@cnmozzie Thanks for the heads up! I fixed CI so that it builds with --all-features now to prevent this in the future and cleaned up the code :)

@cnmozzie
Copy link
Contributor

cnmozzie commented Sep 6, 2023

@cnmozzie Thanks for the heads up! I fixed CI so that it builds with --all-features now to prevent this in the future and cleaned up the code :)

Nice, can't wait to see the new release :)

@ryan-summers
Copy link
Member Author

In practice, is it easy to keep the username and password alive long enough to meet the borrowing lifetime requirement?

It sort of depends. If the username / password are hard-coded CONST in the end user application, they have a static lifetime and we don't need to keep a copy around. However, there's also the use case where credentials would be stored in EEPROM or external memory (i.e. are settable at run time). In this case, the user would read them into a stack-allocated buffer before handing them to the client. In this case, the strings would lose scope afterwards. This is why I opted for using some of the buffer the user provides to keep a copy of them around instead.

@ryan-summers ryan-summers merged commit 0932655 into master Sep 6, 2023
7 checks passed
@ryan-summers ryan-summers deleted the rs/cleanup branch September 6, 2023 08:09
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.

None yet

3 participants