forked from lavina/lavina
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
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 crate::prelude::*;
|
|
|
|
pub static XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls";
|
|
|
|
pub struct StartTLS;
|
|
impl StartTLS {
|
|
pub async fn parse(
|
|
reader: &mut NsReader<impl AsyncBufRead + Unpin>,
|
|
buf: &mut Vec<u8>,
|
|
) -> Result<StartTLS> {
|
|
let incoming = skip_text!(reader, buf);
|
|
if let Event::Empty(ref e) = incoming {
|
|
if e.name().0 == b"starttls" {
|
|
return Ok(StartTLS);
|
|
}
|
|
}
|
|
Err(ffail!("XML tag starttls expected, received: {incoming:?}"))
|
|
}
|
|
}
|
|
|
|
pub struct ProceedTLS;
|
|
impl ProceedTLS {
|
|
pub async fn write_xml(&self, writer: &mut Writer<impl AsyncWrite + Unpin>) -> 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(())
|
|
}
|
|
}
|