mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-06-11 18:54:03 +02:00
1bab5c3cd9
These became warnings in a recent nightly.
The TryFrom/TryInto imports were missed in
4089891f6c
, but the rest are truly
redundant.
33 lines
1003 B
Rust
33 lines
1003 B
Rust
use futures::stream::StreamExt;
|
|
use tokio::io::{AsyncRead, AsyncWrite};
|
|
use xmpp_parsers::{component::Handshake, ns};
|
|
|
|
use crate::xmpp_codec::Packet;
|
|
use crate::xmpp_stream::XMPPStream;
|
|
use crate::{AuthError, Error};
|
|
|
|
pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
|
|
stream: &mut XMPPStream<S>,
|
|
password: String,
|
|
) -> Result<(), Error> {
|
|
let nonza = Handshake::from_password_and_stream_id(&password, &stream.id);
|
|
stream.send_stanza(nonza).await?;
|
|
|
|
loop {
|
|
match stream.next().await {
|
|
Some(Ok(Packet::Stanza(ref stanza)))
|
|
if stanza.is("handshake", ns::COMPONENT_ACCEPT) =>
|
|
{
|
|
return Ok(());
|
|
}
|
|
Some(Ok(Packet::Stanza(ref stanza)))
|
|
if stanza.is("error", "http://etherx.jabber.org/streams") =>
|
|
{
|
|
return Err(AuthError::ComponentFail.into());
|
|
}
|
|
Some(_) => {}
|
|
None => return Err(Error::Disconnected),
|
|
}
|
|
}
|
|
}
|