diff --git a/examples/client.rs b/examples/client.rs index fc59286d..d13290c0 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -61,11 +61,7 @@ fn main() { socket.recv_from(&mut buffer).unwrap(); // Parse and print the response - let response = match Message::from_octets(buffer) { - Ok(response) => Some(response), - Err(_) => None, - } - .unwrap(); + let response = Message::from_octets(buffer).unwrap(); for question in response.question() { println!("{}", question.unwrap()); diff --git a/src/base/iana/rcode.rs b/src/base/iana/rcode.rs index 460c8c36..2782b129 100644 --- a/src/base/iana/rcode.rs +++ b/src/base/iana/rcode.rs @@ -537,7 +537,7 @@ impl OptRcode { /// Creates an extended rcode value from its parts. #[must_use] pub fn from_parts(rcode: Rcode, ext: u8) -> OptRcode { - OptRcode(u16::from(ext) << 4 | u16::from(rcode.to_int())) + OptRcode((u16::from(ext) << 4) | u16::from(rcode.to_int())) } /// Returns the two parts of an extended rcode value. diff --git a/src/base/message_builder.rs b/src/base/message_builder.rs index 25b069b7..a90b5d93 100644 --- a/src/base/message_builder.rs +++ b/src/base/message_builder.rs @@ -1420,7 +1420,7 @@ impl AdditionalBuilder { F: FnOnce(&mut OptBuilder) -> Result<(), Target::AppendError>, { self.authority.answer.builder.push( - |target| OptBuilder::new(target)?.build(op).map_err(Into::into), + |target| OptBuilder::new(target)?.build(op), |counts| counts.inc_arcount(), ) } diff --git a/src/base/opt/mod.rs b/src/base/opt/mod.rs index a79ab197..e7d776d8 100644 --- a/src/base/opt/mod.rs +++ b/src/base/opt/mod.rs @@ -571,8 +571,8 @@ impl OptRecord { Name::root_slice(), Class::from_int(self.udp_payload_size), Ttl::from_secs( - u32::from(self.ext_rcode) << 24 - | u32::from(self.version) << 16 + (u32::from(self.ext_rcode) << 24) + | (u32::from(self.version) << 16) | u32::from(self.flags), ), self.data.for_slice_ref(), diff --git a/src/base/opt/subnet.rs b/src/base/opt/subnet.rs index 03e06e20..ead33706 100644 --- a/src/base/opt/subnet.rs +++ b/src/base/opt/subnet.rs @@ -292,7 +292,7 @@ impl OptBuilder<'_, Target> { /// Returns the number of bytes needed for a prefix of a given length fn prefix_bytes(bits: u8) -> usize { - (usize::from(bits) + 7) / 8 + usize::from(bits).div_ceil(8) } /// Only keeps the left-most `mask` bits and zeros out the rest. diff --git a/src/base/record.rs b/src/base/record.rs index dd82b21e..010f0f20 100644 --- a/src/base/record.rs +++ b/src/base/record.rs @@ -1096,7 +1096,7 @@ const SECS_PER_DAY: u32 = 86400; /// /// Two reasons make [`std::time::Duration`] not suited for representing DNS TTL values: /// 1. According to [RFC 2181](https://datatracker.ietf.org/doc/html/rfc2181#section-8) TTL values have second-level precision while [`std::time::Duration`] can represent time down to the nanosecond level. -/// This amount of precision is simply not needed and might cause confusion when sending `Duration`s over the network. +/// This amount of precision is simply not needed and might cause confusion when sending `Duration`s over the network. /// 2. When working with DNS TTL values it's common to want to know a time to live in minutes or hours. [`std::time::Duration`] does not expose easy to use methods for this purpose, while `Ttl` does. /// /// `Ttl` provides two methods [`Ttl::from_duration_lossy`] and [`Ttl::into_duration`] to convert between `Duration` and `Ttl`. diff --git a/src/net/server/connection.rs b/src/net/server/connection.rs index a09609a0..ed5dc484 100644 --- a/src/net/server/connection.rs +++ b/src/net/server/connection.rs @@ -40,7 +40,7 @@ use super::ServerCommand; /// - "A timeout of at least a few seconds is advisable for normal /// operations". /// - "Servers MAY use zero timeouts when they are experiencing heavy load or -/// are under attack". +/// are under attack". /// - "Servers MAY allow idle connections to remain open for longer periods as /// resources permit". /// @@ -129,7 +129,7 @@ impl Config { /// - "A timeout of at least a few seconds is advisable for normal /// operations". /// - "Servers MAY use zero timeouts when they are experiencing heavy load - /// or are under attack". + /// or are under attack". /// - "Servers MAY allow idle connections to remain open for longer /// periods as resources permit". /// diff --git a/src/rdata/dnssec.rs b/src/rdata/dnssec.rs index 8004968e..bb96e809 100644 --- a/src/rdata/dnssec.rs +++ b/src/rdata/dnssec.rs @@ -2633,7 +2633,7 @@ impl Iterator for RtypeBitmapIter<'_> { return None; } let res = - Rtype::from_int(self.block | (self.octet as u16) << 3 | self.bit); + Rtype::from_int(self.block | ((self.octet as u16) << 3) | self.bit); self.advance(); Some(res) } diff --git a/src/rdata/rfc1035/txt.rs b/src/rdata/rfc1035/txt.rs index 3eb1d51d..d9890a56 100644 --- a/src/rdata/rfc1035/txt.rs +++ b/src/rdata/rfc1035/txt.rs @@ -105,7 +105,7 @@ impl Txt { { let mut builder = TxtBuilder::::new(); builder.append_slice(text)?; - builder.finish().map_err(Into::into) + builder.finish() } } diff --git a/src/utils/base32.rs b/src/utils/base32.rs index 33372bea..21a8cbaa 100644 --- a/src/utils/base32.rs +++ b/src/utils/base32.rs @@ -81,24 +81,24 @@ where f.write_char(ch((chunk[0] & 0x07) << 2))?; // 1 break; } - f.write_char(ch((chunk[0] & 0x07) << 2 | chunk[1] >> 6))?; // 1 + f.write_char(ch(((chunk[0] & 0x07) << 2) | (chunk[1] >> 6)))?; // 1 f.write_char(ch((chunk[1] & 0x3F) >> 1))?; // 2 if chunk.len() == 2 { f.write_char(ch((chunk[1] & 0x01) << 4))?; // 3 break; } - f.write_char(ch((chunk[1] & 0x01) << 4 | chunk[2] >> 4))?; // 3 + f.write_char(ch(((chunk[1] & 0x01) << 4) | (chunk[2] >> 4)))?; // 3 if chunk.len() == 3 { f.write_char(ch((chunk[2] & 0x0F) << 1))?; // 4 break; } - f.write_char(ch((chunk[2] & 0x0F) << 1 | chunk[3] >> 7))?; // 4 + f.write_char(ch(((chunk[2] & 0x0F) << 1) | (chunk[3] >> 7)))?; // 4 f.write_char(ch((chunk[3] & 0x7F) >> 2))?; // 5 if chunk.len() == 4 { f.write_char(ch((chunk[3] & 0x03) << 3))?; // 6 break; } - f.write_char(ch((chunk[3] & 0x03) << 3 | chunk[4] >> 5))?; // 6 + f.write_char(ch(((chunk[3] & 0x03) << 3) | (chunk[4] >> 5)))?; // 6 f.write_char(ch(chunk[4] & 0x1F))?; // 7 } Ok(()) @@ -319,31 +319,31 @@ impl Decoder { /// Decodes the zeroth octet in a base 32 sequence. fn octet_0(&mut self) { - let ch = self.buf[0] << 3 | self.buf[1] >> 2; + let ch = (self.buf[0] << 3) | (self.buf[1] >> 2); self.append(ch) } /// Decodes the first octet in a base 32 sequence. fn octet_1(&mut self) { - let ch = self.buf[1] << 6 | self.buf[2] << 1 | self.buf[3] >> 4; + let ch = (self.buf[1] << 6) | (self.buf[2] << 1) | (self.buf[3] >> 4); self.append(ch) } /// Decodes the second octet in a base 32 sequence. fn octet_2(&mut self) { - let ch = self.buf[3] << 4 | self.buf[4] >> 1; + let ch = (self.buf[3] << 4) | (self.buf[4] >> 1); self.append(ch) } /// Decodes the third octet in a base 32 sequence. fn octet_3(&mut self) { - let ch = self.buf[4] << 7 | self.buf[5] << 2 | self.buf[6] >> 3; + let ch = (self.buf[4] << 7) | (self.buf[5] << 2) | (self.buf[6] >> 3); self.append(ch) } /// Decodes the forth octet in a base 32 sequence. fn octet_4(&mut self) { - let ch = self.buf[6] << 5 | self.buf[7]; + let ch = (self.buf[6] << 5) | self.buf[7]; self.append(ch) } @@ -417,11 +417,15 @@ impl SymbolConverter { if self.next == 8 { self.output = [ - self.input[0] << 3 | self.input[1] >> 2, - self.input[1] << 6 | self.input[2] << 1 | self.input[3] >> 4, - self.input[3] << 4 | self.input[4] >> 1, - self.input[4] << 7 | self.input[5] << 2 | self.input[6] >> 3, - self.input[6] << 5 | self.input[7], + (self.input[0] << 3) | (self.input[1] >> 2), + (self.input[1] << 6) + | (self.input[2] << 1) + | (self.input[3] >> 4), + (self.input[3] << 4) | (self.input[4] >> 1), + (self.input[4] << 7) + | (self.input[5] << 2) + | (self.input[6] >> 3), + (self.input[6] << 5) | self.input[7], ]; self.next = 0; Ok(Some(&self.output)) @@ -459,21 +463,23 @@ where 1 | 3 | 6 => return Err(Error::custom("short Base 32 input")), _ => {} } - self.output[0] = self.input[0] << 3 | self.input[1] >> 2; + self.output[0] = (self.input[0] << 3) | (self.input[1] >> 2); if self.next == 2 { return Ok(Some(&self.output[0..1])); } - self.output[1] = - self.input[1] << 6 | self.input[2] << 1 | self.input[3] >> 4; + self.output[1] = (self.input[1] << 6) + | (self.input[2] << 1) + | (self.input[3] >> 4); if self.next == 4 { return Ok(Some(&self.output[0..2])); } - self.output[2] = self.input[3] << 4 | self.input[4] >> 1; + self.output[2] = (self.input[3] << 4) | (self.input[4] >> 1); if self.next == 5 { return Ok(Some(&self.output[0..3])); } - self.output[3] = - self.input[4] << 7 | self.input[5] << 2 | self.input[6] >> 3; + self.output[3] = (self.input[4] << 7) + | (self.input[5] << 2) + | (self.input[6] >> 3); Ok(Some(&self.output[0..4])) } } diff --git a/src/utils/base64.rs b/src/utils/base64.rs index 062b2c4e..542d0e7b 100644 --- a/src/utils/base64.rs +++ b/src/utils/base64.rs @@ -74,14 +74,14 @@ where } 2 => { f.write_char(ch(chunk[0] >> 2))?; - f.write_char(ch((chunk[0] & 0x03) << 4 | chunk[1] >> 4))?; + f.write_char(ch(((chunk[0] & 0x03) << 4) | (chunk[1] >> 4)))?; f.write_char(ch((chunk[1] & 0x0F) << 2))?; f.write_char('=')?; } 3 => { f.write_char(ch(chunk[0] >> 2))?; - f.write_char(ch((chunk[0] & 0x03) << 4 | chunk[1] >> 4))?; - f.write_char(ch((chunk[1] & 0x0F) << 2 | chunk[2] >> 6))?; + f.write_char(ch(((chunk[0] & 0x03) << 4) | (chunk[1] >> 4)))?; + f.write_char(ch(((chunk[1] & 0x0F) << 2) | (chunk[2] >> 6)))?; f.write_char(ch(chunk[2] & 0x3F))?; } _ => unreachable!(), @@ -280,11 +280,11 @@ impl Decoder { if self.next == 4 { let target = self.target.as_mut().unwrap(); // Err covered above. target - .append_slice(&[self.buf[0] << 2 | self.buf[1] >> 4]) + .append_slice(&[(self.buf[0] << 2) | (self.buf[1] >> 4)]) .map_err(Into::into)?; if self.buf[2] != 0x80 { target - .append_slice(&[self.buf[1] << 4 | self.buf[2] >> 2]) + .append_slice(&[(self.buf[1] << 4) | (self.buf[2] >> 2)]) .map_err(Into::into)?; } if self.buf[3] != 0x80 { @@ -368,7 +368,7 @@ impl SymbolConverter { self.next += 1; if self.next == 4 { - self.output[0] = self.input[0] << 2 | self.input[1] >> 4; + self.output[0] = (self.input[0] << 2) | (self.input[1] >> 4); if self.input[2] == PAD_MARKER { // The second to last character is padding. The last one @@ -380,7 +380,7 @@ impl SymbolConverter { Err(Error::custom("illegal Base 64 data")) } } else { - self.output[1] = self.input[1] << 4 | self.input[2] >> 2; + self.output[1] = (self.input[1] << 4) | (self.input[2] >> 2); if self.input[3] == PAD_MARKER { // The last characters is padding. diff --git a/src/validator/utilities.rs b/src/validator/utilities.rs index df678d07..4b87ad46 100644 --- a/src/validator/utilities.rs +++ b/src/validator/utilities.rs @@ -365,14 +365,9 @@ pub fn make_ede( code: ExtendedErrorCode, reason: &str, ) -> Option>> { - match ExtendedError::new_with_str(code, reason) { - Ok(ede) => Some(ede), - Err(_) => { - // Assume that the only reason this case fail is a string that - // is way too long. Just return None. - None - } - } + // Assume that the only reason this case fail is a string that + // is way too long. Just return None. + ExtendedError::new_with_str(code, reason).ok() } /// Create a new DNS message based on the original message that fixes any