Skip to content

Commit

Permalink
refactor: use base64 function for length calc
Browse files Browse the repository at this point in the history
Instead of calculating the Base64 encoded size by hand, use the provided
function from the `base64` crate which handles some corner cases.
  • Loading branch information
dnaka91 committed Jan 19, 2025
1 parent 8bc4c23 commit 19ab162
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/client/connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashMap, VecDeque};

use base64::engine::Config;
use futures_util::{Sink, SinkExt, Stream, StreamExt};
use tokio::{
sync::{oneshot, Mutex},
Expand Down Expand Up @@ -221,7 +222,13 @@ fn create_auth_response(challenge: &str, salt: &str, password: &str) -> String {
hasher.update(password.as_bytes());
hasher.update(salt.as_bytes());

let mut auth = String::with_capacity(Sha256::output_size() * 4 / 3 + 4);
let mut auth = String::with_capacity(
base64::encoded_len(
Sha256::output_size(),
general_purpose::STANDARD.config().encode_padding(),
)
.unwrap_or_default(),
);

general_purpose::STANDARD.encode_string(hasher.finalize_reset(), &mut auth);

Expand Down

0 comments on commit 19ab162

Please sign in to comment.