Skip to content

Commit

Permalink
Merge branch 'master' into rs/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers committed Sep 6, 2023
2 parents a9f2bf6 + d23b49a commit 1569843
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --all-features
- name: cargo build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release
args: --release --all-features

test:
runs-on: ubuntu-20.04
Expand Down
28 changes: 12 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,26 @@ impl<'a, Broker: crate::Broker> ConfigBuilder<'a, Broker> {
/// * `user_name` - The user name
/// * `password` - The password
#[cfg(feature = "unsecure")]
pub fn set_auth(&mut self, user_name: &str, password: &str) -> Result<(), ProtocolError> {
pub fn set_auth(mut self, user_name: &str, password: &str) -> Result<Self, ProtocolError> {
if self.auth.is_some() {
return Err(ProtocolError::AuthAlreadySpecified);
}

let user_name = {
let (username, tail) = self.buffer.split_at_mut(user_name.as_bytes().len());
username.copy_from_slice(user_name.as_bytes());
self.buffer = tail;
username
};
let (username_bytes, tail) = self.buffer.split_at_mut(user_name.as_bytes().len());
username_bytes.copy_from_slice(user_name.as_bytes());
self.buffer = tail;

let password = {
let (pass_word, tail) = self.buffer.split_at_mut(password.as_bytes().len());
pass_word.copy_from_slice(password.as_bytes());
self.buffer = tail;
pass_word
};
let (password_bytes, tail) = self.buffer.split_at_mut(password.as_bytes().len());
password_bytes.copy_from_slice(password.as_bytes());
self.buffer = tail;

self.auth.replace(Auth {
user_name,
password,
// Note(unwrap): We are directly copying `str` types to these buffers, so we know they
// are valid utf8.
user_name: core::str::from_utf8(username_bytes).unwrap(),
password: core::str::from_utf8(password_bytes).unwrap(),
});
Ok(())
Ok(self)
}

/// Specify a specific configuration for the session state buffer.
Expand Down
1 change: 1 addition & 0 deletions src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<'a> serde::Serialize for Connect<'a> {
if let Some(will) = &self.will {
item.serialize_field("will", will.contents)?;
}

if let Some(auth) = &self.auth {
item.serialize_field("user_name", &Utf8String(auth.user_name))?;
item.serialize_field("password", &Utf8String(auth.password))?;
Expand Down

0 comments on commit 1569843

Please sign in to comment.