client::auth: update xmpp-parsers usage
This commit is contained in:
parent
b82237f422
commit
a3db744e46
2 changed files with 11 additions and 16 deletions
|
@ -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"
|
||||
|
|
|
@ -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<S: AsyncWrite> {
|
|||
|
||||
impl<S: AsyncWrite> ClientAuth<S> {
|
||||
pub fn new(stream: XMPPStream<S>, creds: Credentials) -> Result<Self, String> {
|
||||
let mechs: Vec<(Box<Mechanism>, XMPPMechanism)> = vec![
|
||||
(Box::new(Scram::<Sha256>::from_credentials(creds.clone()).unwrap()),
|
||||
XMPPMechanism::ScramSha256
|
||||
),
|
||||
(Box::new(Scram::<Sha1>::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<Box<Mechanism>> = vec![
|
||||
Box::new(Scram::<Sha256>::from_credentials(creds.clone()).unwrap()),
|
||||
Box::new(Scram::<Sha1>::from_credentials(creds.clone()).unwrap()),
|
||||
Box::new(Plain::from_credentials(creds).unwrap()),
|
||||
Box::new(Anonymous::new()),
|
||||
];
|
||||
|
||||
let mech_names: Vec<String> =
|
||||
|
@ -56,7 +49,7 @@ impl<S: AsyncWrite> ClientAuth<S> {
|
|||
};
|
||||
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<S: AsyncWrite> ClientAuth<S> {
|
|||
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<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue