From a3db744e46d3bfebc6d440d6888e6d478b355c38 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 3 Aug 2018 01:11:55 +0200 Subject: [PATCH] client::auth: update xmpp-parsers usage --- Cargo.toml | 2 +- src/client/auth.rs | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a23afb3e..4d16028a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ tokio-tls = "0.1" sasl = "0.4" jid = { version = "0.5", features = ["minidom"] } domain = "0.2" -xmpp-parsers = "0.10" +xmpp-parsers = "0.11" idna = "0.1" try_from = "0.2" quick-xml = "0.12" diff --git a/src/client/auth.rs b/src/client/auth.rs index 7d933a44..916b1ddc 100644 --- a/src/client/auth.rs +++ b/src/client/auth.rs @@ -1,4 +1,5 @@ use std::mem::replace; +use std::str::FromStr; use futures::{Future, Poll, Async, sink, Stream}; use tokio_io::{AsyncRead, AsyncWrite}; use sasl::common::Credentials; @@ -29,19 +30,11 @@ enum ClientAuthState { impl ClientAuth { pub fn new(stream: XMPPStream, creds: Credentials) -> Result { - let mechs: Vec<(Box, XMPPMechanism)> = vec![ - (Box::new(Scram::::from_credentials(creds.clone()).unwrap()), - XMPPMechanism::ScramSha256 - ), - (Box::new(Scram::::from_credentials(creds.clone()).unwrap()), - XMPPMechanism::ScramSha1 - ), - (Box::new(Plain::from_credentials(creds).unwrap()), - XMPPMechanism::Plain - ), - (Box::new(Anonymous::new()), - XMPPMechanism::Anonymous - ), + let mechs: Vec> = vec![ + Box::new(Scram::::from_credentials(creds.clone()).unwrap()), + Box::new(Scram::::from_credentials(creds.clone()).unwrap()), + Box::new(Plain::from_credentials(creds).unwrap()), + Box::new(Anonymous::new()), ]; let mech_names: Vec = @@ -56,7 +49,7 @@ impl ClientAuth { }; println!("SASL mechanisms offered: {:?}", mech_names); - for (mut mech, mechanism) in mechs { + for mut mech in mechs { let name = mech.name().to_owned(); if mech_names.iter().any(|name1| *name1 == name) { println!("SASL mechanism selected: {:?}", name); @@ -65,6 +58,8 @@ impl ClientAuth { state: ClientAuthState::Invalid, mechanism: mech, }; + let mechanism = XMPPMechanism::from_str(&name) + .map_err(|e| format!("{:?}", e))?; this.send( stream, Auth { @@ -119,7 +114,7 @@ impl Future for ClientAuth { self.state = ClientAuthState::Start(start); self.poll() } else if let Ok(failure) = Failure::try_from(stanza) { - let e = failure.data; + let e = format!("{:?}", failure.defined_condition); Err(e) } else { Ok(Async::NotReady)