]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/clippy: fix lint: type_complexity
authorJason Ish <jason.ish@oisf.net>
Tue, 29 Nov 2022 13:13:58 +0000 (07:13 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:10:11 +0000 (14:10 +0100)
Convert a DNS sub-parser to use a return type rather than a large
tuple. For mqtt, allow the lint for now, but remove the global allow.

rust/src/dns/parser.rs
rust/src/lib.rs
rust/src/mqtt/parser.rs

index 94b1762db2b3667815318baf7e967e4beb72abaa..197d761d650972ec533269ce068b229a3fa61e8c 100644 (file)
@@ -120,26 +120,36 @@ fn dns_parse_answer<'a>(
     let mut answers = Vec::new();
     let mut input = slice;
 
+    struct Answer<'a> {
+        name: Vec<u8>,
+        rrtype: u16,
+        rrclass: u16,
+        ttl: u32,
+        data: &'a [u8],
+    }
+
     fn subparser<'a>(
         i: &'a [u8], message: &'a [u8],
-    ) -> IResult<&'a [u8], (Vec<u8>, u16, u16, u32, &'a [u8])> {
+    ) -> IResult<&'a [u8], Answer<'a>> {
         let (i, name) = dns_parse_name(i, message)?;
         let (i, rrtype) = be_u16(i)?;
         let (i, rrclass) = be_u16(i)?;
         let (i, ttl) = be_u32(i)?;
         let (i, data) = length_data(be_u16)(i)?;
-        Ok((i, (name, rrtype, rrclass, ttl, data)))
+        let answer = Answer {
+            name,
+            rrtype,
+            rrclass,
+            ttl,
+            data,
+        };
+        Ok((i, answer))
     }
 
     for _ in 0..count {
         match subparser(input, message) {
             Ok((rem, val)) => {
-                let name = val.0;
-                let rrtype = val.1;
-                let rrclass = val.2;
-                let ttl = val.3;
-                let data = val.4;
-                let n = match rrtype {
+                let n = match val.rrtype {
                     DNS_RECORD_TYPE_TXT => {
                         // For TXT records we need to run the parser
                         // multiple times. Set n high, to the maximum
@@ -155,15 +165,15 @@ fn dns_parse_answer<'a>(
                     }
                 };
                 let result: IResult<&'a [u8], Vec<DNSRData>> =
-                    many_m_n(1, n, complete(|b| dns_parse_rdata(b, message, rrtype)))(data);
+                    many_m_n(1, n, complete(|b| dns_parse_rdata(b, message, val.rrtype)))(val.data);
                 match result {
                     Ok((_, rdatas)) => {
                         for rdata in rdatas {
                             answers.push(DNSAnswerEntry {
-                                name: name.clone(),
-                                rrtype,
-                                rrclass,
-                                ttl,
+                                name: val.name.clone(),
+                                rrtype: val.rrtype,
+                                rrclass: val.rrclass,
+                                ttl: val.ttl,
                                 data: rdata,
                             });
                         }
index d7c323cda2545ed731922de463cd5e74cc3164d1..12e4a796eda889cec5c78a57d75fe7e62b64b956 100644 (file)
@@ -29,7 +29,6 @@
 // To be fixed, but remove the noise for now.
 #![allow(clippy::match_like_matches_macro)]
 #![allow(clippy::module_inception)]
-#![allow(clippy::type_complexity)]
 
 #[macro_use]
 extern crate bitflags;
index 26984be118a1a759e4ff2bf5e593771c08262216..78ef4ba01e1f65c8d3bdb8144361c51c06d773c3 100644 (file)
@@ -174,6 +174,7 @@ pub fn parse_fixed_header(i: &[u8]) -> IResult<&[u8], FixedHeader> {
 }
 
 #[inline]
+#[allow(clippy::type_complexity)]
 fn parse_connect_variable_flags(i: &[u8]) -> IResult<&[u8], (u8, u8, u8, u8, u8, u8, u8)> {
     bits(tuple((
         take_bits(1u8),