aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/starttls.rs
blob: b0e0f0f354e0c78f12925cdca2ce3e3087f33a08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use peanuts::{
    element::{FromElement, IntoElement},
    Element,
};

pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-tls";

#[derive(Debug, Clone)]
pub struct StartTls {
    pub required: bool,
}

impl IntoElement for StartTls {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        let mut builder = Element::builder("starttls", Some(XMLNS));

        if self.required {
            builder = builder.push_child(Required)
        }

        builder
    }
}

impl FromElement for StartTls {
    fn from_element(
        mut element: peanuts::Element,
    ) -> std::result::Result<StartTls, peanuts::DeserializeError> {
        element.check_name("starttls")?;
        element.check_namespace(XMLNS)?;

        let mut required = false;
        if let Some(_) = element.child_opt::<Required>()? {
            required = true;
        }

        Ok(StartTls { required })
    }
}

#[derive(Debug)]
pub struct Required;

impl FromElement for Required {
    fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
        element.check_name("required")?;
        element.check_namespace(XMLNS)?;

        Ok(Required)
    }
}

impl IntoElement for Required {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        Element::builder("required", Some(XMLNS))
    }
}

#[derive(Debug)]
pub struct Proceed;

impl IntoElement for Proceed {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        Element::builder("proceed", Some(XMLNS))
    }
}

impl FromElement for Proceed {
    fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
        element.check_name("proceed")?;
        element.check_namespace(XMLNS)?;

        Ok(Proceed)
    }
}

pub struct Failure;

impl IntoElement for Failure {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        Element::builder("failure", Some(XMLNS))
    }
}

impl FromElement for Failure {
    fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
        element.check_name("failure")?;
        element.check_namespace(XMLNS)?;

        Ok(Failure)
    }
}