use xso::{AsXml, FromXml};
use crate::ns;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::TLS, name = "starttls")]
pub struct Request;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::TLS, name = "proceed")]
pub struct Proceed;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::TLS, name = "starttls")]
pub struct StartTls {
#[xml(child(default))]
pub required: Option<RequiredStartTls>,
}
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::TLS, name = "required")]
pub struct RequiredStartTls;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml()]
pub enum Nonza {
#[xml(transparent)]
Request(Request),
#[xml(transparent)]
Proceed(Proceed),
}
#[cfg(test)]
mod tests {
use super::*;
use minidom::Element;
#[test]
fn test_size() {
assert_size!(Request, 0);
assert_size!(Proceed, 0);
assert_size!(StartTls, 1);
assert_size!(RequiredStartTls, 0);
assert_size!(Nonza, 1);
}
#[test]
fn test_parsers() {
let elem: Element = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
.parse()
.unwrap();
let request = Request::try_from(elem.clone()).unwrap();
let elem2 = Element::from(request);
assert_eq!(elem, elem2);
let elem: Element = "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
.parse()
.unwrap();
let proceed = Proceed::try_from(elem.clone()).unwrap();
let elem2 = Element::from(proceed);
assert_eq!(elem, elem2);
let elem: Element = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
.parse()
.unwrap();
let starttls = StartTls::try_from(elem.clone()).unwrap();
assert_eq!(starttls.required, None);
let elem2 = Element::from(starttls);
assert_eq!(elem, elem2);
let elem: Element =
"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>"
.parse()
.unwrap();
let starttls = StartTls::try_from(elem.clone()).unwrap();
assert_eq!(starttls.required, Some(RequiredStartTls));
let elem2 = Element::from(starttls);
assert_eq!(elem, elem2);
let elem: Element = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
.parse()
.unwrap();
let nonza = Nonza::try_from(elem.clone()).unwrap();
assert_eq!(nonza, Nonza::Request(Request));
let elem2 = Element::from(nonza);
assert_eq!(elem, elem2);
let elem: Element = "<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
.parse()
.unwrap();
let nonza = Nonza::try_from(elem.clone()).unwrap();
assert_eq!(nonza, Nonza::Proceed(Proceed));
let elem2 = Element::from(nonza);
assert_eq!(elem, elem2);
}
}