use quick_xml::events::attributes::Attribute; use quick_xml::events::{BytesStart, Event}; use quick_xml::name::QName; use quick_xml::{NsReader, Writer}; use tokio::io::{AsyncBufRead, AsyncWrite}; use super::skip_text; use anyhow::{anyhow, Result}; pub static XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls"; pub struct StartTLS; impl StartTLS { pub async fn parse( reader: &mut NsReader, buf: &mut Vec, ) -> Result { let incoming = skip_text!(reader, buf); if let Event::Empty(ref e) = incoming { if e.name().0 == b"starttls" { return Ok(StartTLS); } } Err(anyhow!("XML tag starttls expected, received: {incoming:?}")) } } pub struct ProceedTLS; impl ProceedTLS { pub async fn write_xml(&self, writer: &mut Writer) -> Result<()> { let mut event = BytesStart::new("proceed"); let attributes = [Attribute { key: QName(b"xmlns"), value: XMLNS.as_bytes().into(), }]; event.extend_attributes(attributes.into_iter()); writer.write_event_async(Event::Empty(event)).await?; Ok(()) } }