mirror of
https://github.com/NLnetLabs/domain.git
synced 2026-09-08 02:47:44 +02:00
Fix clippy errors for 1.85.0. (#490)
* Fix clippy errors for 1.85.0. * Also fix nightly clippies. * Restore comment. * Remove redundant ok()
This commit is contained in:
+1
-5
@@ -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());
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1420,7 +1420,7 @@ impl<Target: Composer> AdditionalBuilder<Target> {
|
||||
F: FnOnce(&mut OptBuilder<Target>) -> 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(),
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -571,8 +571,8 @@ impl<Octs> OptRecord<Octs> {
|
||||
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(),
|
||||
|
||||
@@ -292,7 +292,7 @@ impl<Target: Composer> 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.
|
||||
|
||||
+1
-1
@@ -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`.
|
||||
|
||||
@@ -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".
|
||||
///
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ impl<Octs: FromBuilder> Txt<Octs> {
|
||||
{
|
||||
let mut builder = TxtBuilder::<Octs::Builder>::new();
|
||||
builder.append_slice(text)?;
|
||||
builder.finish().map_err(Into::into)
|
||||
builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-20
@@ -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<Builder: OctetsBuilder> Decoder<Builder> {
|
||||
|
||||
/// 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]))
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -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<Builder: OctetsBuilder> Decoder<Builder> {
|
||||
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.
|
||||
|
||||
@@ -365,14 +365,9 @@ pub fn make_ede(
|
||||
code: ExtendedErrorCode,
|
||||
reason: &str,
|
||||
) -> Option<ExtendedError<Vec<u8>>> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user