Skip to content

Commit

Permalink
clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouaix committed Dec 18, 2024
1 parent 619cf61 commit ed89ce4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions src/decoders/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ fn get_dns_flags(input: &[u8]) -> IResult<(&[u8], usize), String> {
const Z: usize = 3;
const RCODE: usize = 4;

type RET<'a> = ((&'a [u8], usize), u8);
type Ret<'a> = ((&'a [u8], usize), u8);
use nom::bits::complete::take as bits;
// Have to work with bits instead of bytes for the DNS flags
let ((input, offset), query): RET<'_> = bits(QR)((input, 0))?;
let ((input, offset), opcode): RET<'_> = bits(OPCODE)((input, offset))?;
let ((input, offset), authoritative_flag): RET<'_> = bits(AA)((input, offset))?;
let ((input, offset), truncation_flag): RET<'_> = bits(TC)((input, offset))?;
let ((input, offset), recursion_desired): RET<'_> = bits(RD)((input, offset))?;
let ((input, offset), recursion_available): RET<'_> = bits(RA)((input, offset))?;
let ((input, offset), _reserved): RET<'_> = bits(Z)((input, offset))?;
let ((input, _), response_code): RET<'_> = bits(RCODE)((input, offset))?;
let ((input, offset), query): Ret<'_> = bits(QR)((input, 0))?;
let ((input, offset), opcode): Ret<'_> = bits(OPCODE)((input, offset))?;
let ((input, offset), authoritative_flag): Ret<'_> = bits(AA)((input, offset))?;
let ((input, offset), truncation_flag): Ret<'_> = bits(TC)((input, offset))?;
let ((input, offset), recursion_desired): Ret<'_> = bits(RD)((input, offset))?;
let ((input, offset), recursion_available): Ret<'_> = bits(RA)((input, offset))?;
let ((input, offset), _reserved): Ret<'_> = bits(Z)((input, offset))?;
let ((input, _), response_code): Ret<'_> = bits(RCODE)((input, offset))?;

let opcode_message = match opcode {
0 => "QUERY",
Expand Down Expand Up @@ -324,9 +324,9 @@ fn parse_dns_ip_addr(data: &[u8]) -> nom::IResult<&[u8], String> {
const IPV4: u32 = 4;
const IPV6: u32 = 6;
if ip_version == IPV4 {
return get_ip_four(data).map(|(data, result)| (data, result.to_string()));
get_ip_four(data).map(|(data, result)| (data, result.to_string()))
} else if ip_version == IPV6 {
return get_ip_six(data).map(|(data, result)| (data, result.to_string()));
get_ip_six(data).map(|(data, result)| (data, result.to_string()))
} else {
fail(data)
}
Expand Down
6 changes: 3 additions & 3 deletions src/decoders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ pub enum DecoderError<'a> {
},
}

impl<'a> std::error::Error for DecoderError<'a> {}
impl std::error::Error for DecoderError<'_> {}

impl<'a> std::fmt::Display for DecoderError<'a> {
impl std::fmt::Display for DecoderError<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Parse { message, .. } => write!(f, "{message}"),
}
}
}

impl<'a> std::fmt::Debug for DecoderError<'a> {
impl std::fmt::Debug for DecoderError<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Parse {
Expand Down
4 changes: 2 additions & 2 deletions src/decoders/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ fn get_sockaddr_data(input: &[u8]) -> nom::IResult<&[u8], String> {

/// Get the IPv4 data
pub(crate) fn get_ip_four(input: &[u8]) -> nom::IResult<&[u8], Ipv4Addr> {
map(be_u32, |val| Ipv4Addr::from(val))(input)
map(be_u32, Ipv4Addr::from)(input)
}

/// Get the IPv6 data
pub(crate) fn get_ip_six(input: &[u8]) -> nom::IResult<&[u8], Ipv6Addr> {
map(be_u128, |val| Ipv6Addr::from(val))(input)
map(be_u128, Ipv6Addr::from)(input)
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn extract_string_size(data: &[u8], message_size: u64) -> nom::IResul
const NULL_BYTE: u8 = 0;

#[allow(dead_code)]
/// Extract an UTF8 string from a byte array, stops at NULL_BYTE or END OF STRING
/// Extract an UTF8 string from a byte array, stops at `NULL_BYTE` or END OF STRING
/// Consumes the end byte
pub(crate) fn cstring(input: &[u8]) -> nom::IResult<&[u8], String> {
let (input, (str_part, _)) =
Expand All @@ -77,7 +77,7 @@ pub(crate) fn cstring(input: &[u8]) -> nom::IResult<&[u8], String> {
}
}

/// Extract an UTF8 string from a byte array, stops at NULL_BYTE or END OF STRING
/// Extract an UTF8 string from a byte array, stops at `NULL_BYTE` or END OF STRING
/// Consumes the end byte
/// Fails if the string is empty
pub(crate) fn non_empty_cstring(input: &[u8]) -> nom::IResult<&[u8], String> {
Expand Down

0 comments on commit ed89ce4

Please sign in to comment.