eme: Add a serialise function.
This commit is contained in:
parent
c6036194b1
commit
cebccb363f
1 changed files with 16 additions and 0 deletions
16
src/eme.rs
16
src/eme.rs
|
@ -25,6 +25,14 @@ pub fn parse_explicit_message_encryption(root: &Element) -> Result<ExplicitMessa
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn serialise(eme: &ExplicitMessageEncryption) -> Element {
|
||||||
|
Element::builder("encryption")
|
||||||
|
.ns(ns::EME)
|
||||||
|
.attr("namespace", eme.namespace.clone())
|
||||||
|
.attr("name", eme.name.clone())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
|
@ -65,4 +73,12 @@ mod tests {
|
||||||
};
|
};
|
||||||
assert_eq!(message, "Unknown child in encryption element.");
|
assert_eq!(message, "Unknown child in encryption element.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serialise() {
|
||||||
|
let elem: Element = "<encryption xmlns='urn:xmpp:eme:0' namespace='coucou'/>".parse().unwrap();
|
||||||
|
let eme = eme::ExplicitMessageEncryption { namespace: String::from("coucou"), name: None };
|
||||||
|
let elem2 = eme::serialise(&eme);
|
||||||
|
assert_eq!(elem, elem2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue