luz/src/client/mod.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

2023-06-19 19:23:54 +01:00
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 {
2023-07-11 21:28:42 +01:00
Self::Encrypted(c) => Ok(c),
2023-06-19 19:23:54 +01:00
Self::Unencrypted(mut c) => {
2023-07-11 21:28:42 +01:00
if let Some(features) = c.get_features().await? {
if features.contains(&StreamFeature::StartTls) {
Ok(c.starttls().await?)
} else {
Err(JabberError::StartTlsUnavailable)
}
2023-06-19 19:23:54 +01:00
} else {
2023-07-11 21:28:42 +01:00
Err(JabberError::NoFeatures)
2023-06-19 19:23:54 +01:00
}
}
}
}
}
// 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>>;
// }