eme: Use the new helper macros to simplify parsing.
This commit is contained in:
parent
ee243c4720
commit
a2c7529668
1 changed files with 4 additions and 7 deletions
11
src/eme.rs
11
src/eme.rs
|
|
@ -27,12 +27,9 @@ impl TryFrom<Element> for ExplicitMessageEncryption {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<ExplicitMessageEncryption, Error> {
|
fn try_from(elem: Element) -> Result<ExplicitMessageEncryption, Error> {
|
||||||
if !elem.is("encryption", ns::EME) {
|
check_self!(elem, "encryption", ns::EME);
|
||||||
return Err(Error::ParseError("This is not an encryption element."));
|
check_no_children!(elem, "encryption");
|
||||||
}
|
check_no_unknown_attributes!(elem, "encryption", ["namespace", "name"]);
|
||||||
for _ in elem.children() {
|
|
||||||
return Err(Error::ParseError("Unknown child in encryption element."));
|
|
||||||
}
|
|
||||||
Ok(ExplicitMessageEncryption {
|
Ok(ExplicitMessageEncryption {
|
||||||
namespace: get_attr!(elem, "namespace", required),
|
namespace: get_attr!(elem, "namespace", required),
|
||||||
name: get_attr!(elem, "name", optional),
|
name: get_attr!(elem, "name", optional),
|
||||||
|
|
@ -75,7 +72,7 @@ mod tests {
|
||||||
Error::ParseError(string) => string,
|
Error::ParseError(string) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "This is not an encryption element.");
|
assert_eq!(message, "This is not a encryption element.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue