From f92eb10d0d433f7b163672353f4d7ceb32bc8a8c Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Mon, 20 Jan 2025 17:09:51 +0100 Subject: [PATCH] Minor formatting fixes. --- src/rrdp.rs | 337 +++++++++++++++++++++++++++------------------------- 1 file changed, 178 insertions(+), 159 deletions(-) diff --git a/src/rrdp.rs b/src/rrdp.rs index 4e4c603..eac98d0 100644 --- a/src/rrdp.rs +++ b/src/rrdp.rs @@ -230,99 +230,104 @@ impl NotificationFile { return Err(XmlError::Malformed) } - element.attributes(|name, value| { - match name { - b"version" => { - if value.ascii_into::()? != 1 { - return Err(XmlError::Malformed) - } - Ok(()) - } - b"session_id" => { - session_id = Some(value.ascii_into()?); - Ok(()) - } - b"serial" => { - serial = Some(value.ascii_into()?); - Ok(()) - } - _ => Err(XmlError::Malformed) - } - }) - }, MAX_HEADER_SIZE)?; - - let mut snapshot = None; - let mut deltas = Ok(vec![]); - - while let Some(mut content) = outer.take_opt_element_with_limit(&mut reader, - |element| { - match element.name() { - SNAPSHOT => { - if snapshot.is_some() { - return Err(XmlError::Malformed) - } - let mut uri = None; - let mut hash = None; - element.attributes(|name, value| match name { - b"uri" => { - uri = Some(value.ascii_into()?); - Ok(()) - } - b"hash" => { - hash = Some(value.ascii_into()?); + element.attributes(|name, value| { + match name { + b"version" => { + if value.ascii_into::()? != 1 { + return Err(XmlError::Malformed) + } Ok(()) } - _ => Err(XmlError::Malformed) - })?; - match (uri, hash) { - (Some(uri), Some(hash)) => { - snapshot = Some(UriAndHash::new(uri, hash)); + b"session_id" => { + session_id = Some(value.ascii_into()?); Ok(()) } - _ => Err(XmlError::Malformed) - } - } - DELTA => { - let mut serial = None; - let mut uri = None; - let mut hash = None; - element.attributes(|name, value| match name { b"serial" => { serial = Some(value.ascii_into()?); Ok(()) } - b"uri" => { - uri = Some(value.ascii_into()?); - Ok(()) - } - b"hash" => { - hash = Some(value.ascii_into()?); - Ok(()) - } _ => Err(XmlError::Malformed) - })?; - let (serial, uri, hash) = match (serial, uri, hash) { - (Some(serial), Some(uri), Some(hash)) => { - (serial, uri, hash) + } + }) + }, + MAX_HEADER_SIZE + )?; + + let mut snapshot = None; + let mut deltas = Ok(vec![]); + + while let Some(mut content) = outer.take_opt_element_with_limit( + &mut reader, + |element| { + match element.name() { + SNAPSHOT => { + if snapshot.is_some() { + return Err(XmlError::Malformed) } - _ => return Err(XmlError::Malformed) - }; - if let Some(limit) = delta_limit { - let len = deltas.as_ref().map(|deltas| { - deltas.len() - }).unwrap_or(0); - if len >= limit { - deltas = Err(DeltaListError::Oversized); + let mut uri = None; + let mut hash = None; + element.attributes(|name, value| match name { + b"uri" => { + uri = Some(value.ascii_into()?); + Ok(()) + } + b"hash" => { + hash = Some(value.ascii_into()?); + Ok(()) + } + _ => Err(XmlError::Malformed) + })?; + match (uri, hash) { + (Some(uri), Some(hash)) => { + snapshot = Some(UriAndHash::new(uri, hash)); + Ok(()) + } + _ => Err(XmlError::Malformed) } } - if let Ok(ref mut deltas) = deltas { - deltas.push(DeltaInfo::new(serial, uri, hash)) + DELTA => { + let mut serial = None; + let mut uri = None; + let mut hash = None; + element.attributes(|name, value| match name { + b"serial" => { + serial = Some(value.ascii_into()?); + Ok(()) + } + b"uri" => { + uri = Some(value.ascii_into()?); + Ok(()) + } + b"hash" => { + hash = Some(value.ascii_into()?); + Ok(()) + } + _ => Err(XmlError::Malformed) + })?; + let (serial, uri, hash) = match (serial, uri, hash) { + (Some(serial), Some(uri), Some(hash)) => { + (serial, uri, hash) + } + _ => return Err(XmlError::Malformed) + }; + if let Some(limit) = delta_limit { + let len = deltas.as_ref().map(|deltas| { + deltas.len() + }).unwrap_or(0); + if len >= limit { + deltas = Err(DeltaListError::Oversized); + } + } + if let Ok(ref mut deltas) = deltas { + deltas.push(DeltaInfo::new(serial, uri, hash)) + } + Ok(()) } - Ok(()) + _ => Err(XmlError::Malformed) } - _ => Err(XmlError::Malformed) - } - }, MAX_HEADER_SIZE)? { + }, + MAX_HEADER_SIZE + )? { content.take_end(&mut reader)?; } @@ -780,33 +785,36 @@ pub trait ProcessSnapshot { let mut session_id = None; let mut serial = None; - let mut outer = reader.start_with_limit(|element| { - if element.name() != SNAPSHOT { - info!("Bad outer: not snapshot, but {:?}", element.name()); - return Err(XmlError::Malformed) - } - element.attributes(|name, value| match name { - b"version" => { - if value.ascii_into::()? != 1 { - info!("Bad version"); - return Err(XmlError::Malformed) - } - Ok(()) - } - b"session_id" => { - session_id = Some(value.ascii_into()?); - Ok(()) - } - b"serial" => { - serial = Some(value.ascii_into()?); - Ok(()) - } - _ => { - info!("Bad attribute on snapshot."); - Err(XmlError::Malformed) + let mut outer = reader.start_with_limit( + |element| { + if element.name() != SNAPSHOT { + info!("Bad outer: not snapshot, but {:?}", element.name()); + return Err(XmlError::Malformed) } - }) - }, MAX_HEADER_SIZE).map_err(Into::into)?; + element.attributes(|name, value| match name { + b"version" => { + if value.ascii_into::()? != 1 { + info!("Bad version"); + return Err(XmlError::Malformed) + } + Ok(()) + } + b"session_id" => { + session_id = Some(value.ascii_into()?); + Ok(()) + } + b"serial" => { + serial = Some(value.ascii_into()?); + Ok(()) + } + _ => { + info!("Bad attribute on snapshot."); + Err(XmlError::Malformed) + } + }) + }, + MAX_HEADER_SIZE, + ).map_err(Into::into)?; match (session_id, serial) { (Some(session_id), Some(serial)) => { @@ -820,22 +828,26 @@ pub trait ProcessSnapshot { loop { let mut uri = None; - let inner = outer.take_opt_element_with_limit(&mut reader, |element| { - if element.name() != PUBLISH { - info!("Bad inner: not publish"); - return Err(ProcessError::malformed()) - } - element.attributes(|name, value| match name { - b"uri" => { - uri = Some(value.ascii_into()?); - Ok(()) - } - _ => { - info!("Bad attribute on publish."); - Err(ProcessError::malformed()) + let inner = outer.take_opt_element_with_limit( + &mut reader, + |element| { + if element.name() != PUBLISH { + info!("Bad inner: not publish"); + return Err(ProcessError::malformed()) } - }) - },MAX_FILE_SIZE)?; + element.attributes(|name, value| match name { + b"uri" => { + uri = Some(value.ascii_into()?); + Ok(()) + } + _ => { + info!("Bad attribute on publish."); + Err(ProcessError::malformed()) + } + }) + }, + MAX_FILE_SIZE, + )?; let mut inner = match inner { Some(inner) => inner, None => break @@ -1090,28 +1102,31 @@ pub trait ProcessDelta { let mut session_id = None; let mut serial = None; - let mut outer = reader.start_with_limit(|element| { - if element.name() != DELTA { - return Err(ProcessError::malformed()) - } - element.attributes(|name, value| match name { - b"version" => { - if value.ascii_into::()? != 1 { - return Err(ProcessError::malformed()) - } - Ok(()) - } - b"session_id" => { - session_id = Some(value.ascii_into()?); - Ok(()) - } - b"serial" => { - serial = Some(value.ascii_into()?); - Ok(()) + let mut outer = reader.start_with_limit( + |element| { + if element.name() != DELTA { + return Err(ProcessError::malformed()) } - _ => Err(ProcessError::malformed()) - }) - }, MAX_HEADER_SIZE)?; + element.attributes(|name, value| match name { + b"version" => { + if value.ascii_into::()? != 1 { + return Err(ProcessError::malformed()) + } + Ok(()) + } + b"session_id" => { + session_id = Some(value.ascii_into()?); + Ok(()) + } + b"serial" => { + serial = Some(value.ascii_into()?); + Ok(()) + } + _ => Err(ProcessError::malformed()) + }) + }, + MAX_HEADER_SIZE, + )?; match (session_id, serial) { (Some(session_id), Some(serial)) => { @@ -1124,24 +1139,28 @@ pub trait ProcessDelta { let mut action = None; let mut uri = None; let mut hash = None; - let inner = outer.take_opt_element_with_limit(&mut reader, |element| { - match element.name() { - PUBLISH => action = Some(Action::Publish), - WITHDRAW => action = Some(Action::Withdraw), - _ => return Err(ProcessError::malformed()), - }; - element.attributes(|name, value| match name { - b"uri" => { - uri = Some(value.ascii_into()?); - Ok(()) - } - b"hash" => { - hash = Some(value.ascii_into()?); - Ok(()) - } - _ => Err(ProcessError::malformed()) - }) - }, MAX_FILE_SIZE)?; + let inner = outer.take_opt_element_with_limit( + &mut reader, + |element| { + match element.name() { + PUBLISH => action = Some(Action::Publish), + WITHDRAW => action = Some(Action::Withdraw), + _ => return Err(ProcessError::malformed()), + }; + element.attributes(|name, value| match name { + b"uri" => { + uri = Some(value.ascii_into()?); + Ok(()) + } + b"hash" => { + hash = Some(value.ascii_into()?); + Ok(()) + } + _ => Err(ProcessError::malformed()) + }) + }, + MAX_FILE_SIZE, + )?; let mut inner = match inner { Some(inner) => inner, None => break