diff --git a/src/crypto/keys.rs b/src/crypto/keys.rs index e32d1e8..0224173 100644 --- a/src/crypto/keys.rs +++ b/src/crypto/keys.rs @@ -609,7 +609,7 @@ impl<'de> serde::Deserialize<'de> for KeyIdentifier { ) -> Result { struct KeyIdentifierVisitor; - impl<'de> serde::de::Visitor<'de> for KeyIdentifierVisitor { + impl serde::de::Visitor<'_> for KeyIdentifierVisitor { type Value = KeyIdentifier; fn expecting( diff --git a/src/repository/aspa.rs b/src/repository/aspa.rs index d676311..c170cc8 100644 --- a/src/repository/aspa.rs +++ b/src/repository/aspa.rs @@ -267,7 +267,7 @@ impl ProviderAsSet { #[derive(Clone, Debug)] pub struct ProviderAsIter<'a>(SliceSource<'a>); -impl<'a> Iterator for ProviderAsIter<'a> { +impl Iterator for ProviderAsIter<'_> { type Item = Asn; fn next(&mut self) -> Option { diff --git a/src/repository/resources/ipres.rs b/src/repository/resources/ipres.rs index 5821251..2b5a701 100644 --- a/src/repository/resources/ipres.rs +++ b/src/repository/resources/ipres.rs @@ -269,7 +269,7 @@ impl<'a> IpBlocksForFamily<'a> { } } -impl<'a> fmt::Display for IpBlocksForFamily<'a> { +impl fmt::Display for IpBlocksForFamily<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut blocks_iter = self.blocks.iter(); diff --git a/src/repository/roa.rs b/src/repository/roa.rs index 0fcfc8f..a012185 100644 --- a/src/repository/roa.rs +++ b/src/repository/roa.rs @@ -312,7 +312,7 @@ impl RoaIpAddresses { #[derive(Clone, Debug)] pub struct RoaIpAddressIter<'a>(SliceSource<'a>); -impl<'a> Iterator for RoaIpAddressIter<'a> { +impl Iterator for RoaIpAddressIter<'_> { type Item = RoaIpAddress; fn next(&mut self) -> Option { diff --git a/src/repository/x509.rs b/src/repository/x509.rs index 897763c..cbfc1d2 100644 --- a/src/repository/x509.rs +++ b/src/repository/x509.rs @@ -561,7 +561,7 @@ impl<'de> serde::Deserialize<'de> for Serial { ) -> Result { struct SerialVisitor; - impl<'de> serde::de::Visitor<'de> for SerialVisitor { + impl serde::de::Visitor<'_> for SerialVisitor { type Value = Serial; fn expecting( @@ -665,7 +665,7 @@ impl Eq for SignedData {} #[derive(Clone, Copy, Debug)] pub struct SignatureValueContent<'a, Alg>(&'a SignedData); -impl<'a, Alg> PrimitiveContent for SignatureValueContent<'a, Alg> { +impl PrimitiveContent for SignatureValueContent<'_, Alg> { const TAG: Tag = Tag::BIT_STRING; fn encoded_len(&self, _: Mode) -> usize { diff --git a/src/resources/addr.rs b/src/resources/addr.rs index 8ebd71b..e1e2a03 100644 --- a/src/resources/addr.rs +++ b/src/resources/addr.rs @@ -472,7 +472,7 @@ impl<'de> serde::Deserialize<'de> for Prefix { ) -> Result { struct Visitor; - impl<'de> serde::de::Visitor<'de> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = Prefix; fn expecting( diff --git a/src/resources/asn.rs b/src/resources/asn.rs index 54bfee9..52c83d9 100644 --- a/src/resources/asn.rs +++ b/src/resources/asn.rs @@ -169,7 +169,7 @@ impl Asn { ) -> Result { struct Visitor; - impl<'de> serde::de::Visitor<'de> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = Asn; fn expecting( @@ -198,7 +198,7 @@ impl Asn { ) -> Result { struct Visitor; - impl<'de> serde::de::Visitor<'de> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = Asn; fn expecting( @@ -390,7 +390,7 @@ pub struct SmallSetDifference<'a> { right: Peekable>, } -impl<'a> Iterator for SmallSetDifference<'a> { +impl Iterator for SmallSetDifference<'_> { type Item = Asn; fn next(&mut self) -> Option { @@ -423,7 +423,7 @@ pub struct SmallSetSymmetricDifference<'a> { right: Peekable>, } -impl<'a> Iterator for SmallSetSymmetricDifference<'a> { +impl Iterator for SmallSetSymmetricDifference<'_> { type Item = Asn; fn next(&mut self) -> Option { @@ -455,7 +455,7 @@ pub struct SmallSetIntersection<'a> { right: Peekable>, } -impl<'a> Iterator for SmallSetIntersection<'a> { +impl Iterator for SmallSetIntersection<'_> { type Item = Asn; fn next(&mut self) -> Option { @@ -489,7 +489,7 @@ pub struct SmallSetUnion<'a> { right: Peekable>, } -impl<'a> Iterator for SmallSetUnion<'a> { +impl Iterator for SmallSetUnion<'_> { type Item = Asn; fn next(&mut self) -> Option { diff --git a/src/rrdp.rs b/src/rrdp.rs index 845f7a6..90f9f75 100644 --- a/src/rrdp.rs +++ b/src/rrdp.rs @@ -569,7 +569,7 @@ impl DeltaElement { } } -///--- From +//--- From impl From for DeltaElement { fn from(src: PublishElement) -> Self { @@ -1434,7 +1434,7 @@ pub struct ObjectReader<'a>( base64::XmlDecoderReader<'a> ); -impl<'a> ObjectReader<'a> { +impl ObjectReader<'_> { /// Processes an element with optional XML PCDATA as object content. /// /// An object reader is created and passed to the closure `op` for @@ -1481,7 +1481,7 @@ impl<'a> ObjectReader<'a> { } } -impl<'a> io::Read for ObjectReader<'a> { +impl io::Read for ObjectReader<'_> { fn read(&mut self, buf: &mut [u8]) -> Result { self.0.read(buf) } diff --git a/src/rtr/payload.rs b/src/rtr/payload.rs index 30766d1..772e2ec 100644 --- a/src/rtr/payload.rs +++ b/src/rtr/payload.rs @@ -287,7 +287,7 @@ pub enum PayloadRef<'a> { //--- From -impl<'a> From for PayloadRef<'a> { +impl From for PayloadRef<'_> { fn from(src: RouteOrigin) -> Self { PayloadRef::Origin(src) } diff --git a/src/rtr/pdu.rs b/src/rtr/pdu.rs index 6ae63cd..0d38bec 100644 --- a/src/rtr/pdu.rs +++ b/src/rtr/pdu.rs @@ -787,11 +787,6 @@ pub struct Aspa { #[repr(packed)] struct AspaFixed { header: Header, - flags: u8, - afi_flags: u8, - - #[allow(dead_code)] - provider_count: u16, customer: u32, } @@ -818,10 +813,11 @@ impl Aspa { ).expect("ASPA RTR PDU size overflow"); Aspa { fixed: AspaFixed { - header: Header::new(version, Self::PDU, 0, len), - flags, - afi_flags: 0, - provider_count: providers.asn_count().to_be(), + header: Header::new( + version, Self::PDU, + (flags as u16) << 8, + len + ), customer: customer.into_u32().to_be(), }, providers @@ -848,7 +844,7 @@ impl Aspa { /// The only flag currently used is the least significant bit that is /// 1 for an announcement and 0 for a withdrawal. pub fn flags(&self) -> u8 { - self.fixed.flags + (self.fixed.header.session >> 8) as u8 } /// Returns the customer ASN. @@ -899,7 +895,15 @@ impl Aspa { let provider_len = match header.pdu_len()?.checked_sub(mem::size_of::()) { - Some(len) => len, + Some(len) => { + if len % 4 != 0 { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "invalid length for ASPA PDU" + )) + } + len + } None => { return Err(io::Error::new( io::ErrorKind::InvalidData, @@ -909,16 +913,6 @@ impl Aspa { }; let mut fixed = AspaFixed { header, .. Default::default() }; sock.read_exact(&mut fixed.as_mut()[Header::LEN..]).await?; - if provider_len - != usize::from( - u16::from_be(fixed.provider_count) - ) * mem::size_of::() - { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "invalid length for ASPA PDU" - )) - } let providers = ProviderAsns::read(sock, provider_len).await?; Ok(Aspa { fixed, providers }) } @@ -1831,9 +1825,9 @@ mod test { ]).unwrap(), ), [ - 2, 11, 0, 0, 0, 0, 0, 24, - 1, 0, 0, 2, 0, 1, 0, 15, - 0, 1, 0, 13, 0, 1, 0, 14, + 2, 11, 1, 0, 0, 0, 0, 20, + 0, 1, 0, 15, 0, 1, 0, 13, + 0, 1, 0, 14, ] ); } diff --git a/src/slurm.rs b/src/slurm.rs index 5bcfa02..fe28d57 100644 --- a/src/slurm.rs +++ b/src/slurm.rs @@ -660,7 +660,7 @@ impl<'de> Deserialize<'de> for Base64KeyInfo { ) -> Result { struct Visitor; - impl<'de> serde::de::Visitor<'de> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = Base64KeyInfo; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -736,7 +736,7 @@ mod serde_key_identifier { ) -> Result { struct Visitor; - impl<'de> serde::de::Visitor<'de> for Visitor { + impl serde::de::Visitor<'_> for Visitor { type Value = KeyIdentifier; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/uri.rs b/src/uri.rs index 05a3644..b282273 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -481,7 +481,7 @@ impl<'de> Deserialize<'de> for Rsync { //--- PrimitiveContent #[cfg(feature = "repository")] -impl<'a> encode::PrimitiveContent for &'a Rsync { +impl encode::PrimitiveContent for &'_ Rsync { const TAG: Tag = Tag::IA5_STRING; fn encoded_len(&self, _: Mode) -> usize { @@ -779,7 +779,7 @@ impl<'de> Deserialize<'de> for Https { //--- PrimitiveContent #[cfg(feature = "repository")] -impl<'a> encode::PrimitiveContent for &'a Https { +impl encode::PrimitiveContent for &'_ Https { const TAG: Tag = Tag::IA5_STRING; fn encoded_len(&self, _: Mode) -> usize { @@ -871,7 +871,7 @@ impl Default for UriVisitor { } #[cfg(feature = "serde")] -impl<'de, V> serde::de::Visitor<'de> for UriVisitor +impl serde::de::Visitor<'_> for UriVisitor where V: FromStr + TryFrom, ::Err: fmt::Display, @@ -980,7 +980,7 @@ mod arbitrary { } } - impl<'a> Arbitrary<'a> for super::Https { + impl Arbitrary<'_> for super::Https { fn arbitrary(u: &mut Unstructured) -> arbitrary::Result { let mut res = String::from("https://"); append_host(&mut res, u)?; diff --git a/src/util/base64.rs b/src/util/base64.rs index 87367e4..9b77476 100644 --- a/src/util/base64.rs +++ b/src/util/base64.rs @@ -166,7 +166,7 @@ impl<'a> SkipWhitespace<'a> { } } -impl<'a> io::Read for SkipWhitespace<'a> { +impl io::Read for SkipWhitespace<'_> { fn read(&mut self, mut buf: &mut[u8]) -> Result { let mut res = 0; @@ -205,7 +205,7 @@ pub struct XmlDecoderReader<'a>( > ); -impl<'a> io::Read for XmlDecoderReader<'a> { +impl io::Read for XmlDecoderReader<'_> { fn read(&mut self, buf: &mut [u8]) -> Result { self.0.read(buf) } diff --git a/src/xml/decode.rs b/src/xml/decode.rs index 3ab1619..6e2bdf9 100644 --- a/src/xml/decode.rs +++ b/src/xml/decode.rs @@ -371,7 +371,7 @@ impl<'n, 'l> Name<'n, 'l> { } } -impl<'n, 'l> fmt::Debug for Name<'n, 'l> { +impl fmt::Debug for Name<'_, '_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Name(")?; if let Some(ns) = self.namespace { @@ -381,13 +381,13 @@ impl<'n, 'l> fmt::Debug for Name<'n, 'l> { } } -impl<'n, 'l> From<&'l [u8]> for Name<'n, 'l> { +impl<'l> From<&'l [u8]> for Name<'_, 'l> { fn from(local: &'l [u8]) -> Self { Name::unqualified(local) } } -impl<'n, 'l> From<&'l str> for Name<'n, 'l> { +impl<'l> From<&'l str> for Name<'_, 'l> { fn from(local: &'l str) -> Self { Name::unqualified(local.as_bytes()) } @@ -412,7 +412,7 @@ impl<'n, 'l> From<(&'n str, &'l str)> for Name<'n, 'l> { #[derive(Clone)] pub struct AttrValue<'a>(quick_xml::events::attributes::Attribute<'a>); -impl<'a> AttrValue<'a> { +impl AttrValue<'_> { pub fn ascii_into(self) -> Result { let s = self.0.unescape_value()?; if !s.is_ascii() { @@ -435,7 +435,7 @@ impl<'a> AttrValue<'a> { pub struct Text<'a>(quick_xml::events::BytesText<'a>); -impl<'a> Text<'a> { +impl Text<'_> { pub fn to_utf8(&self) -> Result, Error> { Ok(self.0.unescape()?) } diff --git a/src/xml/encode.rs b/src/xml/encode.rs index eb82cae..6a4b839 100644 --- a/src/xml/encode.rs +++ b/src/xml/encode.rs @@ -225,7 +225,7 @@ impl<'a, W: io::Write> Element<'a, W> { } } -impl<'a, W: io::Write> Drop for Element<'a, W> { +impl Drop for Element<'_, W> { fn drop(&mut self) { if let Err(err) = self.end() { self.writer.store_error(err) @@ -246,7 +246,7 @@ pub struct Content<'a, W> { writer: &'a mut Writer, } -impl<'a, W: io::Write> Content<'a, W> { +impl Content<'_, W> { /// Add an element with the given tag. /// /// This will write the beginning of the tag to the writer and therefore @@ -417,8 +417,8 @@ impl<'a, W: io::Write> DisplayText<'a, W> { } } -impl<'a, W: io::Write> fmt::Write for DisplayText<'a, W> { - fn write_str(&mut self, s: &str) -> fmt::Result { +impl fmt::Write for DisplayText<'_, W> { + fn write_str(&mut self, s: &str) -> fmt::Result { match self.escape.write_escaped(s.as_bytes(), self.inner) { Ok(()) => Ok(()), Err(err) => {