diff --git a/crates/projection-xmpp/src/lib.rs b/crates/projection-xmpp/src/lib.rs index 2a25e82..e854039 100644 --- a/crates/projection-xmpp/src/lib.rs +++ b/crates/projection-xmpp/src/lib.rs @@ -257,9 +257,7 @@ async fn socket_auth( let auth: proto_xmpp::sasl::Auth = proto_xmpp::sasl::Auth::parse(xml_reader, reader_buf).await?; proto_xmpp::sasl::Success.write_xml(xml_writer).await?; - let auth_body = AuthBody::from_str(auth.body); - - match auth_body { + match AuthBody::from_str(&auth.body) { Ok(logopass) => { let name = &logopass.login; let stored_user = storage.retrieve_user_by_name(name).await?; @@ -288,8 +286,8 @@ async fn socket_auth( xmpp_resource: Resource(name.to_string().into()), xmpp_muc_name: Resource(name.to_string().into()), }) - } - Err(e) => Err(e) + }, + Err(e) => return Err(e) } } diff --git a/crates/proto-xmpp/src/sasl.rs b/crates/proto-xmpp/src/sasl.rs index 3ee15b8..53b3c96 100644 --- a/crates/proto-xmpp/src/sasl.rs +++ b/crates/proto-xmpp/src/sasl.rs @@ -35,13 +35,21 @@ pub struct AuthBody { } impl AuthBody { - pub fn from_str(input: Vec) -> Result { - let decoded_body = general_purpose::STANDARD.decode(input).unwrap(); - let parsed_to_string = String::from_utf8(decoded_body).unwrap(); - let separated_words: Vec<&str> = parsed_to_string.split("\x00").filter(|&part| !part.is_empty()).collect::>().clone(); - if separated_words.len() == 2 { - Ok(AuthBody { login: separated_words[0].to_string(), password: separated_words[1].to_string() }) - } else { Err(anyhow!("Incorrect auth format")) } + pub fn from_str(input: &[u8]) -> Result { + match general_purpose::STANDARD.decode(input){ + Ok(decoded_body) => { + match String::from_utf8(decoded_body) { + Ok(parsed_to_string) => { + let separated_words: Vec<&str> = parsed_to_string.split("\x00").filter(|&part| !part.is_empty()).collect::>().clone(); + if separated_words.len() == 2 { + Ok(AuthBody { login: separated_words[0].to_string(), password: separated_words[1].to_string() }) + } else { return Err(anyhow!("Incorrect auth format")) } + }, + Err(e) => return Err(anyhow!(e)) + } + }, + Err(e) => return Err(anyhow!(e)) + } } }