caps: Use the new helper macros to simplify parsing.

This commit is contained in:
Emmanuel Gil Peyrot 2017-10-10 18:04:27 +01:00
parent 66fb8fea74
commit a2b6033336

View file

@ -33,16 +33,12 @@ impl TryFrom<Element> for Caps {
type Err = Error; type Err = Error;
fn try_from(elem: Element) -> Result<Caps, Error> { fn try_from(elem: Element) -> Result<Caps, Error> {
if !elem.is("c", ns::CAPS) { check_self!(elem, "c", ns::CAPS, "caps");
return Err(Error::ParseError("This is not a caps element.")); check_no_children!(elem, "caps");
} check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]);
for _ in elem.children() {
return Err(Error::ParseError("Unknown child in caps element."));
}
let hash = get_attr!(elem, "hash", required);
let ver: String = get_attr!(elem, "ver", required); let ver: String = get_attr!(elem, "ver", required);
let hash = Hash { let hash = Hash {
algo: hash, algo: get_attr!(elem, "hash", required),
hash: base64::decode(&ver)?, hash: base64::decode(&ver)?,
}; };
Ok(Caps { Ok(Caps {