blob: d545923782366e6e31b8134abd9cfd40c1c1d77d (
plain) (
tree)
|
|
pub mod encrypted;
pub mod unencrypted;
// use async_trait::async_trait;
use crate::stanza::stream::StreamFeature;
use crate::JabberError;
use crate::Result;
pub enum JabberClientType<'j> {
Encrypted(encrypted::JabberClient<'j>),
Unencrypted(unencrypted::JabberClient<'j>),
}
impl<'j> JabberClientType<'j> {
pub async fn ensure_tls(self) -> Result<encrypted::JabberClient<'j>> {
match self {
Self::Encrypted(c) => Ok(c),
Self::Unencrypted(mut c) => {
if let Some(features) = c.get_features().await? {
if features.contains(&StreamFeature::StartTls) {
Ok(c.starttls().await?)
} else {
Err(JabberError::StartTlsUnavailable)
}
} else {
Err(JabberError::NoFeatures)
}
}
}
}
}
// TODO: jabber client trait over both client types
// #[async_trait]
// pub trait JabberTrait {
// async fn start_stream(&mut self) -> Result<()>;
// async fn get_features(&self) -> Result<Vec<StreamFeatures>>;
// }
|