diff options
Diffstat (limited to '')
-rw-r--r-- | jabber/src/client.rs (renamed from src/client.rs) | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/src/client.rs b/jabber/src/client.rs index e94008d..c8b0b73 100644 --- a/src/client.rs +++ b/jabber/src/client.rs @@ -1,16 +1,16 @@ use std::{pin::pin, sync::Arc, task::Poll}; use futures::{Sink, Stream, StreamExt}; +use jid::ParseError; use rsasl::config::SASLConfig; +use stanza::{ + client::Stanza, + sasl::Mechanisms, + stream::{Feature, Features}, +}; use crate::{ connection::{Tls, Unencrypted}, - jid::ParseError, - stanza::{ - client::Stanza, - sasl::Mechanisms, - stream::{Feature, Features}, - }, Connection, Error, JabberStream, Result, JID, }; @@ -113,7 +113,7 @@ impl ConnectionState { )) } Connecting::InsecureGotFeatures((features, jabber_stream)) => { - match features.negotiate()? { + match features.negotiate().ok_or(Error::Negotiation)? { Feature::StartTls(_start_tls) => { self = ConnectionState::Connecting(Connecting::StartTls(jabber_stream)) @@ -138,7 +138,7 @@ impl ConnectionState { )) } Connecting::GotFeatures((features, jabber_stream)) => { - match features.negotiate()? { + match features.negotiate().ok_or(Error::Negotiation)? { Feature::StartTls(_start_tls) => return Err(Error::AlreadyTls), Feature::Sasl(mechanisms) => { self = ConnectionState::Connecting(Connecting::Sasl( @@ -190,35 +190,6 @@ impl Connecting { } } -impl Features { - pub fn negotiate(self) -> Result<Feature> { - if let Some(Feature::StartTls(s)) = self - .features - .iter() - .find(|feature| matches!(feature, Feature::StartTls(_s))) - { - // TODO: avoid clone - return Ok(Feature::StartTls(s.clone())); - } else if let Some(Feature::Sasl(mechanisms)) = self - .features - .iter() - .find(|feature| matches!(feature, Feature::Sasl(_))) - { - // TODO: avoid clone - return Ok(Feature::Sasl(mechanisms.clone())); - } else if let Some(Feature::Bind) = self - .features - .into_iter() - .find(|feature| matches!(feature, Feature::Bind)) - { - Ok(Feature::Bind) - } else { - // TODO: better error - return Err(Error::Negotiation); - } - } -} - pub enum InsecureConnecting { Disconnected, ConnectionEstablished(Connection), |